supervisor simple to use

I. INTRODUCTION

supervisor is to use Python developed a C / S services. It is a process management tool under Linux / Unix systems. It can easily monitor, start, stop, restart one or more processes. Supervisor with process management, when a process is killed unexpectedly, supervisort to monitor the process of death, it will automatically pull up again, it is convenient to do the process of automatic recovery functions, eliminating the need to write shell scripts to control.

Note: You can only use on Unix systems, Windows does not take

Second, the installation

yum way

# Update yum source 
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7 .repo 

# yum install 
yum install supervisor -y

Third, the configuration file

cat /etc/supervisord.conf

[unix_http_server] 
File = / opt / supervisor.sock; supervisorctl Socket file uses 
the chmod = 0700                  ; Socket file permissions 
; chown = the nobody: nogroup; Socket File UID: GID owner 
; username = User; default IS NO username (Open Server) 
; password = 123; default IS NO password (Open Server) 

[inet_http_server]; Web management interface, i.e. do restart page, and stop 
port = *: 9001                 ; listen port 
username = ADMIN; user 
password = 123                ; password 

[supervisord ]
logfile= / var / log / supervisord.log; supervisor CWD log file $ / supervisord.log 
logfile_maxbytes = 50MB; log file size, default 50MB 
logfile_backups =. 1            ; Reserved a default file 
LogLevel = info; log level, the default info; other formats : Debug, the warn, the trace 
PidFile = / var / rUN / supervisord.pid; PID file 
nodaemon = to false; whether in the foreground, the default false, a daemon running mode 
minfds = 1024                   ; minimum can open file descriptor 
minprocs = 200 is                  ; minimum number of processes can be opened 
; the umask = 022; File Creation process the umask; default 022 
; User=chrism                 ; default is current user, required if root
;identifier=supervisor       ; supervisord identifier, default is 'supervisor'
;directory=/opt              ; default is not to cd during start
;nocleanup=true              ; don't clean up tempfiles at start; default false
;childlogdir=/opt            ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false


[supervisorctl]
serverurl=unix:///opt/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available


