Linux Background Process management tool supervisor

Source: Internet
Author: User
Tags cas

There are several ways to run the background process of Linux, such as Nohup,screen, but, if it is a service program, to reliably run in the background, we need to make it daemon, the mostIt can also monitor the status of the process and automatically restart at the end of an accident .。 Supervisor is a set of common process management programs developed with Python that can turn a normal command-line process into a background daemon and monitor the status of the process, which can be restarted automatically when the exception exits. Ubuntu Installation: Apt-get install supervisor in the/etc/supervisor directory has supervisord.conf file, the content is as follows:
; Supervisor Configfile[Unix_http_server]file=/var/run/supervisor.sock; (The path to the socketfile)chmod=0700; SockeffileMode (default0700) [Supervisord]logfile=/var/Log/supervisor/supervisord.Log; (MainLog file;default $CWD/supervisord.Log) Pidfile=/var/run/supervisord.pid; (Supervisord pidfile;defaultSupervisord.pid) Childlogdir=/var/Log/supervisor; (' AUTO ' childLog dir,default $TEMP); The below section must remain in the Configfile  forRPC; (Supervisorctl/webInterface) to work,additional interfaces May is; added by defining them in separate Rpcinterface:Sections[rpcinterface:Supervisor]supervisor. rpcinterface_factory = Supervisor.rpcinterface:Make_main_rpcinterface[supervisorctl]serverurl=unix:///var/run/supervisor.sock; Use a unix://URL for a UNIX socket; The [include] section can just contain the "files" setting.This ; setting canListmultiple files (separated by whitespace or; newlines). It can also contain wildcards.The filenames is; interpreted asRelative to thisfile. Included Files *cannot*; includeFiles themselves.[include]files=/ETC/SUPERVISOR/CONF.D/*. conf
Then, write a configuration file for our own development application and let supervisor manage it. Each process configuration file can be split separately and placed in the/etc/supervisor/conf.d/directory, with. conf as the extension, if you modify/etc/supervisord.conf, you need to perform supervisorctl reload to reload the configuration file. Otherwise it will feel not effective, toss to the crazy ... ExampleFor example, app.conf defines a gunicorn process: [HTML] [Program:app] command=/usr/bin/gunicorn-w 1 wsgiapp:application directory=/srv/ www user=www-data among them, the process app is defined in [Program:app], command is the commands, directory is the current directory of the process, and user is the process running users identity. Restart supervisor, let the config file take effect, # Supervisorctl start app then run command supervisorctl START process: Stop process: # Supervisorctl Stop app if you want to use a variable on the command line, You need to write a shell script yourself: [HTML] #!/bin/sh/usr/bin/gunicorn-w ' grep-c ^processor/proc/cpuinfo ' wsgiapp:application then, plus x permissions , and then point the command to the shell script.

Get to know two commands first:

Supervisord:supervisor server-side section, starting supervisor is running this command

Supervisorctl: Launches the command-line window for supervisor.

Reference: http://www.2cto.com/os/201308/238166.html

An article: Using Supervisor to monitor the process:

Under Linux monitoring process, you can use Inittab, recently found supervisor, also very useful, record:
1, the system to install Python, and installed with the corresponding setuptools, in this
2. Installation:
# sh Setuptoolsxxxx.egg
3, install supervisor, in this, after decompression
# python setup.py Install
This will be OK, then execute the
# echo_supervisord_conf >/etc/supervisord.conf
Modify the/etc/supervisord.conf file to join the process you want to monitor, the comments inside are very detailed, for a simple example:
This is a description of the process to be monitored and added to the end of this file:
[Program:meta.txn.recover.on.error]
Command=/cas/bin/meta.txn.recover.on.error; The process path being monitored
Numprocs=1; Start several processes
Directory=/cas/bin; Do not need to CD to the directory before the implementation, generally do not
Autostart=true; Started with the start of Supervisord
Autorestart=true; Auto Restart: Of course we have to choose.
startretries=10; Maximum number of retries at startup failure
exitcodes=0; Normal exit code (does this mean that the exit code is no longer restarted?) Pending confirmation)
Stopsignal=kill; A signal to kill the process.
stopwaitsecs=10; Wait time before sending Sigkill
Redirect_stderr=true; REDIRECT stderr to stdout
To save space, the contents of the note are not posted.
Perform
# Supervisord-n
Can see the output of the monitoring process in the console:
2010-08-17 10:26:07,467 INFO Supervisord started with PID 943
2010-08-17 10:26:08,469 INFO spawned: ' Meta.txn.recover.on.error ' with PID 1009
2010-08-17 10:26:09,876 INFO Success:meta.txn.recover.on.error entered RUNNING state, process have stayed up for > than 1 seconds (Startsecs)
2010-08-17 10:26:48,442 INFO exited:meta.txn.recover.on.error (terminated by SIGKILL; not expected)
2010-08-17 10:26:49,444 INFO spawned: ' Meta.txn.recover.on.error ' with PID 2427
2010-08-17 10:26:50,487 INFO Success:meta.txn.recover.on.error entered RUNNING state, process have stayed up for > than 1 seconds (Startsecs)
The place of the blackbody is I use kill-9 kill the process to come out after, see Supervisor detects the process exits and then starts the process again.
Running Supervisord without parameters is run in daemon mode.
The ability to monitor the process can be completed by adding Supervisord to the boot entry.

"Note": When Supervisord is running in a non-daemon manner, the monitored process exits when the Supervisord is killed.
While running in daemon mode, killing Supervisord has no effect on the monitored process.

More:

Http://digdeeply.org/archives/07102224.html

Linux Background Process management tool supervisor

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.