Linux Process Management Tool supervisor Installation Configuration Tutorial

  • 2021-08-12 03:58:56
  • OfStack

Environment: CentOS 7

Official document: http://supervisord.org/

Installation

# yum install -y epel-release
# yum install -y supervisor

Start

# supervisord -c /etc/supervisord.conf
# ps -ef | grep supervisor
root 19703 1 0 17:32 ? 00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root 19715 19495 0 17:32 pts/0 00:00:00 grep --color=auto supervisor

Configuration description

Configuration file address:/etc/supervisor. conf

If there is no configuration file, you can generate it with the following command:

echo_supervisord_conf > /etc/supervisord.conf

Detailed description of configuration file:

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

; [inet_http_server]; HTTP server, providing web management interface
; port=127.0. 0.1: 9001; Web manages the IP and port running in the background. If it is open to the public network, it is necessary to pay attention to security
; username = user; Log in to the user name of the management background
; password=123; Password for login management background

[supervisord]
logfile=/tmp/supervisord. log; Log file, default is $CWD/supervisord. log
logfile_maxbytes=50MB; Log file size, if it exceeds rotate, the default is 50MB. If it is set to 0, it means that the size is not limited
logfile_backups=10; The number of log files reserved for backup defaults to 10, and setting it to 0 means no backup
loglevel = info; Log level, default info, others: debug, warn, trace
pidfile=/tmp/supervisord. pid; pid file
nodaemon = false; Whether to start in the foreground, the default is false, that is, to start in the way of daemon
minfds=1024; The minimum value of the file descriptor that can be opened, the default is 1024
minprocs=200; The minimum number of processes that can be opened, the default is 200

[supervisorctl]
serverurl=unix://tmp/supervisor. sock; Connect supervisord via UNIX socket, pathway to file1 of unix_http_server portion
; serverurl=http://127.0. 0.1: 9001; Connect supervisord through HTTP

; [program: xx] is the managed process configuration parameter, and xx is the name of the process
[program:xx]
command=/opt/apache-tomcat-8. 0.35/bin/catalina. sh run; Program start command
autostart = true; It also starts automatically when supervisord starts
startsecs=10; If there is no abnormal exit after starting for 10 seconds, it means that the process starts normally, and the default is 1 second
autorestart = true; Automatic restart after program exit, optional values: [unexpected, true, false], default to unexpected, indicating that the process is killed unexpectedly before restarting
startretries=3; The number of automatic retries that failed to start, the default is 3
user = tomcat; Which user to use to start the process, the default is root
priority=999; Process startup priority, the default is 999, and the smaller one is started first
redirect_stderr=true; Redirect stderr to stdout, default false
stdout_logfile_maxbytes=20MB; stdout log file size, default 50MB
stdout_logfile_backups = 20; Number of stdout log file backups, default is 10
; stdout log file, it should be noted that when the specified directory does not exist, it cannot be started normally, so it is necessary to manually create the directory (supervisord will automatically create the log file)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup = false; The default is false. When a process is killed, whether to send an stop signal to this process group, including child processes
killasgroup = false; The default is false, which sends kill signals to process groups, including child processes

; Include additional configuration files
[include]
files = supervisord.d/*. ini; You can specify one or more configuration files that end with. ini

Configuring Tomcat Test

/etc/supervisord.d/tomcat.ini

[program:tomcat]
command=/opt/apache-tomcat-8.0.44/bin/catalina.sh run
stdout_logfile=/opt/apache-tomcat-8.0.44/logs/catalina.out
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true

Restart supervisor

supervisord -c /etc/supervisord.conf

View

[root@gr5bm1tynui4toof-0622769 system]# supervisorctl
tomcat RUNNING pid 21609, uptime 0:25:15


Related articles: