2013-05-06

Setup Supervisor on Ubuntu

1. Install
easy_install supervisor
2. Generate config file
echo_supervisord_conf > /etc/supervisord.conf
3. Prepare for application conf files
mkdir /etc/supervisord.conf.d
Edit /etc/supervisord.conf
vi /etc/supervisord.conf
Add line

[include]
files = /etc/supervisord.conf.d/*.conf
4. Create file /etc/init.d/supervisord
vi /etc/init.d/supervisord
Content:

#! /bin/bash -e
SUPERVISORD=/usr/local/bin/supervisord
PIDFILE=/tmp/supervisord.pid
OPTS="-c /etc/supervisord.conf"
test -x $SUPERVISORD || exit 0
. /lib/lsb/init-functions
export PATH="${PATH:+$PATH:}/usr/local/bin:/usr/sbin:/sbin"
case "$1" in
  start)
    log_begin_msg "Starting Supervisor daemon manager..."
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $SUPERVISORD -- $OPTS || log_end_msg 1
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Stopping Supervisor daemon manager..."
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE || log_end_msg 1
    log_end_msg 0
    ;;
  restart|reload|force-reload)
    log_begin_msg "Restarting Supervisor daemon manager..."
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec $SUPERVISORD -- $OPTS || log_end_msg 1
    log_end_msg 0
    ;;
  *)
    log_success_msg "Usage: /etc/init.d/supervisor
{start|stop|reload|force-reload|restart}"
    exit 1
esac
exit 0
Change permission and update service
chmod +x /etc/init.d/supervisord
update-rc.d supervisord defaults

5. Add your application conf files into folder /etc/supervisord.conf.d
For example
vi /etc/supervisord.conf.d/mytest.conf
Content
[program:sqlparse]
directory = /var/www/python
command = /bin/env python test.py 
6. Start/stop/restart supervisor daemon service
 service supervisord start/stop/restart
Repeat step 5, 6 to add more application you want.

7. Then, you  can use supervisorctl to manage your tasks.
supervisorctl

Issue:
If you found this error when you restart service

 * Starting Supervisor daemon manager...
Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
   ...fail!
Try this
sudo unlink /tmp/supervisor.sock 

No comments: