5

I'm trying to run celery as a service as described in the docs.

The documentation uses %n%I specifiers for the log files:

celery.service:

ExecStart= [...] --logfile=${CELERYD_LOG_FILE}

celery.service.d/celery.conf

Environment="CELERYD_LOG_FILE=/var/log/celery/%n%I.log"

When doing this, I can see in the service status that %n is resolved at start time and %I remains at this stage:

systemctl status celery.service
[...]
    --logfile=/var/log/celery/worker%I.log

And I get those log files:

/var/log/celery/worker.log
/var/log/celery/worker-1.log
/var/log/celery/worker-2.log

If I use %i, however, the whole thing resolves at start time

celery.service.d/celery.conf

Environment="CELERYD_LOG_FILE=/var/log/celery/%n%i.log"

produces this:

systemctl status celery.service
[...]
    --logfile=/var/log/celery/celery.service.log

And I get only one log file:

/var/log/celery/celery.service.log

This is troubling.

From systemd documentation, the only difference should be about escaping:

  • "%i" | Instance name | For instantiated units: this is the string between the "@" character and the suffix of the unit name.
  • "%I" | Unescaped instance name | Same as "%i", but with escaping undone

Is there something I'm missing, here?

Also, I noticed that if I set the log path directly in the .service file, only the %n%i form is accepted.

ExecStart= [...] --logfile=/var/log/celery/%n%i.log

will do, and results in

/var/log/celery/celery.service.log

while

ExecStart= [...] --logfile=/var/log/celery/%n%I.log

triggers an error:

celery.service failed to run 'start' task: Operation not supported
Failed to start Celery worker.

How come?

I'm using systemd 215-17 on Debian Jessie.

Edit 1:

It seems %I is not understood by systemd at all. What we see when using %I is specific to Celery. (See Celery docs). So %i is managed by systemd while %I is ignored and passed transparently by systemd, then managed by Celery.

This explains a lot but leaves a few questions open:

  • Why doesn't systemd understand %I here?
  • Conversely, what if I wanted to pass Celery a %i?
  • Why does it differ if I pass the option directly in the .service file rather than in the .conf file?

I went through systemd changelog and didn't find anything about %I being more recent than the version I am using.

Edit 2:

I saw this error message while running systemctl status celery.service:

[/etc/systemd/system/celery.service.d/celery.conf:18] Failed to resolve specifiers, ignoring: "CELERYD_LOG_FILE=/var/log/celery/%n%I.log"

I can't reproduce it, though. I can't tell why it happened once and and not every time.

  • The celery doc you refer to is not using a service template, or the unit file would be named celery@.service (which you can try). You should probably replace every % with %% so systemd does no processing of the specifiers, since your celery application seems to be wanting to do it. – meuh Oct 9 '17 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.