Atlantic.Net Blog

How to Install and Configure Supervisor on Ubuntu 20.04

Hitesh Jethva
by Atlantic.Net (228 posts) under VPS Hosting
0 Comments

In Linux, Supervisor is a client/server system that allows users to control numerous processes over an operating system such as UNIX. The following are the key benefits of Supervisor:

  • Convenience: Writing rc.d for all single process instances is inconvenient. Rc.d scripts, similarly, do not restart crashed processes automatically. However, Supervisor can be configured to automatically restart processes when they crash.
  • Accuracy:  In UNIX, it is frequently difficult to get accurate up/down status on processes. Supervisor starts processes as sub-processes, so it is aware of the up/down status of its children. This is easy to query for an end-user.

In this tutorial, we will learn how to install Supervisor and configure it to manage the Nginx process on Ubuntu 20.04.

Prerequisites

  • A fresh Ubuntu 20.04 VPS on the Atlantic.Net Cloud Platform.
  • A root password is configured on your server.

Step 1 – Create an Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Ubuntu 20.04 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install Supervisor

By default, the Supervisor package is available in the Ubuntu 20.04 default repository. You can install it with the following command:

apt-get install supervisor -y

After installing Supervisor, you can verify the installed version of the Supervisor with the following command:

supervisord -v

You should get the following output:

4.1.0

Next, verify the status of the Supervisor service with the following command:

systemctl status supervisor

You should get the following output:

  • supervisor.service - Supervisor process control system for UNIX
Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-10-01 13:31:42 UTC; 9s ago
Docs: http://supervisord.org
Main PID: 14419 (supervisord)
Tasks: 1 (limit: 2353)
Memory: 14.2M
CGroup: /system.slice/supervisor.service
└─14419 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

Step 3 – Enable Supervisor Web Interface

Supervisor provides a web-based interface to manage all processes, but it is disabled by default. You can enable it by editing the file /etc/supervisor/supervisord.conf.

nano /etc/supervisor/supervisord.conf

Add the following lines:

[inet_http_server]
port=*:9001
username=admin
password=admin

Save and close the file, then restart the Supervisor service to apply the changes:

systemctl restart supervisor

Step 4 – Manage Nginx Process with Supervisor

In this section, we will learn how to control the Nginx process with Supervisor.

First, install the Nginx server with the following command:

apt-get install nginx -y

After installing Nginx, you will need to stop and disable the Nginx service as we will use Supervisor to manage the Nginx process.

You can stop and disable the Nginx service with the following command:

systemctl stop nginx
systemctl disable nginx

Next, you will need to create a standalone configuration file for each service that you want to manage. You can create an Nginx configuration file with the following command:

nano /etc/supervisor/conf.d/nginx.conf

Add the following lines:

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
startretries=5
numprocs=1
startsecs=0
process_name=%(program_name)s_%(process_num)02d
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MB

Save and close the file when you are finished. Next, tell the Supervisor to know about the new config:

supervisorctl reread

You should get the following output:

nginx: available

Next, tell Supervisor to start the Nginx service:

supervisorctl update

You should get the following output:

nginx: added process group

Next, verify whether Supervisor started the Nginx service with the following command:

supervisorctl

You should get the following output:

nginx:nginx_00                   RUNNING   pid 15717, uptime 0:00:13

If you want to stop the Nginx service, run the following command:

stop nginx:nginx_00

Output:

nginx:nginx_00: stopped

To start the Nginx service again, run the following command:

start nginx:nginx_00

Output:

nginx:nginx_00: started

Now, exit from the Supervisor shell with the following command:

exit

You can also verify the Nginx process with the following command:

ps aux | grep nginx

You should get the following output:

root       15721  0.0  0.4  57176 10064 ?        S    14:14   0:00 nginx: master process /usr/sbin/nginx -
g daemon off;
www-data   15722  0.0  0.2  57828  5340 ?        S    14:14   0:00 nginx: worker process
www-data   15723  0.0  0.2  57828  5340 ?        S    14:14   0:00 nginx: worker process

Step 5 – Access Supervisor Web Interface

You can now access the Supervisor web interface using the URL http://your-server-ip:9001. You will be asked to provide a username and password as shown below:

Provide your admin username and password that you have defined in the configuration, file then click on the Sign-in button. You should see the Supervisor web interface in the following page:

Conclusion

In this guide, you learned how to install Supervisor and enable the web interface on Ubuntu 20.04. You also learned how to control the Nginx process with Supervisor. Try controlling processes on your Linux VPS hosting account with Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources