Setting up Supervisor on a Shared Hosting Without Root Access

To set up supervisor on a shared host can be a pain in the neck when you don’t have root access on your server. But as long as you have ssh access to your server and you have a python 2.* cli installed on your server, getting supervisor up and running is not too difficult:

First, connect to your server through ssh; on a shared host, you’re likely to find yourself in a subfolder such as `/home/yoursiteuser/`.

ssh yoursiteuser@example.com

If you’re logging in through ssh for the first time or you have not set up password-less ssh access, you may be prompted to type in your password at this point.

Once you’re in, verify that you have python 2 installed by running the following command

python -V

You should see something like

Python 2.7.5

According to the Supervisor documentation, it has to be Python 2.4 or later. Supervisor will not work with any version of Python 3

INSTALLING SUPERVISOR

Because you don’t have root access to the server, simply using the documented easy_install supervisor or python setup.py install commands will give you no joy. You may get a message like the one below:

error: can’t create or remove files in install directory
The following error occurred while trying to add or remove files in the installation directory:
[Errno 13] Permission denied: ‘/usr/lib/python2.7/site-packages/test-easy-install-26871.write-test’
The installation directory you specified (via — install-dir, — prefix, or the distutils default setting) was:
/usr/lib/python2.7/site-packages/
Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or “root” account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable.
For information on other options, you may wish to consult the documentation at: https://pythonhosted.org/setuptools/easy_install.html
Please make the appropriate changes for your system and try again.

What you need to do is use the — install-dir flag to install supervisor in a custom location to which your user has full access. You can use the bin directory in your subfolder, i.e. /home/yoursiteuser/bin, or create it if it doesn’t already exist. Add this directory to the PYTHONPATH environmental variable by running the following command;

export PYTHONPATH=$PYTHONPATH:/home/yoursiteuser/bin

Now you can verify that you have your custom bin directory in the PYTHONPATH environmental variable by typing

echo $PYTHONPATH

ACTUALLY INSTALLING SUPERVISOR

Now you can install Supervisor using the easy_install command like so

easy_install — install-dir=/home/yoursiteuser/bin supervisor

This should successfully install Supervisor on your server. Yaay!

USING SUPERVISOR

To use supervisor, you first need to create a configuration file with the sample configuration. You can do this by running the following command:

echo_supervisord_conf > supervisord.conf

This will create the configuration file named supervisord.conf in the current directory. Now you can run supervisor like so;

supervisord –c supervisord.conf

The -c flag tells supervisor where to find the configuration file, in this case it’s right there in the same current directory.

Refer to the documentation for more information about adding programs to your configuration file.

STOPPING SUPERVISOR

In case you ever need to stop the supervisord service, like when you need to make changes to the configuration and rerun it. You need to find the process by its process id (PID) and kill it, and then run it again: To find the process, run

ps -ef | grep supervisord

This will show you something similar to

yoursit+ 28192 1 0 22:28 ? 00:00:00 /usr/bin/python /home/yoursiteuser/bin/supervisord -c supervisord.conf
yoursit+ 29039 27189 0 22:40 pts/0 00:00:00 grep — color=auto supervisord

Your PID will be the second item, to kill it type the following;

kill –s SIGTERM 28192

This will kill your supervisord process, so that you can edit the configuration and rerun it.