Background Process Management tool---Supervisor

Source: Internet
Author: User
Tags terminates

Supervisor is a Linux process management tool, sometimes need to develop some background service class programs, such programs are usually not due to accidentally hang up, so it is best to be able to restart in the event of unexpected hangs, continue to service. I used to create the daemon, that is, the daemon process to implement, and then through the other process monitoring, recently discovered this background process management artifact. With supervisor, you can easily change the console program of the command line to daemon, and supervisor can automatically restart it when it hangs unexpectedly.

System Environment ubuntu14.04, other distributions Linux installation configuration is basically the same


Here is a small example of the simple use of supervisor


Suppose we are in the/root/test directory, to execute a test.py file, and want it to be a daemon in the background, and be able to be restarted as soon as possible, and continue to serve as much as you can.


Install Supervisor First

sudo apt-get install Supervisor

can also be installed via PIP

Pip Install Supervisor

Also available through Easy_install

Easy_install Supervisor


Configuration

Enter the/ETC/SUPERVISOR/CONF.D directory

Add a test.conf configuration file to configure our process

[Program:test]command=python Test.pydirectory=/root/testautorestart=trueuser=root
Where [program:test] Specifies the name of the configuration, which is followed by the configuration process name in Supervisorctl start [config process name]

command specifies the commands executed, here is a python file, which we execute via Python test.py

Directory has the path where the test.py file is located

AutoRestart can be restarted when the specified process terminates unexpectedly

User specified to run the program


You can also directly write the above configuration directly to the/etc/supervisor/supervisord.conf file, the effect is consistent with the above.


Overloaded configuration Files

After adding the configuration file, we need to have supervisor re-read the configuration file so that our configuration can take effect

SUPERVISORCTL Update

Delete the configuration file, also perform supervisorctl update



Start process

Supervisorctl Start test

Where test is the [Program:test] written in the configuration, the effect of the command is consistent with the Python test.py, except that it runs as a daemon and is supervisor restarted when the process terminates unexpectedly


Because in the configuration file, specifying that the process terminates unexpectedly is restarted, we cannot end the process by killing the process, but by supervisor

Terminating a process

Supervisorctl Stop Test


Restart process

Supervisorctl Restart Test




More information about supervisor can be found in the official documentation http://supervisord.org/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Background Process Management tool---Supervisor

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.