Supervisor Management Process

Supervisor Management Process

Introduction

Supervisor is a Python process management tool that can easily be used to start, restart, and shut down processes. In this article, we will explore how to install, configure, and use Supervisor to manage your applications.

Installation

To install Supervisor, run the following command:

pip install supervisor

Configuration

To configure Supervisor, you need to create a configuration file. You can do this by running the following command:

echo_supervisord_conf > /etc/supervisord.conf

This will create a default configuration file in the /etc/supervisord.conf location. You can then edit this file to suit your needs.

Supervisord Configuration File

Here is an example of a Supervisor configuration file:

[unix_http_server]
file = /tmp/supervisor.sock; UNIX socket file, supervisorctl use

[Supervisord]
logfile = /tmp/supervisord.log; log file, the default is $CWD/supervisord.log
logfile_maxbytes = 50MB; log file size beyond will rotate, the default 50MB
logfile_backups = 10; number of log files to keep the backup default 10
loglevel = info; log level, info default, other: debug, warn, trace
pidfile = /tmp/supervisord.pid; pid file
nodaemon = false; whether to start in the foreground, the default is false, that is the way to start the daemon
minfds = 1024; minimum file descriptor that can be opened, by default 1024
minprocs = 200; the minimum number of processes that can be opened, the default 200

[Rpcinterface: supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface: make_main_rpcinterface

[Supervisorctl]
serverurl = unix:///tmp/supervisor.sock; supervisord connected via UNIX socket, with the same file path portion unix_http_server[Include]. Files = relative / directory / * ini; * .conf or may be a * .ini

[Program: appname]
directory = /myproject; program startup directory
command = gunicorn -w 8 -b 0.0.0.0:9090 manage:app; Start command
autostart = true; automatically started when the start supervisord
startsecs = 5; no quit unexpectedly after starting five seconds, it is deemed to have been properly started
autorestart = true; automatic restart after abnormal exit procedure
startretries = 3; retries failed to start automatically, the default is 3
user = www; start with which users
redirect_stderr = true; redirect stderr to stdout, default false
stdout_logfile_maxbytes = 50MB; stdout log file size, default 50MB
stdout_logfile_backups = 20; stdout log file backup Number
stdout_logfile = /var/log/appname.log

Program Configuration

In the above configuration file, the [Program: appname] section is used to configure the application. The appname is the unique identification of the application, and it cannot be repeated.

All operations of the program (start, restart, etc.) are accomplished by name.

Important Notes

  1. Run command must be an absolute path.

  2. The execution of the program must be running in the foreground, if it is running in the background into the foreground.

  3. If the child process involves adding the following parameters to ensure that the child can stop:

    • stopasgroup = true
    • killasgroup = true

Starting Supervisor

To start Supervisor, you can run the following command:

supervisord -c /etc/supervisord.conf

Adding as a Service

To add Supervisor as a service, and add the boot (CentOS 7), you can create a service file:

files
# Supervisord.service
[Unit]
Description = Supervisor daemon

[Service]
Type = forking
ExecStart = /bin/supervisord -c /etc/supervisord.conf
ExecStop = /bin/supervisorctl shutdown
ExecReload = /bin/supervisorctl reload
KillMode = process
Restart = on-failure
RestartSec = 42s

[Install]
WantedBy = multi-user.target

Adding to Service and Start-up

To add the service and start-up, you can run the following commands:

cp supervisord.service /usr/lib/systemd/system/supervisord.service
systemctl start supervisord
chkconfig supervisord on

Supervisorctl

To use Supervisorctl, you can run the following commands:

supervisorctl status
supervisorctl stop appname
supervisorctl start appname
supervisorctl restart appname
supervisorctl reread
supervisorctl update

By following these steps, you can effectively use Supervisor to manage your applications.