1. 概念
一般在linux中运行某个进程的时候,通过start、stop、restart以及reload进行运行,将其配置的服务放置在/etc/init.d/的目录下
supervisor主要的作用是管理进程,主要通过fork/exec进程对其启动(将其作为子进程),之后supervisor作为父进程对其启动,即使断电宕机也可将其重启,主要在配置文件中书写autostart=true即可。而传统方式的当即重启脚本需要写一个脚本来监控
对比传统方式的书写,supervisor的特性作用比较大
supervisor主要有两个命令参数:
supervisord : 服务端,启动supervisor即启动supervisord服务。
manong@manong-offline27-30001:~/manong/yanjiuseng$ supervisord --help
supervisord -- run a set of applications as daemons.
Usage: /usr/local/bin/supervisord [options]
supervisorctl:客户端,启动supervisor的监控窗口,内有监控的子进程
manong@manong-offline27-30001:~/manong/yanjiuseng$ supervisorctl --help
supervisorctl -- control applications run by supervisord from the cmd line.
Usage: /usr/local/bin/supervisorctl [options] [action [arguments]]
2. 命令讲解
supervisorctl 主要是supervisor的一个客户端管理工具,主要用来管理进程
下载这个命令完成之后,其命令的配置文件路径在:cat /etc/supervisor/supervisord.conf
查询所有的子进程状态:supervisorctl status,执行supervisorctl是进到这个命令的内部
具体的参数讲解:
子进程名
运行状态(RUNNING、FATAL、STOPPED、STARTING)
进程号或者子进程的运行时间
- 查看单个子进程的状态: supervisorctl status 子进程
- 关闭单个子进程 :supervisorctl stop 子进程
- 关闭所有子进程:supervisorctl stop all
- 启动单个子进程:supervisorctl start 子进程
- 启动所有子进程:supervisorctl start all
- 重启单个子进程:supervisorctl restart 子进程
3. 配置文件
将其脚本配置在文件中
其配置文件的详解具体如下:(我的目录在conf文件下)
[program:xx_ccd]
# 进入到这个目录下
directory=/home/xx
# 执行虚拟环境的命令
command=/home/xx/.virtualenvs/manong/bin/uwsgi --ini uwsgi.ini
# 用户名是这个
user=test_user
numprocs=1
# 日志文件
stdout_logfile=/home/xx/logs/uwsgi.log
redirect_stderr=true
autostart=false
autorestart=true
startsecs=5
stopwaitsecs=10
killasgroup=true
priority=999
stopsignal=QUIT