18

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 /.

Glueon
  • 3,664
  • 2
  • 24
  • 32
  • You were lucky. I tried to launch Celery from another dir but with specifying `workdir`, it did not start. So better sit in the right directory and launch without `workdir`. – sekrett Dec 01 '20 at 08:22

3 Answers3

27

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
acidjunk
  • 371
  • 3
  • 4
1

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.

Tanel Tammik
  • 191
  • 1
  • 4
1

It's the same with Laravel (PHP Framework), I'm using supervisor to run jobs in queue and the .env file was not found, here's a configuration that works:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
directory=/var/www/YOUR_LARAVEL_APP
command=php artisan queue:work database --sleep=3 --tries=3
autostart=true
autorestart=true
user=YOUR_USER
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/YOUR_LARAVEL_APP/storage/logs/worker.log
stderr_logfile=/var/www/YOUR_LARAVEL_APP/storage/logs/worker_error.log