Supervisor overview
Supervisor is a Client/Server mode system that allows users to monitor and control multiple processes, or programs, on a unix like operating system. Supervisor has the same functions as launchd, daemon tools, runit and other programs. Different from some of them, it does not replace init as a "process with id 1". On the contrary, it is used to control applications. Like starting other programs, it is commonly understood that the process programs managed by the supervisor service run as child processes of the supervisor, and the supervisor is the parent process. Supervisor to monitor the startup and shutdown of the management sub process and the automatic startup after abnormal exit.
Supervisor component
1) Supervisor: Service daemon
The process name of the supervisor server is supervisor. It is mainly responsible for starting subroutines in its own call, responding to client commands, restarting crashed or exited processes, recording the output of its subprocesses stdout and stderr, and generating and processing configuration files corresponding to "event" server processes in the subprocess life cycle. Usually, the path is stored in / etc / Supervisor In conf a. This profile is in INI format.
2) supervisorctl: command line client
The client name of the supervisor command line is supervisorctl. It provides a shell like interactive interface for supervisor. Using supervisorctl, users can view different supervisord process lists and obtain the status of control sub processes, such as stopping and starting sub processes
3) Web Server: provides a WEB operation interface equivalent to the function of supervisorctl
One can view and control the status of the process through the Web interface. The default listening is on 9091.
4) XML-RPC Interface: XML-RPC interface
supervisor XML-RPC interface for control
Supervisor installation
$ cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) $ rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # Install supervisor using yum or up2date $ yum install -y supervisor # Startup self startup $ systemctl enable supervisord # start-up $ systemctl start supervisord
Supervisor profile description
[unix_http_server] file=/tmp/supervisor.sock ; socket The path to the file, supervisorctl use XML_RPC and supervisord Communication is through it of If not, supervisorctl It won't work If not set, the default value is none. Not required ;chmod=0700 ; This is simple, just modify the one above socket File permissions are 0700 If it is not set, it defaults to 0700. Not required ;chown=nobody:nogroup ; Like this, modify the one above socket The group of the file is user.group If it is not set, it is enabled by default supervisord The user and group of the process. Not required ;username=user ; use supervisorctl When connecting, authenticated users If it is not set, it defaults to no user. Not required ;password=123 ; The password corresponding to the user name above can be used directly or in plain code SHA encryption For example:{SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d Not set by default... Not required ;[inet_http_server] ; Listen in TCP Upper socket,Web Server And remote supervisorctl All need him If it is not set, it is not enabled by default. Not required ;port=127.0.0.1:9001 ; This is listening IP And ports, listening for all IP use :9001 or*:9001. This must be set as long as the above[inet_http_server]When it is turned on, it must be set ;username=user ; This and the one above uinx_http_server The same. Not required ;password=123 ; This is the same. Not required [supervisord] ;This is mainly the definition supervisord Some parameters of the server process This must be set, not set, supervisor You don't have to work logfile=/tmp/supervisord.log ; This is supervisord The log path of the main process. Note that it does not match the log of the child process. Default path $CWD/supervisord.log,$CWD Is the current directory.. Not required logfile_maxbytes=50MB ; This is the maximum size of the log file above, when it exceeds 50 M A new day will be generated Log file. When set to 0, it means that the file size is not limited The default value is 50 M,Not required. logfile_backups=10 ; The number of log files maintained. The above log files are greater than 50 M A new file is generated. file When the number is greater than 10, the original old file is overwritten by the new file, and the number of files will remain 10 When set to 0, it means that the number of files is not limited. By default, it is 10... Not required loglevel=info ; Log level, yes critical, error, warn, info, debug, trace, or blather etc. Default to info. . . Non mandatory pidfile=/tmp/supervisord.pid ; supervisord of pid File path. Default to $CWD/supervisord.pid. . . Not required nodaemon=false ; If it is true,supervisord The process will run in the foreground Default to false,That is, the background runs as a daemon... Not required minfds=1024 ; This is the least system free file descriptor, lower than this value supervisor Will not start. The file descriptor of the system is set here cat /proc/sys/fs/file-max 1024 by default... Not required minprocs=200 ; The smallest available process descriptor below this value supervisor It will not start normally. ulimit -u With this command, you can view linux Maximum number of processes for the following users The default is 200... Not required ;umask=022 ; Mask of the file created by the process The default is 022.. Non mandatory ;user=chrism ; This parameter can be set to a non root Users, when we root User startup supervisord After that. The user I set up here can also supervisord Manage The default is not set... Non mandatory ;identifier=supervisor ; This parameter is supervisord Identifier, mainly for XML_RPC Yes. When you have multiple supervisor And want to call XML_RPC Unified management is needed for each supervisor Set a different identifier The default is supervisord. . . Non required settings ;directory=/tmp ; This parameter is when supervisord When running as a daemon, set this parameter to start supervisord Before the process, it will switch to this directory first Not set by default... Not required ;nocleanup=true ; When this parameter is false When you are, you will be supervisord When the process starts, the previous child process Generated log file(Path is AUTO In case of)Clear it. Sometimes we want to read the history log when However, I don't want the log to be cleared. So it can be set to true The default is false,Students with debugging needs can be set as true. . . Not required ;childlogdir=/tmp ; When the child process log path is AUTO The storage path of the subprocess log file when. The default path is this thing. Just execute the following command OK The default path is used to process things python -c "import tempfile;print tempfile.gettempdir()" Not required ;environment=KEY="value" ; This is used to set environment variables, supervisord stay linux Default inheritance started in linux of Environment variable, which can be set here supervisord Other process specific environment variables. supervisord When a child process is started, the child process copies the memory space content of the parent process. So set These environment variables are also inherited by child processes. Small example: environment=name="haha",age="hehe" The default is not set... Not required ;strip_ansi=false ; If this option is set to true,All in the child process log are cleared ANSI Sequence. What is? ANSI What about the sequence? It's ours\n,\t These things. Default to false. . . Not required ; the below section must remain in the config file for RPC ; (supervisorctl/web interface) to work, additional interfaces may be ; added by defining them in separate rpcinterface: sections [rpcinterface:supervisor] ;This option is for XML_RPC Yes, of course. If you want to use it supervisord perhaps web server this Options must be enabled supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] ;This is mainly aimed at supervisorctl Some configurations of serverurl=unix:///tmp/supervisor.sock ; This is the local UNIX socket when supervisorctl connects to supervisord locally Path, note that this is the same as the previous one[unix_http_server]Corresponding The default is unix:///tmp/supervisor.sock. . Not required ;serverurl=http://127.0. 0.1:9001 ; This is the TCP socket path used by supervisorctl when connecting to supervisord remotely Pay attention to this and the front[inet_http_server]corresponding Default is http://127.0. 0.1:9001. . . Non mandatory ;username=chris ; user name The default is null.. Not required ;password=123 ; password The default is null.. Not required ;prompt=mysupervisor ; Prompt when entering user name and password default supervisor. . Not required ;history_file=~/.sc_history ; This parameter and shell Medium history Similarly, we can use the up and down keys to find the previously executed commands The default is no file of So if we want to have this function, we must specify a file... wrong Must be set ; The below sample program section shows all possible program subsection values, ; create one or more 'real' program: sections to be able to control them under ; supervisor. ;[program:theprogramname] ;This is the sub process we want to manage,":"The following is the name. It's best not to scribble and the actual process A little connection is best. In this way program We can set one or more, one program namely A process to be managed ;command=/bin/cat ; This is our command path to start the process, with parameters example:/home/test.py -a 'hehe' One thing to note is that our command It can only be the process running on the terminal, not Daemons. I know this when I think about it, for example command=service httpd start. httpd This process is linux of service Managed, our supervisor Start this command again This is no longer a child process in the strict sense. This is a required item ;process_name=%(program_name)s ; This is the process name if we numprocs If the parameter is 1, don't worry about this parameter Yes, it defaults%(program_name)s That's the one above program The name after the colon, But if numprocs You can't do this for more than one. Think about it. It's impossible for everyone All processes use the same process name. ;numprocs=1 ; Number of processes started. When it is not 1, it is the concept of process pool. Note: process_name Settings for The default is 1 . . Not required ;directory=/tmp ; Before the process runs, switch to this directory before the session Not set by default... Not required ;umask=022 ; Process mask, default none,Not necessary ;priority=999 ; Subprocesses are started and closed first. Those with low priority are started first and closed last The default value is 999.. Not required ;autostart=true ; If it is true If so, the subprocess will supervisord Automatically started after startup Default is true . . Not required ;autorestart=unexpected ; This is to set the automatic restart after the child process hangs. There are three options, false,unexpected and true. If yes false In any case, it will not be restarted, If yes unexpected,Only when the exit code of the process is not below exitcodes What's defined in it It will be automatically restarted when the code is out. should be true As long as the child process hangs, it will be ignored Conditional restart ;startsecs=1 ; This option is the number of seconds after the child process is started. If the status is running,Then we think Kai The move succeeded The default value is 1.. Not required ;startretries=3 ; The maximum number of attempts to start a process after it fails to start.. When more than three times, supervisor Will put The status of this process is set to FAIL The default value is 3.. Not required ;exitcodes=0,2 ; Pay attention to the above autorestart=unexpected corresponding.. exitcodes What's in it The exit code is expected of ;stopsignal=QUIT ; Process stop signal, which can be TERM, HUP, INT, QUIT, KILL, USR1, or USR2 Equal signal Default to TERM . . When the set signal is used to kill the process, the exit code will be considered as expected Not required ;stopwaitsecs=10 ; This is when we send to the child process stopsignal After receiving the signal, the system returns the information to supervisord,Maximum time to wait. Beyond this time, supervisord Will report to the The child process sends a force kill Signal. The default is 10 seconds.. Not required ;stopasgroup=false ; This thing is mainly used for, supervisord The sub process of management, and the sub process itself has Child process. So if we just kill supervisord If the subprocess of the subprocess, the subprocess of the subprocess It may become an orphan process. So we can set an option to put the whole sub process The whole process group was killed. Set to true If so, general killasgroup Will also be set to true. Note that this option sends stop signal Default to false. . Not required.. ;killasgroup=false ; This and the one above stopasgroup Similar, but sent kill signal ;user=chrism ; If supervisord yes root Start, let's set this non root User, can be used to Manage this program Not set by default... Non mandatory ;redirect_stderr=true ; If yes true,be stderr The log will be written stdout In log file Default to false,Not required ;stdout_logfile=/a/path ; Of child processes stdout You can specify the log path, AUTO,none Three options. Set to none If so, no log will be generated. Set to AUTO If so, we'll find a place at random Generate log files, and when supervisord When you restart, the previous log files will be deleted Empty. When redirect_stderr=true When I was young, sterr It will also be written into this log file ;stdout_logfile_maxbytes=1MB ; Maximum log file size, and[supervisord]As defined in. The default is 50 ;stdout_logfile_backups=10 ; and[supervisord]The definition is the same. Default 10 ;stdout_capture_maxbytes=1MB ; This thing is set capture The size of the pipeline. When the value is not 0, the child process can stdout Send messages, and supervisor According to the information, the corresponding message can be sent event. The default is 0. When it is 0, it means to close the pipeline... Non mandatory ;stdout_events_enabled=false ; When set to ture When the child process is controlled by stdout When writing a log to a file descriptor, the trigger supervisord send out PROCESS_LOG_STDOUT Type event Default to false. . . Not required ;stderr_logfile=/a/path ; This thing is set stderr Write log path, when redirect_stderr=true. Not this one It's useless to set it. Because it will be written stdout_logfile In the same file Default to AUTO,That is to deposit it anywhere, supervisord Restart is cleared.. Not required ;stderr_logfile_maxbytes=1MB ; This has appeared several times, so I won't repeat it ;stderr_logfile_backups=10 ; So is this ;stderr_capture_maxbytes=1MB ; The same as this, and stdout_capture Same. The default value is 0. It is off ;stderr_events_enabled=false ; This is the same. The default is false ;environment=A="1",B="2" ; This is the environment variable of the child process and is not shared with other child processes ;serverurl=AUTO ; ; The below sample eventlistener section shows all possible ; eventlistener subsection values, create one or more 'real' ; eventlistener: sections to be able to handle event notifications ; sent by supervisor. ;[eventlistener:theeventlistenername] ;This thing is actually different from program Their status is the same, too suopervisor Start the sub inlet Cheng, but what it does is subscribe supervisord Sent event. His name is listener Yes. We can listener It does a series of processing, such as alarm and so on This is what the landlord did these two days ;command=/bin/eventlistener ; This and the one above program Same, indicating listener The path to the executable file for ;process_name=%(program_name)s ; The same is true for this, the process name, when the following numprocs For more than one time, it is needed. Otherwise, the default is OK Yes ;numprocs=1 ; same listener Number of started ;events=EVENT ; event The type of event, that is, only the event type written in this place. Will be sent ;buffer_size=10 ; This is event The queue cache size and unit are not clear. The landlord guessed that it should be a. When buffer Over 10, the oldest event Will be cleared and the new event Put it in. The default value is 10.. Optional ;directory=/tmp ; Before the process is executed, it will switch to this directory for execution The default is no switching... Not necessary ;umask=022 ; Submergence, default to none,That's all ;priority=-1 ; Start priority, default-1,Not anymore ;autostart=true ; Whether to follow supervisord Start together, default true ;autorestart=unexpected ; Whether to restart automatically, and program One sample, divided true,false,unexpected Wait, attention unexpected and exitcodes Relationship between ;startsecs=1 ; The same is true. After running for a few seconds after the process is started, it is recognized as successful startup. The default is 1 ;startretries=3 ; The maximum number of failed attempts is 3 by default ;exitcodes=0,2 ; Expected or expected process exit code, ;stopsignal=QUIT ; The signal to kill the process. The default is TERM,For example, set to QUIT,So if QUIT To do the process Then it will be considered as normal maintenance, and the exit code will also be considered as normal maintenance expected Medium ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ;Set up ordinary users, which can be used to manage this listener Process. The default value is empty.. Not required ;redirect_stderr=true ; by true If so, stderr of log Will incorporate stdout of log inside Default to false. . . Not required ;stdout_logfile=/a/path ; I've stopped talking about this several times ;stdout_logfile_maxbytes=1MB ; So is this ;stdout_logfile_backups=10 ; So is this ;stdout_events_enabled=false ; This is actually wrong, listener Can't send event ;stderr_logfile=/a/path ; So is this ;stderr_logfile_maxbytes=1MB ; So is this ;stderr_logfile_backups ; Don't say that ;stderr_events_enabled=false ; This is also wrong, listener Cannot send event ;environment=A="1",B="2" ; This is the environment variable of the child process The default is empty... Not required ;serverurl=AUTO ; override serverurl computation (childutils) ; The below sample group section shows all possible group values, ; create one or more 'real' group: sections to create "heterogeneous" ; process groups. ;[group:thegroupname] ;This thing is for you programs Group, divided into groups program. We don't have to operate one by one We can perform unified operations on group names. be careful: program After being divided into groups, it is equivalent to the original Configuration from supervisor Disappeared from your configuration file... supervisor Only groups are managed, not Individual in the group program Managed ;programs=progname1,progname2 ; Group members, separated by commas This is a required setting item ;priority=999 ; Priority, relative to groups and between groups The default is 999.. Optional ; The [include] section can just contain the "files" setting. This ; setting can list multiple files (separated by whitespace or ; newlines). It can also contain wildcards. The filenames are ; interpreted as relative to this file. Included files *cannot* ; include files themselves. ;[include] ;This thing is very useful. When we have a lot of processes to manage, it is written in a file It's a little big. We can write the configuration information to multiple files, and then include come here ;files = relative/directory/*.ini
supervisor example
Example: managing elasticsearch based on supervisor
# cat /etc/supervisord.d/service.ini [program:elasticsearch] command=/application/elasticsearch/bin/elasticsearch ;Program start command user=elastic ; Which user is used to start the process? The default is root loglevel=info ;Log level redirect_stderr=true ; hold stderr Redirect to stdout,default false stdout_logfile_maxbytes=50MB ; stdout Log file size, default 50 MB stdout_logfile_backups = 10 ; stdout The number of log file backups. The default is 10 ;stdout The log file cannot be started normally when the specified directory does not exist, so you need to create the directory manually( supervisord (log files are created automatically) stdout_logfile=/var/log/supervisord/service.log stderr_logfile=/var/log/supervisord/service.log startsecs=10 ; If there is no abnormal exit after 10 seconds of startup, it means that the process is started normally. The default is 1 second startretries=60 ; The number of automatic retries after startup failure. The default is 3 redirect_stderr=true stopasgroup=false ;Default to false,Whether to send to this process group when the process is killed stop Signals, including child processes killasgroup=false ;Default to false,Send to process group kill Signals, including child processes # load configuration $ supervisorctl reread $ supervisorctl update # Start elasticsearch $ supervisorctl start elasticsearch # View startup status $ supervisorctl status elasticsearch
Common commands are as follows:
- Supervisor starts the supervisor initially, and starts and manages the processes set in the configuration
- supervisorctl stop programxxx stops a process (programxxx), programxxx is
- The value configured in [program: chatdaemon]. This example is chatdaemon
- supervisorctl start programxxx starts a process
- supervisorctl restart programxxx restart a process
- supervisorctl stop groupworker restarts all processes belonging to the group named groupworker (the same applies to start and restart)
- supervisorctl stop all stops all processes. Note: start, restart and stop will not load the latest configuration file
- supervisorctl reload loads the latest configuration file, stops the original process, starts and manages all processes according to the new configuration
- supervisorctl update starts the process with new configuration or changes according to the latest configuration file. The process without configuration changes will not be affected and restarted. Note: the process stopped with stop will be displayed. Using reload or update will not automatically restart the supervisorctl tail
- Programname / / view the log of programname
- supervisorctl tail redis / / view the log
supervisor monitoring management
For more convenient remote management of Supervisor, you can open its own web console.
# Modify the configuration file to remove comments and enable $ vim at /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)) # Restart the supervisor service $ systemctl restart supervisord
It can be accessed directly through the browser
Click“ Read the original text "Get a better reading experience!