Turn: https: //blog.csdn.net/zou79189747/article/details/80403016
Brief introduction
supervisor is developed with a client Python / server services, it is a process management tool under Linux / Unix systems. You can easily monitor, start, stop, restart one or more processes. Management supervisor with the process, when a process is killed unexpectedly, supervisor to monitor the process of death, it will automatically restart, it is convenient to do the process of automatic recovery functions, eliminating the need to write shell scripts to control himself.
Installation
After configuring yum source, can be installed directly
yum install supervisor
Configuration
After installation file and generate a supervisord.conf a supervisord.d file directory in / etc / will
supervisord.conf some default configuration, you can modify:
[unix_http_server]
File = / tmp / supervisor.sock; Socket the UNIX file, supervisorctl use
; chmod = 0700; mode socket file, the default is 0700
; the nobody = chown: nogroup; owner Socket file format: UID: GID
; [inet_http_server]; HTTP server to provide web management interface
; port = 127.0.0.1: 9001; Web management background IP and port, if open to the public, need to pay attention to safety
; username = user; the user name to log management background
; password = 123; login password management background
[supervisord]
logfile = / tmp / supervisord.log; log file, the default is CWD $ / supervisord.log
= 50MB logfile_maxbytes; log file size beyond will rotate, the default 50MB, if set to 0, not to limit the size
logfile_backups = 10; number of log files to keep the backup default 10 set to 0 backup
loglevel = info; log level, info default, other: debug, warn, trace
PidFile = / tmp / supervisord.pid ; pid file
nodaemon = false; if started in the foreground, the default is false, that is the way to start the daemon
minfds = 1024; minimum file descriptors that can be opened, the default 1024
minprocs = 200; the minimum number of processes that can be opened, the default 200
[supervisorctl]
ServerURL = UNIX: ///tmp/supervisor.sock; via UNIX socket supervisord, consistent with the path portion unix_http_server File
; ServerURL = HTTP: //127.0.0.1: 9001; supervisord connected by way of HTTP
; [ program: xx] is being managed process configuration parameters, xx is the name of the process
[program: xx]
the command = / opt / the Apache-Tomcat-8.0.35 / bin / catalina.sh RUN; startup command
autostart = true; in supervisord start automatically when starting
startsecs = 10; no quit unexpectedly after starting 10 seconds, it means that the process starts normally, the default is 1 second
autorestart = true; automatically restart after the program exits, optional value: [unexpected, true, false ], the default is unexpected, means that the process accidentally killed after the restart
startretries = 3; failed to start automatically retries, the default is 3
user = tomcat; to start the process with which the user, the default is the root
priority = 999; priority process starts, the default 999, the value of a small boot priority
redirect_stderr = true; redirect stderr to stdout, default false
stdout_logfile_maxbytes = 20MB; stdout log file size, default 50MB
stdout_logfile_backups = 20; stdout log file backup number, the default is 10
; stdout log file, you need to pay attention to when not start properly when the specified directory does not exist, it is necessary to create the directory manually (supervisord automatically creates a log file)
stdout_logfile = / opt / Apache Tomcat-8.0.35-/ logs / catalina.out
stopasgroup = to false; default is false, when the process is killed, whether to send a signal to stop the process group including the child process
killasgroup = false; default is false, the kill signal group transmission process, the child process comprising
; comprise other profiles
[the include]
files = relative / Directory / INI *;. may specify one or more end to .ini configuration file
Note: [include] the default configuration is to develop * .ini, due to personal habits named * .conf files, modify the configuration is as follows:
[include]
files = relative/directory/*.conf
supervisord.d directory used to store user-defined configuration process, refer to:
[program:es]
command=/opt/software/elasticsearch/bin/elasticsearch
user=es
stdout_logfile=/opt/supervisor_test/run.log
autostart=true
autorestart=true
startsecs=60
stopasgroup=true
ikillasgroup=true
startretries=1
redirect_stderr=true
Note: supervisor can not monitor background processes, command command can not run in the background
Services segment starts
supervisord -c load the specified configuration file /etc/supervisord.conf // start
Common Commands
supervisorctl is supervisord command-line client tools
supervisorctl status: view all processes of state
supervisorctl stop es: Stop es
supervisorctl Start es: Start es
supervisorctl restart es: Restart es
supervisorctl Update: After the configuration file modification can use this command to load the new configuration
supervisorctl reload: restart all configurations program
Es to replace all can manage all processes configuration
Direct Input: supervisorctl supervisorctl entering the shell interface, the above command can be used directly without supervisorctl
Q&A
1、unix:///var/run/supervisor/supervisor.sock no such file
unix:///var/run/supervisor/supervisor.sock refuse connect.
Problem Description: supervisor did not start the service directly wrong supervisorctl newspaper
Solution: supervisord -c /etc/supervisord.conf
2, command specified process has been up, but also continue to restart supervisor
Problem Description: command in start-up mode to start the background, leading to not recognize pid, then continue to restart, I am using elasticsearch, command specifies the $ path / bin / elasticsearch -d, stepped pit
Solution: supervisor can not detect the background to start the process of pid, while the supervisor is itself a background daemon started, so do not worry about it
3, launched more than supervisord service, resulting in normal service can not be closed
Problem Description: Before running supervisord -c /etc/supervisord.conf, I run directly through supervisord -c /etc/supervisord.d/xx.conf, resulting in some being more superviord management process, the process can not be closed properly.
Solution: Use ps -fe | grep supervisord View all started off supervisord services, kill related processes.