How to Install Supervisor on CentOS 7,8

The supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. In this article, I’m going to show how to install Supervisor on CentOS 7,8. Let’s get started:

Table of Contents

  1. Install Supervisor
  2. Add a Service
  3. HTTP Access (optional)

Install Supervisor

The Supervisor package exists in the EPEL package repository. So, we need to install EPEL first and then supervisor:

# on cenots 8, you can use dnf instead of yum
sudo yum install epel-release -y
sudo yum install supervisor -y

Enable and start the supervisord service:

sudo systemctl enable supervisord
sudo systemctl start supervisord

Now check the status:

sudo systemctl status supervisord

Output:

● supervisord.service - Process Monitoring and Control Daemon
   Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-08-02 11:40:54 UTC; 1 day 3h ago
  Process: 5282 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
 Main PID: 5285 (supervisord)

Add a Service

We have to add our services in the /etc/supervisord.conf file. For example, I’m going to add Laravel Horizon service. You need to add your service like this one:

supervisord.conf
[program:horizon]
process_name=%(program_name)s
command=php /var/www/example.com/artisan horizon
autostart=true
autorestart=true
user=apache
redirect_stderr=true
stdout_logfile=/var/www/example.com/storage/log/horizon.log
stopwaitsecs=3600

Don’t forget to set the correct user in the config file. Now reload the supervisord service:

# reload the changes
sudo supervisorctl reread

# restart supervisor & reload the changes
sudo supervisorctl update

# check status (all running services)
sudo supervisorctl status

HTTP Access (optional)

We can enable HTTP access to see the status on a webpage. To do this, uncomment and update these lines:

supervisord.conf
[inet_http_server]
port=*:9001
username=admin
password=G4bvDy68nUFmJrPe

Then open 9001 port and visit ip_address:9001 to see webpage UI.

That’s all. Thanks for reading.