preface
Supervisor is a client/server system that allows its users to control many processes on unix-like operating systems. (Official explanation)
In simple terms, it is a tool to monitor the execution of scripts, but it can be unified management, laravel queue documentation also has related methods of use, for example
- Start, restart, close, and monitor logs of scheduled scripts
- Swoole startup, restart, shutdown, and log monitoring (most of swoole’s features are known to run only in cli)
- Redis startup, restart, shutdown, and log monitoring (Redis itself does not provide a phpMyAdmin-like backend visualization tool)
- Queues in Laravel, some automated scripts, workman scripts, etc
It is common to use &test.sh to ensure that it runs in the background, but in many cases it is not possible to monitor scripts personally. You may need your Supervisor to help you. Think of it as a visual administrative background for your Unix system. Here’s how powerful it can be.
The installation
There are many ways to install Supervisor, and I recommend the simplest and easiest one to install
apt-get -y install python-setuptools
easy_install supervisor
Copy the code
As you can see, two commands complete the installation
configuration
When the Supervisor is installed, run echo_supervisord_conf. This will print a sample Supervisor configuration file to your terminal. As long as you can see the printed content of the configuration file.
The Supervisor does not automatically generate configuration files.
Run the echo_supervisord_conf > /etc/supervisord.conf command to generate the configuration file.
Partial configuration file information table
The name of the | annotation | chestnuts |
---|---|---|
inet_http_server[port] | Built-in management background | * : 8888 |
inet_http_server[username] | Manage background user names | admin |
inet_http_server[password] | Admin Background Password | admin |
include[files] | Set the process configuration file format | /etc/supervisor/supervisor.d/*.ini |
run
To start the Supervisor, load the configuration file
supervisord -c /etc/supervisor/supervisord.conf
Copy the code
The stop command is
supervisorctl shutdown
Copy the code
Reload the configuration file
supervisorctl reload
Copy the code
Supervisor starts each process configuration file with [program:[your_cli_name]. Your_cli_name is the name of your process. The name is displayed in the Supervisor daemon tool and the Supervisor CLI command output. Let’s take running phP-fpm as an example
[program:php7]
command=php-fpm
Copy the code
Oh, it’s so simple. Not too much nonsense. Or run a piece of shell.
[program:echo]
command=sh echo.sh
--------------------------------
echo.sh
your_name="my name zhangsan"
echo $your_name
Copy the code
Of course, the Laravel queue is still simple
[program:laravel-worker]
command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3
Copy the code
Of course, this is just a simple demo to get you started, configuration scripts are not just command commands. Concrete is the official document www.supervisord.org/configurati…
The background
Background management provided by the Supervisor is relatively simple
The general functions are restart, start, stop process, print logs, clear logs and so on. Basically so a few simple functions, of course, there is no downtime alarm, log alarm of what. However, the powerful Supervisor provides us with an interface 😄
interface
Access to all basic information through the API, such as process list, the status of a process, process logs. Including process restart, stop, start and other operations, the Supervisor is completely integrated into the internal monitoring background, there is no problem.
Details please click www.supervisord.org/api.html website Api documentation
The script
Finally, I gave my friends a simple script for learning the Supervisor
#! /bin/bash
set -x
case $1 in
'sp')
if [[ $2 == 'start' ]]; then
"supervisord -c /etc/supervisor/supervisord.conf"
elif [[ $2 == 'stop' ]]; then
"supervisorctl shutdown"
elif [[ $2 == 'restart' ]]; then
"supervisorctl shutdown"
"supervisord -c /etc/supervisor/supervisord.conf"
elif [[ $2 == 'reload' ]]; then
"supervisorctl reload"
fi
;;
esac
Copy the code
You can use this simple script to quickly start, restart, and shut down the Supervisor
Sh sp start // Start sh test.sh sp restart // RestartCopy the code
Thank you
Thank you for reading this. I hope this chapter helped you. thank you
communication
There is life, there is code.
Spread the positive energy of technology and continue to learn new knowledge.