Build personal server based on centos7: Supervisor installation and deployment

introduce

How to ensure the normal operation of services is the concern of programmers. You should know that after the development of the project, the deployment to the server will be abandoned, which is not the attitude you and I should have. When the service leaves abnormally in the middle of the night, the head will be big. How can we make our services run more stably? So please introduce the main character supervisor to you today!

supervisor is a daemons tool developed based on python. It supports the process management of Linux/Unix system and provides the control of interactive command line mode and HTTP web page mode for processes. Since the release of version 4.0, it has fully supported the deployment of python2 and python3.

Deployment and installation

Get supervisor

Because it is directly based on centos7, you can install it directly through the yum command, and when you install it directly through yum, the startup script will be generated automatically, which is convenient to configure the supervisor to start with the system.

# Install download source
sudo yum install epel-release
sudo yum install supervisor

configuration file

After installation, the main configuration file and sub configuration file directory will be generated in / etc directory

Master profile

# /etc/supervisord.conf
# Key contents

# To enable web management, configure as follows
[inet_http_server]
port=0.0.0.0:9001
username=user
password=123
# The following configuration is used to specify the sub profile path and valid sub profile suffix `. ini`
[include]
files = supervisord.d/*.ini

Sub profile directory

# /etc/supervisord.d/
# Example / etc / supervisor.d/frp_client.ini
[program:frp_client]
directory = /opt/frp ; Program start directory
command = /opt/frp/frpc -c frpc.ini   ; Start the command, and you can see that it is the same as the command started manually on the command line
autostart = true     ; stay supervisord It starts automatically when it starts
startsecs = 5        ; If there is no abnormal exit after 5 seconds of startup, it will be regarded as normal startup
autorestart = true   ; Automatic restart after abnormal exit of program
startretries = 3     ; Number of automatic retries for startup failure, default is 3
user = wuyue          ; Which user to start with
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
; 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 = /data/logs/frp_client_stdout.log
;
; ; Can pass environment To add the required environment variables, a common use is to modify PYTHONPATH
; ; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere

matters needing attention:

  1. It is better to use the absolute path for command. When using the relative path, the supervisor may not find the startup command, resulting in the failure of service startup;
  2. If the program requires the use of ordinary users to run, you must configure the user as the corresponding ordinary user, otherwise the root user will be used to start the program;
  3. The configuration of stdout ﹣ logfile is good for locating program exceptions.

Startup service

sudo systemctl start supervisord.service
# Configure service startup
sudo systemctl enable supervisord.service

Command line mode

sudo supervisorctl
frp_client                       RUNNING   pid 1468, uptime 23:57:52
hass                             RUNNING   pid 1354, uptime 23:57:54
jupyterlab                       STOPPED   Not started
wukong_robot                     STOPPED   Not started

HTTP management mode

Enter the configured user name and password

So far, it's convenient to monitor and manage the process. Even if the server is down and restarted, the supervisor can successfully restart the deployed service, which is very rare~

Published 6 original articles, praised 0, visited 1229
Private letter follow

Keywords: supervisor sudo yum Python

Added by alext on Sun, 19 Jan 2020 16:52:22 +0200