Preface
Supervisor is a client/server system that allows its users to control many processes on UNIX-like operating systems. (Official Interpretation)
Simply put, it is a tool to monitor the running of scripts, but it can be managed in a unified way. laravel’s queue documents also have relevant usage methods, such as
- Start, restart, shutdown and log monitoring of timed scripts
- Swoole’s startup, restart, shutdown, and log monitoring (it is well known that most of its features can only be run in cli)
- Redis startup, restart, shutdown, and log monitoring (redis itself does not provide a background visualization tool similar to phpmyadmin)
- Queues in laravel, some automated scripts, scripts for workman, etc
Generally used&test.sh
Let it run in the background, but in many cases, it is impossible to monitor scripts individually. At this time, you may need a Supervisor to help you. You can use it as the visual management background of your unix system. Now let’s witness its strength.
Installation
Supervisor can be installed in many ways, and I recommend the simplest and easiest one.
apt-get -y install python-setuptools
easy_install supervisor
As you can see, the two commands complete the installation.
Configuration
After Supervisor installation is completed, runecho_supervisord_conf
. This will print an example Supervisor configuration file to your terminal. As long as you can see the printed profile content.
Supervisor does not automatically generate configuration files.
Please use the commandecho_supervisord_conf > /etc/supervisord.conf
To generate a configuration file.
Partial Profile Information Table
Name | Notes | Chestnut |
---|---|---|
inet_http_server[port] | Built-in management background | *:8888 |
inet_http_server[username] | Management background user name | admin |
inet_http_server[password] | Manage background passwords | admin |
include[files] | Setting Process Profile Format | /etc/supervisor/supervisor.d/*.ini |
run
Supervisor startup requires configuration files to be loaded
supervisord -c /etc/supervisor/supervisord.conf
The stop command is
supervisorctl shutdown
Reload configuration file
supervisorctl reload
Supervisor to[program:[your_cli_name]]
At the beginning of each process configuration file, your_cli_name is your process name, which will be displayed on the Supervisor background management tool and Supervisor cli command output. Let’s take php-fpm as an example.
[program:php7]
command=php-fpm
Oh, it is simple. There is not too much nonsense. Or run a shell.
[program:echo]
command=sh echo.sh
--------------------------------
echo.sh
your_name="my name zhangsan"
echo $your_name
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
Of course, this is only a simple demonstration so that you can get started quickly. command is not the only command in the configuration script.
See official documents for details.http://www.supervisord.org/co …
Background
Supervisor provides simple background management
The general functions include restarting, starting, stopping processes, printing logs, clearing logs, etc. Basically, there are only a few simple functions, and of course there is no downtime alarm, log alarm, etc. However, the powerful Supervisor provides us with an interface.
Interface
Through API, all basic information can be obtained, such as process list, status of a process and process log. Including the restart, stop and start of the process, there is no problem in completely integrating the Supervisor into the internal monitoring background.
Please move to the official website Api document for detailshttp://www.supervisord.org/ap …
Script
Finally, I gave a simple script to my friends for learning 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
You can use this simple script to quickly start, restart, and close the Supervisor.
Sh test.sh sp start // start
Sh test.sh sp restart // restart
Thank you
Thank you for seeing here. I hope this chapter can help you. Thank you