A system that can control and manage processes.
Specifically, it daemonizes the process and restarts it in the event of a crash.
For example, my assigned project uses Laravel's queue worker, which is useful for continuous parallel running of programs.
Unfortunately for Windows users, it doesn't start on Windows because it's UNIX-like.
Official documentation http://supervisord.org/running.html#adding-a-program
I will write the minimum necessary contents about the basic usage of Supervisor.
This time, we will practice it on the EC2 instance launched appropriately on AWS.
Server access-superuser switching
...$ ssh -i ~/.ssh/udemy_sample2.pem [email protected]
[ec2-user@ip-172-31-37-208 ~]$ sudo su -
Install supervisor I haven't investigated it in detail, but it seems that ʻeasy_install` is good.
[root@ip-172-31-37-208 ~]# sudo easy_install supervisor
Searching for supervisor
Reading https://pypi.python.org/simple/supervisor/
Downloading https://files.pythonhosted.org/packages/ca/1f/07713b0e1e34c312450878801d496bce8b9eff5ea9e70d41ff4e299b2df5/supervisor-4.1.0-py2.py3-none-any.whl#sha256=a76b2f77a560f2dc411c0254a4eb15f555e99faac48621b0f1fc9ab013944f47
Best match: supervisor 4.1.0
Processing supervisor-4.1.0-py2.py3-none-any.whl
Installing supervisor-4.1.0-py2.py3-none-any.whl to /usr/lib/python2.7/site-packages
writing requirements to /usr/lib/python2.7/site-packages/supervisor-4.1.0-py2.7.egg/EGG-INFO/requires.txt
Adding supervisor 4.1.0 to easy-install.pth file
Installing echo_supervisord_conf script to /usr/bin
Installing pidproxy script to /usr/bin
Installing supervisorctl script to /usr/bin
Installing supervisord script to /usr/bin
Installed /usr/lib/python2.7/site-packages/supervisor-4.1.0-py2.7.egg
Processing dependencies for supervisor
Finished processing dependencies for supervisor
[root@ip-172-31-37-208 ~]# echo_supervisord_conf > /etc/supervisord.conf
The configuration file is placed under etc.
If you do not manage the configuration files individually, add the program you want to daemonize to supervisord.conf as follows.
supervisord.conf
[program:foo]
command=/bin/cat
If you want to manage the configuration files individually, follow the procedure below.
Creating a directory for storing individual program configuration files
[root@ip-172-31-37-208 ~]# mkdir /etc/supervisord.d
Modify supervisord.conf
Changes (before change)
supervisord.conf
;[include]
;files = relative/directory/*.ini
Changed part (after change)
supervisord.conf
[include]
files = /etc/supervisord.d/*.conf
Now, the individual configuration files created under /etc/supervisord.d will also be read.
Creating individual program configuration files
[root@ip-172-31-37-208 ~]# vi /etc/supervisord.d/foo.conf
Created as follows
foo.conf
[program:foo]
command=/bin/cat
supervisord
Used to start the supervisor.
It is not used for detailed program operations.
supervisorctl
Used in the operation of the executed program. See the URL below for detailed operation methods.
Start Supervisor.
[root@ip-172-31-37-208 ~]# /usr/bin/supervisord -c /etc/supervisord.conf
It will start with just / usr / bin / supervisord
, but in that case it seems better to use the c option and specify the absolute path of the configuration file because it goes to search the location of the configuration file in order. ..
Check the program in the configuration file.
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl status
foo RUNNING pid 29747, uptime 0:02:30
The program described in the configuration file seems to be executed automatically when Supervisor starts.
Try kill.
[root@ip-172-31-37-208 etc]# kill -9 29747
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl status
foo RUNNING pid 29761, uptime 0:00:03
Confirm that the process ID has changed and it has been restarted.
Try stopping the process.
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl stop foo
foo: stopped
[root@ip-172-31-37-208 ~]# /usr/bin/supervisorctl status
foo STOPPED Mar 29 01:17 AM
Make sure the process is stopped.
Try deleting the process.
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl remove foo
foo: removed process group
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl status
[root@ip-172-31-37-208 etc]#
Make sure the process is dead.
Add a new program and try running it in the foreground.
Add the following to supervisord.conf
supervisord.conf
[program:foo2]
command=watch -n 1 `date`
Read the configuration file and start the process
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl reread
foo: available
foo2: available
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl add foo2
foo2: added process group
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl status
foo2 RUNNING pid 1177, uptime 0:00:04
[root@ip-172-31-37-208 etc]# /usr/bin/supervisorctl fg foo2
Every 1.0s: `date` Sun Mar 29 04:24:25 2020
sh: Sun: command not found
Confirm execution in the foreground.
You can exit with Ctl + C. (Of course the process remains daemonized)
I have extracted the ones that I think I will use often.
status
Check the status of the process status.
reread
Read the configuration file.
No programs are added or removed at this stage.
add <name>
Apply the program described in the configuration file (process start).
remove <name>
Delete a stopped process.
restart <name>
Process restart.
Note that this alone will not read the contents of the configuration file.
stop
Stop the process.
start
Start the process.
update
Reload the configuration file and restart the program.
Is only the program whose settings have changed restarted?
reload
Restart the Supervisor daemon.
Convenient! !! !! !! !!
Recommended Posts