Supervisor is a service that makes it easy to automatically start programs without needing to create rc.d scripts. In this article we look at how to install it on various Linux distros.

Gentoo

Supervisor is in portage as app-admin/supervisor.

We want the latest version in portage installed. We’ll create the following file for that:

/etc/portage/package.accept_keywords/supervisord

1
app-admin/supervisor

To actually make the file, we’ll execute the following commands:

Console - user@hostname ~ $

1
sudo mkdir -p /etc/portage/package.accept_keywords

Console - user@hostname ~ $

1
2
3
sudo cat << EOF | sudo tee /etc/portage/package.accept_keywords/supervisord
app-admin/supervisor
EOF

Emerge Supervisor

Console - user@hostname ~ $

1
sudo emerge -av app-admin/supervisor

The default location for the Supervisor config file is /etc/supervisord.conf. The file format is a windows INI style file. See the Configuration File page of the Supervisor documentation for details. We’ll use echo_supervisord_conf to create a sample config file.

Console - user@hostname ~ $

1
echo_supervisord_conf | sudo tee /etc/supervisord.conf

Just to give an example we'll add a sample program section. This is just for demonstrative purposes; if you have a different program section to add, feel free to skip this part.

Sample program section for /etc/supervisord.conf

1
2
[program:cat]
command=/bin/cat

Console - user@hostname ~ $

1
2
3
4
cat << EOF | sudo tee -a /etc/supervisord.conf
[program:cat]
command=/bin/cat
EOF

To start Supervisor, we can use the init script:

Console - user@hostname ~ $

1
sudo /etc/init.d/supervisord start

Note If /etc/supervisord.conf doesn't exist the following error will occur:

1
2
 * supervisord: `/etc/supervisord.conf' is not readable
 * ERROR: supervisord failed to start

And so it will start up on the next reboot:

Console - user@hostname ~ $

1
sudo rc-update add supervisord default

Note While the init script should be used rather than starting it directly, Supervisor can started up directly like so:

Console - user@hostname ~ $

1
sudo supervisord -c /etc/supervisord.conf

Amazon Linux

First we’ll check if Supervisor is available in the yum repository

Console - [user@hostname ~]$

1
yum info supervisor

As of this writing it is not in the yum repository, so we will install it with pip instead.

Console - [user@hostname ~]$

1
sudo pip install supervisor

Find an initscript from Supervisor initscripts. We’ll use redhat-init-mingalevme in this case.

Download the initscript

Console - [user@hostname ~]$

1
curl -O https://raw.githubusercontent.com/Supervisor/initscripts/master/redhat-init-mingalevme

Because Supervisor was installed in /usr/local/bin we want to change PREFIX from /usr to /usr/local. Also we want to rename the script to supervisord, we’ll accomplish both with following command:

Console - [user@hostname ~]$

1
sed -e "s/^PREFIX=\/usr$/PREFIX=\/usr\/local/" redhat-init-mingalevme > supervisord

Set permissions on the initscript

Console - [user@hostname ~]$

1
chmod 755 supervisord

Console - [user@hostname ~]$

1
sudo chown root.root supervisord

And put the initscript in place

Console - [user@hostname ~]$

1
sudo mv supervisord /etc/init.d

The default location for the Supervisor config file is /etc/supervisord.conf. The file format is a windows INI style file. See the Configuration File page of the Supervisor documentation for details. We’ll use echo_supervisord_conf to create a sample config file.

Console - [user@hostname ~]$

1
echo_supervisord_conf | sudo tee /etc/supervisord.conf

Just to give an example we'll add a sample program section. This is just for demonstrative purposes; if you have a different program section to add, feel free to skip this part.

Sample program section for /etc/supervisord.conf

1
2
[program:cat]
command=/bin/cat

Console - [user@hostname ~]$

1
2
3
4
cat << EOF | sudo tee -a /etc/supervisord.conf
[program:cat]
command=/bin/cat
EOF

Start Supervisor

Console - [user@hostname ~]$

1
sudo /etc/init.d/supervisord start

Note If /etc/supervisord.conf doesn't exist the following error will occur:

1
2
3
4
5
Starting supervisord:
Error: could not find config file /etc/supervisord.conf
For help, use /usr/local/bin/supervisord -h
Error: could not find config file /etc/supervisord.conf
For help, use /usr/local/bin/supervisorctl -h

Add Supervisor as a service for chkconfig

Console - [user@hostname ~]$

1
sudo chkconfig --add supervisord

Have Supervisor turn on at boot

Console - [user@hostname ~]$

1
sudo chkconfig supervisord on

Ubuntu

For this we are using Ubuntu 16.04

Check to make sure Supervisor is available in the repository

Console - user@hostname~$

1
apt-cache show supervisor

Install Supervisor

Console - user@hostname~$

1
sudo apt-get install supervisor

Note The Ubuntu package has a different setup for supervisor config files. It will read the *.conf files in /etc/supervisor/conf.d/.

The file format is a windows INI style file. See the Configuration File page of the Supervisor documentation for details.

We'll create a sample program section and put it in /etc/supervisor/conf.d/program-cat.conf. This is just for demonstrative purposes; if you have a different program section to setup, feel free to skip this step.

/etc/supervisor/conf.d/program-cat.conf

1
2
[program:cat]
command=/bin/cat

Console - user@hostname~$

1
2
3
4
cat << EOF | sudo tee /etc/supervisor/conf.d/program-cat.conf
[program:cat]
command=/bin/cat
EOF

Make Supervisor start on boot

Console - user@hostname~$

1
sudo systemctl enable supervisor

Start Supervisor now

Console - user@hostname~$

1
sudo systemctl start supervisor

References