Table of Contents
How to install Supervisor and manage process in Ubuntu 18? This article, I will guide you to use a tool called Supervisor.
This tool allows you to manage processes in Linux. Back in my previous article on MkDocs, you can see that when we run the mkdocs serve command, the process only works at the command line.
So what if I exit the command line window? The process will stop working, we need it to work 24/7. So how?
At this point, we will need a tool that allows us to manage processes in Linux and that is the Supervisor.
Install Supervisor in Ubuntu 18.04

First, we need to install the dependencies.
apt-get install python-setuptools -yNext, use the following command to install Supervisor.
sudo easy_install supervisorSet up Supervisor service
Once the installation is completed, we need to create conf.d directory to contain the Supervisor’s configuration files.
sudo mkdir -p /etc/supervisor/conf.dRun the following command to create a configuration file for the main Supervisor service.
echo_supervisord_conf > /etc/supervisor/supervisord.confYou open up /etc/supervisor/supervisord.conf file and find the following paragraph.
;[include]
;files = relative/directory/*.iniEdit it into below. The purpose of this is to declare the process management configuration files into the conf.d directory, each process being a configuration file.
[include]
files=conf.d/*.confAnd save the configuration file.
Next, you need to create a service file for the Supervisor.
nano /etc/systemd/system/supervisord.serviceCopy the content below into the file and save it.
[Unit]
Description=Supervisor daemon
Documentation=http://supervisord.org
After=network.target
[Service]
ExecStart=/usr/local/bin/supervisord -n -c /etc/supervisor/supervisord.conf
ExecStop=/usr/local/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/local/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
Alias=supervisord.serviceReload the daemon service.
systemctl daemon-reloadNow start the Supervisor service and check its status.
systemctl start supervisord.service && systemctl status supervisord.serviceEstablish mkdocs process manager
In the article about mkdocs, we have the command to run the mkdocs service. Now, we will use the Supervisor to manage that process as a service, you can start, stop, status it.
You create /etc/supervisor/conf.d/supervisor_mkdocs.conf file with the following content.
[program:supervisor_mkdocs]
process_name=mkdocs
command=/home/source/venv/bin/mkdocs serve -a 0.0.0.0:8000
environment=PATH="/home/source/venv"
directory=/home/source/
autostart=true
autorestart=true
stderr_logfile=/var/log/mkdocs/mkdocs.err.log
stdout_logfile=/var/log/mkdocs/mkdocs.out.logYou change the information in accordance with your command and environment.
- program:supervisor_mkdocs: name your service, in this example is
supervisor_mkdocs. - process_name: name your process, it’s optional.
- command: the command you want Supervisor manage.
- environment: define the environment of the command above in the configuration file. In my example, i run the program in virtualenv, so i have to define it here.
- directory: the working directory of this service.
Next, create the directory containing the log for the mkdocs service.
mkdir /var/log/mkdocsAnd then, you could use the below command to see if the Supervisor detected a newly configured process.
root@dev:/home# sudo supervisorctl reread
supervisor_mkdocs: availableThen you can update it.
root@dev:/home# supervisorctl update
supervisor_mkdocs: added process groupOr restart the Supervisor service.
systemctl restart supervisord.serviceAnd now, you can check if the mkdocs service is working with the following command.
root@dev:/home# sudo supervisorctl
supervisor_mkdocs:mkdocs RUNNING pid 3270, uptime 4:27:22
supervisor>Conclusion
So with this article, you already know how to use the Supervisor tool to manage processes in Linux. It helps you to set up some simple commands or scripts that run realtime as a daemon service.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).