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

Detailed explanation of Nginx rewrite jump application scenarios

Application scenario 1: Domain name-based redirec...

MySQL database optimization: index implementation principle and usage analysis

This article uses examples to illustrate the prin...

Detailed explanation of CSS text decoration text-decoration &amp; text-emphasis

In CSS, text is one of the most common things we ...

Kill a bunch of MySQL databases with just a shell script like this (recommended)

I was woken up by a phone call early in the morni...

Sample code for implementing PC resolution adaptation in Vue

Table of contents plan Install Dependencies Intro...

Flex layout allows subitems to maintain their own height

When using Flex layout, you will find that when a...

A simple example of creating a thin line table in html

Regarding how to create this thin-line table, a s...

Linux Basic Tutorial: Special Permissions SUID, SGID and SBIT

Preface For file or directory permissions in Linu...

Installation and use of Ubuntu 18.04 Server version (picture and text)

1 System Installation Steps OS Version:1804 Image...

10 HTML table-related tags

In fact many people will say “I’ve seen that table...

Solve the problems encountered when installing MySQL 8.0 on Win10 system

The problems and solutions encountered when insta...