(Centos7) Supervisor installation and deployment

Keywords: Linux supervisor Tomcat Unix socket

1.yum installation

yum install epel-release
yum install -y supervisor

2. Configuration file
After the supervisor is installed successfully, no default configuration file is provided. You can generate the initialization configuration file of the supervisor by running the echo supervisor conf program

mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf

3. Profile parameter description
There are many configuration parameters for supervisor. Please refer to the official documents for details.
Note: the configuration beginning with a semicolon (;) indicates a comment

[unix_http_server]
file=/tmp/supervisor.sock   ;UNIX socket Documents, supervisorctl Will use
;chmod=0700                 ;socket Documentation mode,The default is 0700
;chown=nobody:nogroup       ;socket Documentation owner,Format: uid:gid

[inet_http_server]         ;HTTP Server, providing web Management interface
port=0.0.0.0:9001        ;Web Manage background running IP And port. If you open it to the public network, you need to pay attention to security
;username=user              ;User name of login management background
;password=123               ;Password of login management background

[supervisord]
logfile=/tmp/supervisord.log ;Log file, default is $CWD/supervisord.log
logfile_maxbytes=50MB        ;Log file size, exceeding rotate,Default 50 MB,If set to 0, it means unlimited size
logfile_backups=10           ;The number of log file reserved backups is 10 by default. If it is set to 0, it means no backup
loglevel=info                ;Log level, default info,Other: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid file
nodaemon=false               ;Whether to start in the foreground, the default is false,That is to say daemon Start by
minfds=10240                  ;Minimum value of file descriptors that can be opened, default: 1024
minprocs=200                 ;Minimum number of processes that can be opened, default 200

[supervisorctl]
;serverurl=unix:///tmp/supervisor.sock; connect supervisor through UNIX socket, and the path is the same as the file in the HTTP server part of UNIX
serverurl=http://0.0.0.0:9001; connect to supervisor through HTTP

; [program:xx]Is the managed process configuration parameter, 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       ; stay supervisord It starts automatically when it starts
startsecs=10         ; If there is no abnormal exit after 10 seconds of starting, it means that the process is started normally. The default is 1 second
autorestart=true     ; Automatic restart after program exit,Optional values:[unexpected,true,false],Default is unexpected,Indicates that the process is not restarted until it is accidentally killed
startretries=3       ; Number of automatic retries for startup failure, default is 3
user=tomcat          ; Which user is used to start the process? The default is root
priority=999         ; Process start priority, 999 by default, priority start with small value
redirect_stderr=true ; hold stderr Redirection to stdout,default false
stdout_logfile_maxbytes=20MB  ; stdout Log file size, default 50 MB
stdout_logfile_backups = 20   ; stdout Number of log file backups, default is 10
; stdout For log files, it should be noted that when the specified directory does not exist, it cannot be started normally, so you need to create the directory manually( supervisord Automatically create log file)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false     ;Default is false,Whether to send to this process group when the process is killed stop Signals, including subprocesses
killasgroup=false     ;Default is false,Send to process group kill Signals, including subprocesses

;Include other profiles
[include]
files = /etc/supervisor/config.d/*.ini    ;You can specify one or more to.ini Profile ended
;files = /opt/absolute/filename.ini /opt/absolute/*.ini foo.conf config??.ini   ; include Example

4. Process management configuration parameters are not recommended to be written in the supervisor.conf file. Each process should write a configuration file to be included in the supervisor.conf file in the directory specified by include.
Create / etc/supervisor/config.d directory to store configuration files for process management

mkdir /etc/supervisor/config.d

Here is an example of configuring the Tomcat process:

cat  /etc/supervisor/config.d/tomcat.ini 

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

5. Start the Supervisor service

supervisord -c /etc/supervisor/supervisord.conf

Now you can browse to http://ip:9001
You can also command to start and view services:

[root@localhost supervisor]# supervisorctl restart tomcat
tomcat: stopped
tomcat: started
[root@localhost supervisor]# supervisorctl status
tomcat                           STOPPED   Nov 19 11:22 AM

6. Enable self start configuration
Enter the / lib/systemd/system directory and create the supervisor.service file

vim supervisor.service
//Document content:

[Unit]
Description=supervisor
After=network.target

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

[Install]
WantedBy=multi-user.target

Set startup

systemctl enable supervisor.service
systemctl daemon-reload

Modify file permissions to 766

chmod 766 supervisor.service

Posted by Valdhor on Tue, 19 Nov 2019 12:13:26 -0800