Install and Configure Supervisor on a shared hosting without root access (cpanel)

Installing and configuring Supervisor on a shared hosting can be a real headache. Previously in other articles we have seen an introduction to Supervisor and its power in managing system processes. We have also seen how to install it on different operating systems.
- Installing and configuring Supervisor on MacOS
- Installing and configuring Supervisor on GNU/Linux Debian
- Installing and configuring Supervisor on Arch Linux
Today, we will see how to install and configure Supervisor easily on a shared hosting without access to the root user.
Requirements
The basis for installing Supervisor is Python. The first thing you should make sure is that you have Python installed and can run scripts on it. Don't worry because most shared servers have Python enabled for their users. You can check which version you have installed with the following command.
$ python -V
Python 2.7.5
In this case the version is 2.7.5. Any version greater than or equal to 2.7 would serve for this purpose.
Configuring easy_install
Easy install is a Python module that allows you to download, build, install and manage Python packages. It is not the current solution for package management since it has been replaced by pip, however it is the option by which we will install Supervisor.
It is most likely that even if you have easy_install you will not be able to install packages. To verify this, try running this command and you will surely get something similar to the following:
$ easy_install
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-12911.write-test'
...
To solve this, we must configure a directory where our user can write and install packages with easy_install there. If you are on a shared hosting, your directory is probably of the type /home/usuario
. If so, you must enter by SSH, or by terminal from your cpanel and overwrite the PYTHONPATH variable to a directory within your home.
export PYTHONPATH=$PYTHONPATH:~/bin
mkdir bin supervisor.d
Note that we have also created the supervisor.d directory where we will store all the configuration files for our processes.
Installing Supervisor with easy_install
After this we must install Supervisor with easy_install indicating the installation directory.
easy_install --install-dir=~/bin supervisor
If everything went well you can proceed to create the Supervisor configuration with the following command.
echo_supervisord_conf > supervisord.conf
Once this is done you can use vim or your preferred editor to modify the supervisor.conf file and configure the process directory as follows:
[include]
files = ./supervisor.d/*.ini
After this you could start the Supervisor daemon.
supervisord -c supervisord.conf
Creating a process in Supervisor
You can configure a process in Supervisor by following this link. Once you have configured your process you must reload Supervisor.
$ supervisorctl reload
If everything went well you can check the status of the processes in the following way and verify that they are running satisfactorily.
$ supervisorctl status
apicheckerworker:apicheckerworker_00 RUNNING pid 6121, uptime 0:02:41
Persistence
Although the solution seen in this post works, a few weeks after trying this on some of my clients' servers I realized that the queues were not working. It didn't take long after I logged in to the server and realized that they had restarted the server and since that day they weren't working.
To prevent this and avoid your queues from falling when the server restarts, you must ensure that the Supervisor service starts with the cpanel session user. Just add the following line to your ~/.bashrc file.
supervisord -c ~/supervisord.conf