I've got a worker process which processes 1 RabbitMq message at a time. Right now, as soon as the worker exits, supervisord is restarting it (which will process the next message).

I'd like to set an interval X seconds, so that supervisord does not restart immidietly, but it waits a given amount of time before starting another worker.

Is this possible? How?


There is no way to specify interval in supervisor program section, but what you could do is put "sleep()" into your code so that after program waits for specified period of time after it finishes with message processing.

If you don't want/cant alter the program code, you may try wrapping it into bash script, for example:

sleep 30

And alter your supervisor program section to run that script, instead of your program:

  • Sleep won't be executed until /usr/local/bin/myprogram returns? – loostro Jun 30 '14 at 8:15
  • Exactly, only after myprogram exits, sleep will start counting. – Jakov Sosic Jun 30 '14 at 8:59
  • A problem is that this script does not handle signals, in particular, TERM. – Torsten Bronger Nov 23 '19 at 19:00

I needed a simple way to run a command from inside a docker container, where there is no cron. Here is what I'm using:

directory = /my/workdir
command = sh -c "sleep 5;date >>/root/test.ts"
stdout_logfile = /var/log/supervisor/%(program_name)s.log
stderr_logfile = /var/log/supervisor/%(program_name)s.log
autorestart = true
startsecs = 0
exitcodes = 0,1,2

startsecs = 0 ensures that supervisor thinks the command was started successfully even if it exits after a few secs. Otherwise supervisor will stop restarting it, thinking it's in a loop.

Here is what you would see in /root/date.ts with the example above:

# tail -f /root/test.ts 
Tue Nov 17 20:42:58 UTC 2015
Tue Nov 17 20:43:04 UTC 2015
Tue Nov 17 20:43:10 UTC 2015

Tune the sleep to your liking and replace 'date >>/root/test.ts' with whatever you need.

This solution also comes handy if you need to run a cronjob more often than every minute.

  • +1 for the clever solution. I want to do something similar. Unfortunately, this doesn't work for me as I need to get the exit code in a listener using an RPC call. Unfortunately, supervisor restarts the program immediately after exit, making the code 0, sigh... Any other ideas? – Onema Feb 13 '16 at 1:52
command = bash -c "sleep 60 && exec urcmd'
startsecs = 65 ; 

and then

supervisorctl -c your_config_file reload

1. you need to use exec command, otherwise it will fork a subprogress from sleep 60 && exec your command and your progress will look like as the following

$ ps -ef|grep urcmd
work      1818  1698  0 17:35 ?        00:00:00 bash -c sleep 60 && urcmd
work      3872  1818  0 17:36 ?        00:00:00 urcmd

and then when you use supervisorctl to stop urApp, you will stop 1818 progress and leave 3872 an orphan progress

2.recommend to change the startsecs to 5 more than the sleep secs, then when you start this app and check the status, it will show you it's starting

$supervisorctl -c your_config_file status;echo;ps -ef|grep urcmd
urapp                          STARTING  
otherapp                       RUNNING   pid 13502, uptime 0:00:55

$supervisorctl -c your_config_file status;echo;ps -ef|grep urcmd
urapp                          RUNNING   pid 13503, uptime 0:00:05
otherapp                       RUNNING   pid 13502, uptime 0:00:65

else if you set the value less than the sleep secs, when you start the app and check the status,you will get a running status, but it's still sleeping cmd before real executing

3.when you change your configuration file, you need to use reload cmd or just restart your supervisord to make it work

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.