Directory setting in Supervisor

I was configuring supervisor daemon to be able to start/stop Celery.

It did not work. After debuging back and forth I realized that the problem was that it did not change the working directory to the one mentioned in the directory option in supervisord.conf under program section.

Hopefully there is a workdir in Celery but I am curious - what is the purpose of the directory option then?

If you run a script via supervisor and print pwd it will output /.


Solution 1:

I had the same problem and managed to resolve it by reversing the order of directory and command options:

e.g. working:

[program:cat]
directory=/var/log
command=cat logfile

NOT working:

[program:cat]
command=cat logfile
directory=/var/log

Solution 2:

here is an example how i got nodejs app with correct ENV working with supervisor

[program:fake-smtp]
directory=/home/web/fake-smtp
command=sh -c 'NODE_ENV=production node src/index.js'
autostart=true
autorestart=true
user=web
redirect_stderr=true
stdout_logfile=/home/web/logs/smtp.log
stderr_logfile=/home/web/logs/smtp.err.log

i hope this helps! this app also requires correct directory.