Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A simple description of the process management supervisor

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Background:

Some scripts encountered in the project need to be run through background processes to ensure that they will not be interrupted abnormally. Previously, they were all implemented through nohup, &, and screen, and found the Supervisor with the idea of starting a start/stop/restart/reload service. The introduction to supervisor is summarized in a general online search as follows:

Supervisor is a set of general process management program developed with Python, which can change an ordinary command line process into background daemon, monitor the status of the process, and restart automatically when an exception exits. It starts these managed processes as children of supervisor by fork/exec, so as long as the path of the executable of the process to be managed is written in the supervisor configuration file. It is also realized that when the child process dies, the parent process can accurately get the information that the child process is dead, and can choose whether to start and alarm itself. Supervisor also provides a function to set a non-root user for supervisord or each child process, and this user can manage its corresponding process.

Description:

1, install

1:easy_install installation: easy_install supervisor2:pip installation: pip install supervisor3:Debian / Ubuntu can be installed directly through apt: apt-get install supervisor

2, profile

1) after installing through apt-get install, the configuration file of supervisor is as follows:

/ etc/supervisor/supervisord.conf

The configuration file for supervisor is incomplete by default, but by most defaults, the basic functions mentioned above have been met. The child process configuration files it manages are as follows:

/ etc/supervisor/conf.d/*.conf

Then, start writing a child process configuration file for the script you need, let supervisor manage it, put it in the / etc/supervisor/conf.d/ directory, with .conf as the extension (the configuration file for each process can be split separately or the related scripts can be put together). For example, any option group (/ etc/supervisor/conf.d/test.conf) that defines a project name associated with the script:

# Project name [program:blog] # script directory whether to start the directory=/opt/bin# script command command=/usr/bin/python / opt/bin/test.py#supervisor at the same time, default Trueautostart=true# when the program exit, the program will not restart automatically. By default, unexpected# sets the situation where the child process restarts automatically after it hangs. There are three options, false,unexpected and true. If it is false, it will not be restarted under any circumstances. If it is unexpected, only after the exit code of the process is autorestart=false# defined in the exitcodes below is the number of seconds after the child process is started, if the status is running, then we think the startup is successful. The default value is 1startsecs=1# log output stderr_logfile=/tmp/blog_stderr.log stdout_logfile=/tmp/blog_stdout.log # the user identity of the script running user = zhoujy # redirects stderr to stdout, default falseredirect_stderr = true#stdout log file size Default 50MBstdout_logfile_maxbytes = number of 20M#stdout log file backups stdout_logfile_backups = 20 [program:zhoujy] # same as above directory=/opt/bin command=/usr/bin/python / opt/bin/zhoujy.py autostart=true autorestart=false stderr_logfile=/tmp/zhoujy_stderr.log stdout_logfile=/tmp/zhoujy_stdout.log # user = zhoujy

2) after installing through easy_install, the configuration file does not exist and needs to be imported by yourself.

①: run echo_supervisord_conf to print a sample of a configuration file. The sample description can be found in the basic section of supervisor (1). If the sample is set to a configuration file:

1: run echo_supervisord_conf to view the configuration sample: echo_supervisord_conf2: create configuration file: echo_supervisord_conf > / etc/supervisord.conf

②: configure the child process configuration file, which can be set directly in supervisor; [program:theprogramname].

Detailed child process configuration file:

Sample:

View Code

Description:

View Code

Change it to your actual configuration file: the same as above ①.

3: run

1) the supervisor installed by apt-get install can be run directly through / etc/init.d/supervisor:

/ etc/init.d/supervisor start

2) run supervisord through the supervisor installed by easy_install:

Supervisord

4:web interface operation

You need to add the [inet_http_server] option group to the supervisor configuration file: you can then access the management of the control child threads through http://10.211.55.11:9001.

[inet_http_server] port=10.211.55.11:9001username=userpassword=123

Effect:

5: child process management (supervisorctl)

1) View the status of all child processes:

# supervisorctl statusblog RUNNING pid 2395, uptime 0:08:41zhoujy RUNNING pid 2396, uptime 0:08:41

2) close and open the specified child process:

# supervisorctl stop zhoujyzhoujy: stopped# supervisorctl start zhoujyzhoujy: started

3) close and open all child processes:

# supervisorctl stop allblog: stoppedzhoujy: stopped# supervisorctl start allblog: startedzhoujy: started

4): other parameters: autostart=true after supervisor is enabled and autorestart=ture after child process exits

For more parameters, please see the official documentation and the description of the basic part of supervisor (1).

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report