How to Install and Configure Supervisord on CentOS 7

supervisordcentos 7 installationprocess managementsystemctl commandssupervisord configuration
Published·Modified·

Supervisord is a process management tool for Linux/Unix systems.

Installation

yum install supervisor

Enable Supervisord at Boot

systemctl enable supervisord.service

Configuration Files

The main configuration file for supervisord is /etc/supervisord.conf. The custom configuration directory is /etc/supervisord.d, where files must have a .ini extension.

Supervisord Commands

Start

systemctl start supervisord.service

Stop

systemctl stop supervisord.service

Restart

systemctl restart supervisord.service

Configuring Processes

For example, to configure an Nginx process:

vim /etc/supervisord.d/nginx.ini

Content:

[program:nginx]
; directory = /www/lanmps/bin                                 ; Program start directory
command = /www/lanmps/bin/nginx start                ; Start command, same as manual CLI command
autostart = true                                                         ; Automatically start when supervisord starts
startsecs = 5                                            ; Considered successfully started if no abnormal exit within 5 seconds
autorestart = true                                   ; Automatically restart if the program exits abnormally
startretries = 3                                        ; Number of retries on startup failure, default is 3
user = www                                           ; User to run the process
redirect_stderr = true                               ; Redirect stderr to stdout, default is false
stdout_logfile_maxbytes = 20MB                   ; Maximum size of stdout log file, default is 50MB
stdout_logfile_backups = 20                          ; Number of stdout log file backups
; stdout log file, note that if the specified directory does not exist, the process cannot start normally, so the directory must be created manually (supervisord will create log files automatically)
stdout_logfile = /www/logs/usercenter_stdout.log
stopasgroup=false     ; Default is false, whether to send stop signal to the process group when the process is killed, including child processes
killasgroup=false     ; Default is false, whether to send kill signal to the process group, including child processes

; Environment variables can be added via environment, a common use case is modifying PYTHONPATH
; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere

Supervisord Client Management Commands

supervisorctl status                            # Check status
supervisorctl stop nginx                # Stop nginx
supervisorctl start nginx               # Start nginx
supervisorctl restart nginx             # Restart nginx
supervisorctl reread
supervisorctl update                    # Update new configuration

Note: nginx refers to the program name defined in the configuration.

Other Information

Components

  • supervisord: Service daemon
  • supervisorctl: Command-line client
  • Web Server: Provides a web interface with functionality similar to supervisorctl
  • XML-RPC Interface: XML-RPC interface

Configuration File Explanation

Configuration file: /etc/supervisord.conf

[unix_http_server]
file=/tmp/supervisor.sock   ; UNIX socket file, used by supervisorctl
;chmod=0700                 ; Socket file mode, default is 0700
;chown=nobody:nogroup       ; Socket file owner, format: uid:gid

;[inet_http_server]         ; HTTP server, provides web management interface
;port=127.0.0.1:9001        ; IP and port for web management backend, if exposed to public network, security must be considered
;username=user              ; Username for logging into the management backend
;password=123               ; Password for logging into the management backend

[supervisord]
logfile=/tmp/supervisord.log ; Log file, default is $CWD/supervisord.log
logfile_maxbytes=50MB        ; Log file size, rotates when exceeded, default is 50MB, set to 0 for no limit
logfile_backups=10           ; Number of log file backups, default is 10, set to 0 for no backups
loglevel=info                ; Log level, default is info, others: debug, warn, trace
pidfile=/tmp/supervisord.pid ; PID file
nodaemon=false               ; Whether to start in foreground, default is false, starts as a daemon
minfds=1024                  ; Minimum number of open file descriptors, default is 1024
minprocs=200                 ; Minimum number of open processes, default is 200

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; Connect to supervisord via UNIX socket, path must match the file in unix_http_server section
;serverurl=http://127.0.0.1:9001 ; Connect to supervisord via HTTP

; [program:xx] contains configuration parameters for managed processes, where xx is the process name
[program:xx]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run  ; Program start command
autostart=true       ; Automatically start when supervisord starts
startsecs=10         ; Considered successfully started if no abnormal exit within 10 seconds, default is 1 second
autorestart=true     ; Automatically restart after program exit, options: [unexpected, true, false], default is unexpected, meaning restart only after unexpected termination
startretries=3       ; Number of retries on startup failure, default is 3
user=tomcat          ; User to run the process, default is root
priority=999         ; Process startup priority, default is 999, smaller values have higher priority
redirect_stderr=true ; Redirect stderr to stdout, default is false
stdout_logfile_maxbytes=20MB  ; Maximum size of stdout log file, default is 50MB
stdout_logfile_backups = 20   ; Number of stdout log file backups, default is 10
; stdout log file, note that if the specified directory does not exist, the process cannot start normally, so the directory must be created manually (supervisord will create log files automatically)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false     ; Default is false, whether to send stop signal to the process group when the process is killed, including child processes
killasgroup=false     ; Default is false, whether to send kill signal to the process group, including child processes

; Include other configuration files
[include]
files =/etc/supervisord.d/*.ini    ; Can specify one or more configuration files ending with .ini

References:


Original source: Centos 7.X 安装 supervisord. All rights reserved by the original author. If there is any infringement, please contact QQ: 337003006 for deletion.