Supervisor's never-to-die process

Keywords: supervisor Unix Python sudo

brief introduction

Supervisor is a C/S system. It can control the process on UNIX-like system. It is written by python. It provides a lot of functions to manage the process.

install

sudo pip install supervisor
  • 1

To configure

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

echo_supervisord_conf
  • 1

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

Startup service

Service procedure

First, write a small program to simulate a service program, as follows.
myserver.sh

#!/bin/sh

while true
do
    date 
    sleep 5
done
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

To configure

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

[supervisord]
nodaemon=true

[program:myserver]
command=/home/kongxx/test/myserver.sh
  • 1
  • 2
  • 3
  • 4
  • 5

Startup service

supervisord -c /etc/supervisord.conf
  • 1

Running the above program will start the supervisor service, which will generate a log file supervisord.log in the current directory.

At this point, we use "ps-ef | grep myserver" to find the service process above, and then kill the process. At this point, you will see that the supervisor in the log will start a new Myserver process.

management service

For the example above, we can only start a service, but can not manage these configurations of services. Let's see how to manage services.

Service procedure

Or use the myserver.sh program above.

To configure

/etc/supervisord.conf

[inet_http_server]         ; inet (TCP) server disabled by default
port = *: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 socket
username = admin              ; should be same as http_username if set
password = Letmein            ; should be same as http_password if set
prompt = mysupervisor         ; cmd line prompt (default "supervisor")

[program:myserver]
command = /home/kongxx/test/myserver.sh
redirect_stderr = true
stdout_logfile = /tmp/myserver.log
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

Startup service

supervisord -c /etc/supervisord.conf
  • 1

Query/Start/Stop Services

$ supervisorctl status myserver
myserver                         RUNNING   pid 14034, uptime 0:00:03 

$ supervisorctl start myserver
$ supervisorctl stop myserver
  • 1
  • 2
  • 3
  • 4
  • 5

supervisor manages the command line

supervisorctl can also enter supervisor's management command line interface without any parameters, as follows:

$ supervisorctl 
myserver                         RUNNING   pid 15297, uptime 0:00:27
mysupervisor> ?

default commands (type help <topic>):
=====================================
add    exit      open  reload  restart   start   tail   
avail  fg        pid   remove  shutdown  status  update 
clear  maintail  quit  reread  signal    stop    version

mysupervisor> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Remote management

supervisorctl -s http://<ip>:9999 -u admin -p Letmein status myserver
  • 1

Web interface

Browsers can be used to access http://:9999 to manage services through web interfaces.

Posted by backinblack on Tue, 26 Mar 2019 19:42:28 -0700