I recently wrote a script under linux that needs to run in the background of linux all the time. Here I use supervisor to manage the script process.
One: supervisor installation
1: yum installation
yum install supervisor
2: pip install
pip install supervisor
Two: Supervisor common commands
supervisorctl status //查看所有进程的状态
supervisorctl stop xx //停止指定进程(all为所有进程)
supervisorctl start xx //启动指定进程(all为所有进程)
supervisorctl restart //重启
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl reload //重新启动配置中的所有程序
systemctl start supervisord.service //启动supervisor并加载默认配置文件
systemctl enable supervisord.service //将supervisor加入开机启动项
Three: Add the specified command to the process management instance
1: Supervisor configuration
Supervisor configuration file: /etc/supervisord.conf
Subprocess configuration file path: /etc/supervisord.d/ (the subprocess configuration file is in ini format)
To add a command to the process, we only need to create an ini process file in the subprocess configuration file directory for configuration.
example:vim /etc/supervisord.d/test.ini
Add the following command to the test.ini file:
[program:test] #项目进程名称
dircetory=/XXX #进程目录
command=XXX #进程命令
autostart = true #在supervisord启动的时候是否自动启动
autorestart=false #程序退出后是否自动重启
#日志输出
stderr_logfile=/tmp/client_stderr.log
stdout_logfile=/tmp/client_stdout.log
user=www #脚本运行的用户身份
2: Add the test process to the process management
systemctl start supervisord.service
supervisorctl update
supervisorctl reload
supervisorctl start test
According to the above arrangement, the specified script can be added to the process management
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。