38

Supervisord does not come with an init script or does not indicate how to get it started automatically, ie. after a reboot. I've tried some user-contributed /etc/init.d scripts, but they all fail.

What would be the preferred solution ?

7 Answers7

40

Actually, I found one that works here http://gist.github.com/176149. To install it:

sudo curl https://gist.github.com/howthebodyworks/176149/raw/88d0d68c4af22a7474ad1d011659ea2d27e35b8d/supervisord.sh > /etc/init.d/supervisord

to run it

sudo chmod +x /etc/init.d/supervisord

and to automatically schedule it, do

sudo update-rc.d supervisord defaults

Make ensure correct pid in /etc/supervisord.conf which is mapped in /etc/init.d/supervisord

example: pidfile=/var/run/supervisord.pid

Stop and Start work properly

service supervisord stop
service supervisord start
caesarsol
  • 186
  • 8
  • This is debian specific? Missing /lib/init/vars.sh and update-rc.d on a Centos6.5 box – EoghanM Jul 12 '12 at 20:04
  • 1
    how do we know where supervisord.conf goes?/Where should we put supervisord.conf? – Weiwei Jul 20 '12 at 23:37
  • 1
    I found it was much easier to just install supervisord from the Debian squeeze repo - doing aptitude install supervisord includes correct setup of the /etc/init.d file with links, and puts the config file in /etc/supervisor/supervisord.conf – RichVel Jan 10 '13 at 22:25
  • @RichVel however you installed an absolete version. For example, Ubuntu 12.04 includes Supervisor 3.0a8, released in January 2010 http://supervisord.org/installing.html#installing-a-distribution-package – glarrain Jul 26 '13 at 14:27
  • @glarrain - old but not obsolete, since the Debian squeeze version works fine. To reduce sysadmin effort, I try to install non-distro packages only where essential. – RichVel Jul 27 '13 at 08:16
  • 2
    @RichVel That's an alpha version, with many bugs in it. Maybe most of them do not affect your system, but you can't be sure, and not having the latest release can bite you at any momment. Check the source repo and you'll see that there are more than 320 commits between versions 3.0a8 and 3.0b2 https://github.com/Supervisor/supervisor/compare/3.0a8...3.0b2 – glarrain Jul 29 '13 at 16:37
  • 1
    @glarrain - thanks for the heads-up and comparison link... Didn't realise that - annoying that the Debian packager took an alpha release. Surely the point of Debian stable is to only use proven versions... – RichVel Jul 29 '13 at 16:44
  • Updated link to gist is https://gist.github.com/howthebodyworks/176149/raw/88d0d68c4af22a7474ad1d011659ea2d27e35b8d/supervisord.sh – Marcos Besteiro López Oct 08 '13 at 22:44
13

I created an upstart script for ubuntu 9.10

For example I installed supervisor into a virtual environment, then start and control supervisor from upstart.

create a text file /etc/init/supervisord.conf

the contents are:

description     "supervisord"

start on runlevel [345]
stop on runlevel [!345]

expect fork
respawn

exec /misc/home/bkc/Python_Environments/java2/supervisord/bin/supervisord -c /misc/home/bkc/Python_Environments/java2/supervisord/work/supervisord.conf

It will automatically start supervisor on boot. To manually start after creating the .conf file, use

sudo start supervisord

To manually stop the service, use

sudo stop supervisord

bkc
  • 131
  • 1
  • 2
  • 2
    Thanks! Here is a one-liner: `curl -L https://gist.github.com/raw/1213031/929e578faae2ad3bcb29b03d116bcb09e1932221/sup‌​ervisord.conf > /etc/init/supervisord.conf && start supervisord` (you need to be root) – charlax Sep 16 '11 at 17:48
  • 3
    Always check gist one-liners before you run them. This one is fine, but I just wanted to add that tip. – Cory Walker Jun 08 '13 at 15:59
12

This is what I use on RHEL 5.4 and CentOS 5.5

I'm not sure wether it's depending on some configuration settings in my supervisord.conf. But it seems to work OK.

You need to run the following command after installing it

chkconfig --add supervisord

[/etc/rc.d/init.d/supervisord]

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"

start()
{
        echo -n $"Starting $prog: "
        daemon $prog_bin --pidfile $PIDFILE
        [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
        echo
}

stop()
{
        echo -n $"Shutting down $prog: "
        [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
        echo
}

case "$1" in

  start)
    start
  ;;

  stop)
    stop
  ;;

  status)
        status $prog
  ;;

  restart)
    stop
    start
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
  ;;

esac
Peter Lindqvist
  • 518
  • 4
  • 11
  • would only add that you need to add a +x permissions before you try running it: chmod +x /etc/init.d/supervisord – JiminyCricket Jan 08 '13 at 08:44
  • Don't forget that after running `chkconfig --add supervisord` you also need to enable it for different run levels via `chkconfig supervisord --level 345 on` – Corey Ballou Feb 13 '13 at 13:49
5

There is a Debian/Ubuntu script in official Supervisor GitHub repo:

https://github.com/Supervisor/initscripts/blob/master/debian-norrgard

Ian Mackinnon
  • 183
  • 2
  • 15
Mike Korobov
  • 173
  • 1
  • 6
2

This is working for me on Ubuntu 10.04.3 LTS. It also appears to work in 8.04:

Add the following to /etc/init.d/supervisord

#! /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 $PIDFILE --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

Then run:

sudo chmod +x /etc/init.d/supervisord
sudo update-rc.d supervisord defaults

sudo service supervisord start

None of the other answers worked for me.

Alex N
  • 772
  • 3
  • 10
  • 23
shennyg
  • 51
  • 2
1

I added this lines into /etc/init.d/supervisord to fix "stop" argument processing:

do_stop()
{
    /usr/local/bin/supervisorctl stop all
    /usr/local/bin/supervisorctl shutdown
    # Return
    ...

and this works great for me.

rukeba
  • 111
  • 2
1

Supervisor appears to now be in apt repository, so it shouldn't be necessary to hand-craft init files, just:

sudo apt-get install supervisor

You may want to first clean out (and backup) your old files prior to installation.

Jeff Bauer
  • 316
  • 2
  • 8
  • You need to be aware that "Some of these packages can lag considerably behind the official release version. For example, Ubuntu 12.04 (released April 2012) offers a package based on Supervisor 3.0a8 (released January 2010)." (from Supervisord's documentation http://supervisord.org/installing.html#installing-a-distribution-package) – glarrain Apr 25 '13 at 16:31