[include]
files = /etc/supervisord.d/*.conf ;子文件

Fourth, with the modified file

vim /etc/supervisord.conf

   [inet_http_server] ; inet (TCP) server disabled by default

  port=0.0.0.0:9001 ; ip_address:port specifier, *:port for all iface

  username=user ; default is no username (open server)

  password=123 ; default is no password (open server)

  [include]

  files = /etc/supervisord.d/*.conf

  创建.conf目录     mkdir /etc/supervisord.d

  创建nginx配置文件  vim nginx.conf

  [program:nginx]

  autorestart=True

  autostart=True

  redirect_stderr=True

  ; Environment = the PATH = ""   

  the Command = / usr / sbin / nginx -g ' daemon OFF; ' ; 
  sbin / nginx this command is the default background to start, but the supervisor can not monitor daemon, the supervisor has been executing this command, resulting in nginx has been restarted, with -g 'daemon off;' parameter solve this problem, this means that the parameter in the foreground   User
= the root   ; process_name =% (program_name) S% (process_num) D   ; numprocs =. 3      ; Directory = / the root /   stdout_logfile_maxbytes = 20MB   stdout_logfile_backups = 20 is   ; stdout   stdout_logfile = / var / log / Supervisor / nginx.log   stderr_logfile = / var / log / Supervisor / nginx_error.log

Five, supervisord Detailed configuration block

- logfile: log file path
 - logfile_maxbytes: automatic log file rotation number reaches, the unit is KB, MB, GB. If set to 0 not to limit the log file size
 - logfile_backups: log backup rotation number, the default is 10, if set to 0, no backup
 - LogLevel: error, The warn, info, Debug, the trace, blather, Critical
 - PidFile : pid file path
 - the umask: the umask value, a default 022
 - nodaemon: If set to true, the supervisord started in the foreground, rather than start the daemon
 - minfds: supervisord minimum number of available file descriptors before the successful launch, the default 1024
 - minprocs: supervisord minimum number of process descriptor available before a successful start, the default 200
 - nocleanup: prevent supervisord remove existing child process log files at startup
 - childlogdir: automatic start child processes of the log directory
 - the User: supervisord users running
 - directory: supervisord daemon running time to switch to this directory
 -strip_ansi: eliminate the escape sequences child process log files
 - environment: a k / v list to the list

Six, program configuration in detail

- the Command: The command to start using the program, can be absolute or relative path
 - process_name: a python string expression used to indicate the start of this process supervisor name, the default is% (program_name) S
 - numprocs: Supervisor start multiple instances of this procedure, if numprocs> 1, then the expression must process_name% (process_num) S, defaults. 1
 - numprocs_start: an int offset value, when the calculated value is used to start an instance of numprocs
 - priority : weight, can control sequence when the program starts and closed, the lower the weight: start earlier, the later closed. The default value is 999
 - autostart: If set to true, when supervisord start, the process will automatically restart.
- autorestart is: value can be false, true, unexpected. false: the process will not automatically restart, unexpected: when the exit code when the program exits not exitcodes defined, the process will restart, true: the process will restart when an unconditional withdrawal.
- startsecs: After the program how long to wait before starting the program considered successful start
 - startretries: supervisord attempts of trying to start a program. The default is 3
 - exitcodes: an expected return exit code, the default is 0,2 .
- stopsignal: when the stop request is received, transmits a signal to the program, the default is the TERM signal, may be the HUP, the INT, the QUIT, the KILL, USR1, or the USR2.
- stopwaitsecs: time to wait when the operating system sends a signal to the SIGCHILD supervisord
 - stopasgroup: If set to true, the supervisor will send a stop signal to the whole process group
 - killasgroup: If set to true, then the SIGKILL signal is sent to the program time, the whole process will be sent to the group, its children are also affected.
- the User: If supervisord run as root, this will be used to set the user startup routines
 - redirect_stderr is: If set to true, the process will be the standard error output to standard output file descriptor supervisord background.
- stdout_logfile: the standard output of the process of writing to a file, if stdout_logfile not set or set to AUTO, the supervisor will automatically choose a file location.
- automatically rotate after the standard output log file reaches the number, the unit is KB, MB, GB: stdout_logfile_maxbytes. If set to 0 not to limit the log file size
 - stdout_logfile_backups: Quantity backup output log rotation, default is 10, if set to 0, is not backed
 -stdout_capture_maxbytes: When the process is in stderr capture mode mode, the maximum bytes written into the FIFO queue value, the unit can be KB, MB, GB
 - stdout_events_enabled: If set to true, when the process of writing its stderr to file descriptors , PROCESS_LOG_STDERR event is triggered
 - : stderr_logfile the output of a process error log file, unless redirect_stderr parameter is set to true
 - automatically rotate after the error log files reach the number, the unit is KB, MB, GB: stderr_logfile_maxbytes. If set to 0 not to limit the log file size
 - stderr_logfile_backups: Error Number backup log rotation, default is 10, if set to 0, no backup
 - stderr_capture_maxbytes: When a process model is stderr capture mode, the write FIFO queue the maximum bytes value, the unit can be KB, MB, GB
 - stderr_events_enabled: If set to true, when the process of writing its stderr to file descriptors, PROCESS_LOG_STDERR event will be triggered
 - environment: a k / v pair list list
 - directory: supervisord when generating the child process will change to that directory
 -umask: umask setting process
 - serverurl: whether to allow the child process and internal HTTP server communication, if set to AUTO, supervisor will automatically construct a url

 Seven, execution

# supervisord -c /etc/supervisord.conf
# supervisorctl

# 重启supervisor
# supervisorctl reload

 

Guess you like

Origin www.cnblogs.com/angelyan/p/10984390.html