Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

supervisor - how to run multiple commands

I'm managing a Celery worker that processes queue via Supervisor.

Here's my /etc/supervisor/celery.conf:

[program:celery] command = /var/worker/venv/bin/celery worker -A a_report_tasks -Q a_report_process --loglevel=INFO directory=/var/worker user=nobody numprocs=1 autostart=true autorestart=true startsecs=10 stopwaitsecs = 60 stdout_logfile=/var/log/celery/worker.log stderr_logfile=/var/log/celery/worker.log killasgroup=true priority=998 

How do I add this second command to run?

/var/worker/venv/bin/celery worker -A b_report_tasks -Q b_report_process --loglevel=INFO 

I tried separating the two commands on the same line with && (resulted in a syntax error), adding an entirely separate [program:celery] section to this same file (resulted in only the first one being run), and creating an entirely different celery1.conf file in the same directory (resulted in only the original/first one being run).

like image 521
okoboko Avatar asked Mar 11 '15 18:03

okoboko


People also ask

How do you run multiple commands?

Running Multiple Commands as a Single Job We can start multiple commands as a single job through three steps: Combining the commands – We can use “;“, “&&“, or “||“ to concatenate our commands, depending on the requirement of conditional logic, for example: cmd1; cmd2 && cmd3 || cmd4.

How do you run as a supervisor?

To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor. log by default.

Can be used to run multiple commands one after the other?

The semicolon (;) operator allows you to execute multiple commands in succession, regardless of whether each previous command succeeds.


1 Answers

Add a second section with a different task name. If two tasks have the same task name, the latter overwrites the former.

[program:celeryb] command = /var/worker/venv/bin/celery worker -A b_report_tasks -Q b_report_process --loglevel=INFO directory=/var/worker user=nobody numprocs=1 autostart=true autorestart=true startsecs=10 stopwaitsecs = 60 stdout_logfile=/var/log/celery/worker.log stderr_logfile=/var/log/celery/worker.log killasgroup=true priority=998 

You can also group them so both tasks get restarted as a group:

[group:celery-workers] programs=celery,celeryb priority=999 
like image 77
dhke Avatar answered Oct 08 '22 20:10

dhke