Use Supervisor to manage Linux Processes

Source: Internet
Author: User

Use Supervisor to manage Linux Processes
Introduction to using Supervisor to manage Linux Processes

Supervisor is a C/S system that can control system processes on UNIX-like systems. It is written in python and provides a large number of functions to manage processes.

Install
sudo pip install supervisor
Configuration

After installing the supervisor, you can run the "echo_supervisord_conf" command to generate the sample configuration file.

echo_supervisord_conf

By default, the supervisor uses/etc/supervisord. conf as the default configuration file.

Start the Service Program

First, write a small program to simulate a service program.
Myserver. sh

#!/bin/shwhile truedo    date     sleep 5done
Configuration

Modify the configuration file/etc/supervisord. conf as follows:

[supervisord]nodaemon=true[program:myserver]command=/home/kongxx/test/myserver.sh
Start the service
supervisord -c /etc/supervisord.conf

Run the preceding program to start the supervisor service. A log file supervisord. log is generated in the current directory.

In this case, we use "ps-ef | grep myserver" to locate the above service process and kill it. In this case, the supervisor in the log starts a new myserver process.

Management Service

In the above example, we can only start one service, but cannot manage the services with these configurations. Let's take a look at how to manage the service.

Service programs

Or use the above myserver. sh program.

Configuration

/Etc/supervisord. conf

[inet_http_server]         ; inet (TCP) server disabled by defaultport = *:9999              ; (ip_address:port specifier, *:port for all iface)username = admin           ; (default is no username (open server))password = Letmein         ; (default is no password (open server))[supervisord]nodaemon = false[rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]serverurl = http://127.0.0.1:9999 ; use an http:// url to specify an inet socketusername = admin              ; should be same as http_username if setpassword = Letmein            ; should be same as http_password if setprompt = mysupervisor         ; cmd line prompt (default "supervisor")[program:myserver]command = /home/kongxx/test/myserver.shredirect_stderr = truestdout_logfile = /tmp/myserver.log
Start the service
supervisord -c /etc/supervisord.conf
Query/start/stop services
$ supervisorctl status myservermyserver                         RUNNING   pid 14034, uptime 0:00:03 $ supervisorctl start myserver$ supervisorctl stop myserver
Supervisor management command line

Supervisorctl can also be used without any parameters. At this time, you can enter the management command line interface of the supervisor, as shown below:

$ supervisorctl myserver                         RUNNING   pid 15297, uptime 0:00:27mysupervisor> ?default commands (type help 
  
   ):=====================================add    exit      open  reload  restart   start   tail   avail  fg        pid   remove  shutdown  status  update clear  maintail  quit  reread  signal    stop    versionmysupervisor> 
  
Remote Management
supervisorctl -s http://
  
   :9999 -u admin -p Letmein status myserver
  
Web Interface

You can use a browser to access http: //: 9999 to manage services through web interfaces.

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.