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

Supervisor managed Services

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Supervisor (http://supervisord.org) is a process management tool written in Python that can be easily used to start, restart, and shut down processes (not just Python processes). In addition to the control of a single process, you can also start and shut down multiple processes at the same time, and of course, writing your own script can also be hosted by supervisor. In the enterprise, we are more managed services, or for more convenient standardization, automation and the use of managed services, the use of tomcat is particularly convenient. Of course, in some small and medium-sized companies, it is quite common for us to mix and distribute. Many projects are thrown under one server and one home directory, and some compiled source code is installed everywhere, which brings great maintenance costs to maintenance or newcomers. In fact, you can use supervisor to host.

First, the installation of supervisor is actually very simple. This section describes the installation method in 2:

1 、 yum install supervisor

2 、 sudo pip install supervisor

Supervisor is quite powerful and provides a wealth of features, but we may only need to use a few of them. After the installation is complete, you can write a configuration file to meet your needs. For convenience, we split the configuration into two parts: supervisord (supervisor is a program based on the C supervisor S model, which is the server side, corresponding to the client side: supervisorctl) and the application (that is, the program we want to manage).

First, take a look at the configuration file for supervisord. After installing supervisor, you can run the echo_supervisord_conf command to output the default configuration items, or you can redirect to a configuration file:

Echo_supervisord_conf > / etc/supervisord.conf

Of course, the installation of yum does not need to be so troublesome, the default is in the / etc directory.

Second: configuration of supervisor:

[unix_http_server]

File=/tmp/supervisor.sock; UNIX socket file, supervisorctl will use the

; chmod=0700; mode of socket file. Default is 0700.

; chown=nobody:nogroup; owner of the socket file, format: uid:gid

; [inet_http_server]; HTTP server, which provides web management interface

; port=127.0.0.1:9001; Web manages the IP and ports running at the backend. If it is open to the public network, you need to pay attention to security.

; username=user; login to the user name of the administrative backend

; password=123; password for logging in to the administrative backend

[supervisord]

Logfile=/tmp/supervisord.log; log file. Default is $CWD/supervisord.log.

Logfile_maxbytes=50MB; log file size, which exceeds rotate. Default is 50MB.

Logfile_backups=10; the number of reserved backups of log files defaults to 10

Loglevel=info; log level, default info, other: debug,warn,trace

Pidfile=/tmp/supervisord.pid; pid file

Nodaemon=false; whether to start in the foreground. The default is false, that is, it starts in the way of daemon.

Minfds=65535; the minimum value of the file descriptor that can be opened. Default is 1024.

Minprocs=65535; the minimum number of processes that can be opened. Default is 200.

User=root

Umask=022

; 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]

Supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

Serverurl=unix:///tmp/supervisor.sock; connect to supervisord through UNIX socket, and the path is the same as that of file in unix_http_server

; serverurl= http://127.0.0.1:9001; connect to supervisord through HTTP

; contains other configuration files

[include]

Files = relative/directory/*.ini / etc/supervisor/*.conf; can be * .conf or * .ini

III. Project startup configuration file:

Now write a configuration file to manage the process (note: when managing with supervisord, the daemon option for gunicorn needs to be set to False):

[program:usercenter]

Directory = / home/leon/projects/usercenter; the startup directory of the program

Command = gunicorn-c gunicorn.py wsgi:app; start the command, you can see that it is the same as the command started manually on the command line

Autostart = true; also starts automatically when supervisord starts

Startsecs = 5; if there is no abnormal exit 5 seconds after startup, it is deemed to have been started normally.

Autorestart = true; automatically restart after the program exits abnormally / / can be cancelled

Startretries = 3; failed startup automatically retries. Default is 3 / / can be cancelled.

User = leon; with which user to start

Redirect_stderr = true; redirect stderr to stdout, default false

Stdout_logfile_maxbytes = 20MB; stdout log file size. Default 50MB / / can be canceled

Stdout_logfile_backups = 20; the number of reserved backups for stdout log files defaults / / can be cancelled

; stdout log file, it should be noted that it cannot be started normally when the specified directory does not exist, so you need to create a directory manually (supervisord will automatically create log files)

Stdout_logfile = / data/logs/usercenter_stdout.log

You can add the environment variables you need through environment, and a common use is to modify PYTHONPATH

; environment=PYTHONPATH=$PYTHONPATH:/path/to/somewhere

4: simple configuration of progrem: (the following is an example)

[program:arch.gate.soa]

Command=sh start.sh

Process_name=arch.gate.soa

Numprocs=1

Stopsignal=INT

Directory=/data/arch.gate.soa

User=www-data

Redirect_stderr=true

Stdout_logfile=/data/log/supervisor/arch.gate.soa.out

Stdout_logfile_maxbytes=100MB

Stdout_logfile_backups=10

Stopasgroup=true

Killasgroup=true

Environment = ELEME_ENV= "prod"

A configuration file requires at least one configuration in the [program:x] section to tell supervisord which process to manage. The x in the [program:x] syntax represents program name, which is displayed on the client side (supervisorctl or web interface). This value is used to perform start, restart, stop and other operations on the program in supervisorctl.

5. Use supervisorctl:

Supervisorctl is a command line client tool for supervisord. You need to specify to use the same configuration file as supervisord at startup, otherwise look for configuration files in the same order as supervisord.

The above command will enter the shell interface of supervisorctl, and then you can execute different commands:

> status # View program status

> stop usercenter # close the usercenter program

> start usercenter # start the usercenter program

> restart usercenter # restart usercenter program

> reread # reads the configuration file with updates (additions) and will not start the newly added program

> update # restart the program modified by the configuration file

All of the above commands have corresponding output. In addition to entering the shell interface of supervisorctl, you can also run them directly on the bash terminal:

$supervisorctl status

$supervisorctl stop usercenter

$supervisorctl start usercenter

$supervisorctl restart usercenter

$supervisorctl reread

$supervisorctl update

In addition to supervisorctl, you can also configure supervisrod to launch the web management interface, which uses Basic Auth for authentication in the web background.

In addition to the control of a single process, group can also be configured for grouping management.

Often check the log files, including supervisord log and each pragram log file, program crash or throw exception information half will be output to stderr, you can check the corresponding log file to find the problem.

Supervisor has a wealth of features and many other configurations, and more information can be found in the official documentation: http://supervisord.org/index.html

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

Servers

Wechat

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

12
Report