Installation, configuration and use of process daemon supervisor in Linux

Installation, configuration and use of process daemon supervisor in Linux

Supervisor is a very good daemon management tool. It has a series of powerful features such as automatic startup, log output, automatic log cutting, etc. The following is a record of installing and using Supervisor under CentOS.

Install

# epel source yum install epel-release
# Install supervisor
yum install -y supervisor
# Start automatically at boot time systemctl enable supervisord
# Start the supervisord service systemctl start supervisord 
Bash

Configuration Path

# Main configuration file /etc/supervisord.conf
# Run the program configuration folder /etc/supervisord.d/
Bash

Operation Command

systemctl stop supervisord
systemctl start supervisord
systemctl status supervisord
# Reload the configuration file without affecting the running program systemctl reload supervisord
systemctl restart supervisord
Bash

Use Test

Write a test script test.php to record the number of startups and runs.

<?php
try {
  $a = file_get_contents('./times.json');
} catch (Exception $e) {
  $a = 0;
}
$a++;
file_put_contents('./times.json', $a);
echo date('Ymd H:i:s') . " This is the {$a}th start!!!!" . PHP_EOL;

$i = 1;
while (1) {
  echo date('Ymd H:i:s') . "{$i}th output" . PHP_EOL;
  $i++;
  sleep(5);
}

PHP

Add test.ini in the program configuration folder /etc/supervisord.d :

[program:test]
directory=/home/wwwroot/test.cc
command=php test.php
autostart=true
autorestart=true
stderr_logfile=/home/wwwroot/test.cc/log/error.log
stdout_logfile=/home/wwwroot/test.cc/log/out.log
Ini

The above are just some necessary basic configurations. For more detailed configuration reference:

;[program:theprogramname]
;command=/bin/cat ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1 ; number of processes copies to start (def 1)
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=999 ; the relative start priority (default 999)
;autostart=true ; start at supervisord start (default: true)
;autorestart=true ; retstart at unexpected quit (default: true)
;startsecs=10 ; number of secs prog must stay running (def. 1)
;startretries=3 ; max # of serial start failures (default 3)
;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait for b4 SIGKILL (default 10)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A=1,B=2 ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils)
Ini

Run the restart or reload configuration command to load the new configuration:

systemctl restart supervisord
systemctl reload supervisord
Bash

View the process:

[root@localhost test.cc]# ps -aux | grep test.php
root 22277 0.0 0.6 269732 12124 ? S 17:38 0:00 php test.php
root 22335 0.0 0.0 112712 996 pts/0 S+ 17:41 0:00 grep --color=auto test.php
Bash

You can restart the server, or kill -9 PID to kill the process. You will find that supervisor will restart the program as soon as possible, thus achieving the purpose of daemonizing the process.

Regarding the configuration, take a closer look at the reference above, which basically covers the required functions, multi-process operation, log cutting size, retention quantity, etc. It is powerful and easy to use.

For more advanced features, please refer to supervisor official website manual: Portal

Summarize

The above is the installation, configuration and use of the process daemon supervisor in Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Linux process management tool supervisor installation and configuration tutorial
  • Installation and use of Linux operation and maintenance tool Supervisor (process management tool)
  • Detailed explanation of Supervisor installation and configuration (Linux/Unix process management tool)
  • PHP programmers play Linux series using supervisor to implement daemon process
  • Learn how to use the supervisor watchdog in 3 minutes

<<:  Angular performance optimization: third-party components and lazy loading technology

>>:  Mysql query the most recent record of the sql statement (optimization)

Recommend

Analysis of the project process in idea packaging and uploading to cloud service

one. First of all, you have to package it in idea...

Detailed tutorial on installing Docker on CentOS 8.4

Table of contents Preface: System Requirements: I...

Notes on the MySQL database backup process

Today I looked at some things related to data bac...

MySQL horizontal and vertical table conversion operation implementation method

This article uses examples to illustrate how to i...

The magic of tbody tag speeds up the display of table content

You must have saved other people’s web pages and l...

Why node.js is not suitable for large projects

Table of contents Preface 1. Application componen...

Mysql: The user specified as a definer ('xxx@'%') does not exist solution

During the project optimization today, MySQL had ...

MySQL log trigger implementation code

SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...

Use Python to connect to MySQL database using the pymysql module

Install pymysql pip install pymysql 2|0Using pymy...

How to use vue-video-player to achieve live broadcast

Table of contents 1. Install vue-video-player 2. ...

CSS3 category menu effect

The CSS3 category menu effects are as follows: HT...