Process monitoring supervisor

Keywords: supervisor Redis Web Server Unix

Supervisor, a process control system, is a C/S mode system that allows users to monitor and control the number of processes in the UNIX-LIKE operating system.Supervisor is the main process and some subprocesses are managed under Supervisor. When a subprocess exits abnormally, Supervisor handles it immediately, usually by daemon, restarting the process.

Main Components
supervisord
Is a server-side program, the main function is to start the supervisord service, start the supervisor management sub-process, to manage the process of the service.
supervisorctl
Is a client program whose main function is to manage (start/close/restart/state, etc.) subprocesses and provide a shell environment for processing.
web server
Web Server mainly manages processes on the interface. Web Server is actually implemented through XML_RPC, which can request data from supervisor, or control supervisor and subprocesses.Configure in [inet_http_server] block
XML_RPC
Remotely invoked, the supervisorctl and Web Server above implement it

Installation and use (ubuntu)

1. Installation

apt-get install supervisor
 Default profile/etc/supervisor/supervisord.conf

2. Directory structure

/etc/supervisor
├── conf.d
│   └── redis_monitor.conf
└── supervisord.conf

3. Start

supervisord -c /etc/supervisor/supervisord.conf

4. Check whether to start

ps aux | grep supervisord 

5. View profile details

echo_supervisord_conf > /etc/supervisor/supervisord.conf

6. Configure monitoring redis-server

Create a new file redis_monitor.conf under conf.d (configure basic information only)
[program:redis]                                                                                                     
command = redis-server
autostart=true
autorestart=true
startsecs=1

7. Use supervisorctl to manage monitoring processes

supervisorctl update /etc/supervisor/conf.d/redis_monitor.conf 
redis: added process group

8. Manual kill redis-server

kill -9 redis-pid

/tmp/supervisor.logThe output is as follows:
2017-09-04 06:10:16,712 INFO exited: redis (terminated by SIGKILL; not expected)
2017-09-04 06:10:17,718 INFO spawned: 'redis' with pid 7005
2017-09-04 06:10:18,779 INFO success: redis entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

//View redis-server status (restarted)
ps aux | grep redis-server
root      7005  0.0  0.7  29924  7444 ?        Sl   06:10   0:00 redis-server *:6379
root      7010  0.0  0.0   4684   848 pts/7    S+   06:11   0:00 grep --color=auto redis-server

9.supervisorctl use

supervisorctl | status
redis   RUNNING    pid 7214, uptime 0:00:58

10.help command

add clear fg open quit remove restart start stop  update 
avail exit maintail pid reload reread shutdown status  tail version

When a managed process updates, an update conf file is required

11. Open a web page

[inet_http_server]         ; inet (TCP) server disabled by default
port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=123               ; (default is no password (open server))

This allows you to manage monitored programs through web pages.

Posted by foobar on Mon, 27 May 2019 10:07:04 -0700