Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a delay to supervised process in supervisor - linux

I added a bottle server that uses python's cassandra library, but it exits with this error:
Bottle FATAL Exited too quickly (process log may have details)
log shows this:
File "/usr/local/lib/python2.7/dist-packages/cassandra/cluster.py", line 1765, in _reconnect_internal raise NoHostAvailable("Unable to connect to any servers", errors)

So I tried to run it manually using supervisorctl start Bottle ,and then it started with no issue. The conclusion= Bottle service starts too fast (before the needed cassandra supervised service does): a delay is needed!

like image 708
Zack S Avatar asked Oct 13 '14 14:10

Zack S


People also ask

How do you stop a supervisor process?

Finally, you can exit supervisorctl with Ctrl+C or by entering quit into the prompt: supervisor> quit.

How does Supervisorctl work?

Supervisorctl allows a very limited form of access to the machine, essentially allowing users to see process status and control supervisord-controlled subprocesses by emitting “stop”, “start”, and “restart” commands from a simple shell or web UI.

How do I start a supervisord process?

To start a non-running service or stop a running one, use supervisorctl start my-daemon and supervisorctl stop my-daemon . To restart a service, you can also use supervisorctl restart my-daemon .


2 Answers

This is what I use:

[program:uwsgi]
command=bash -c 'sleep 5 && uwsgi /etc/uwsgi.ini'
like image 188
DeeY Avatar answered Oct 05 '22 23:10

DeeY


Not happy enough with the sleep hack I created a startup script and launched supervisorctl start processname from there.

[program:startup]
command=/startup.sh
startsecs = 0
autostart = true
autorestart = false
startretries = 1
priority=1

[program:myapp]
command=/home/website/venv/bin/gunicorn /home/website/myapp/app.py
autostart=false
autorestart=true
process_name=myapp

startup.sh

#!/bin/bash
sleep 5
supervisorctrl start myapp

This way supervisor will fire the startup script once and this will start myapp after 5 seconds, mind the autostart=false and autorestart=true on myapp.

like image 23
MGP Avatar answered Oct 05 '22 22:10

MGP