Installing and setting up Supervisord
If you do not know much about supervisord
, then you are missing something awesome. Let me make your world a little better ;-)
In simple words, supervisord
allows you to control your services. If you have a shell script, a python script, a python api, or any executable process that you want to be able to start, stop, and restart and you do not want to create a service executable for it, then look no further. supervisord
can do it for you! This blog's processes are controlled via supervisord
. You can read what supervisord
can do for you here.
Installing it and getting started is a peice of cake!
a. Install supervisord: easy_install supervisor
OR pip install supervisor --pre
b. Create a default configuration file: echo_supervisord_conf > /etc/supervisord.conf
This is one of the default locations supervisord looks for a supervisord.conf file
c. Configure your service by adding the section below in supervisord.conf:
[program:sample_app]
command=python sample_app.py
directory=/home/ravi/dev/projects/python/supervisor-play
autostart=true
startretries=3
stdout_logfile=/var/log/supervisor/sample_app.out
stderr_logfile=/var/log/supervisor/sample_app.err
Explaination of the config above:
command
: The executable command.
directory
: Change to this directory before executing the command
.
autostart
: Start when supervisord process starts.
startretries
: Try restarting the process 3 times if it fails to start.
stdout_logfile
: The file the process's stdout should go to.
stderr_logfile
: The file the process's stderr should go to.
d. Start supervisord
by typing the following on the command line:
supervisord