安装
pip install supervisor
生成配置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf #目录自行创建
启动
supervisord -c /etc/supervisor/supervisord.conf
检查是否启动正常
ps aux | grep supervisord
使用方法
-
打开配置文件,到文件最底部
[include] files=/etc/supervisor/conf.d/*.ini #若你本地无/etc/supervisor/conf.d目录,请自建
-
在/etc/supervisor/conf.d/目录下新建trips-horizon.ini文件,内容如下:(这里要注意我一直使用的是root用户,使用其他非root用户注意权限问题)
# 队列/定时任务服务监测 cat /etc/supervisor/conf.d/trips-horizon.ini [program:trips-horizon] process_name=%(program_name)s command=php /data/wwwroot/tour/artisan horizon autostart=true autorestart=true redirect_stderr=true stdout_logfile=/data/wwwlogs/trips/worker-horizon.log # 聊天服务 cat /etc/supervisor/conf.d/trips-chat.ini [program:trips-chat] process_name=%(program_name)s command=php /data/wwwroot/tour/artisan message:server autostart=true autorestart=true redirect_stderr=true stdout_logfile=/data/wwwlogs/trips/worker-chat.log
-
配置完成之后重新载入一下配置文件
supervisorctl update
-
查看正在运行的脚本
supervisorctl [root@fankers ~]# supervisorctl trips-chat RUNNING pid 3312, uptime 16:04:30 trips-horizon RUNNING pid 16234, uptime 4 days, 3:19:55
-
重启单个脚本
supervisorctl restart trips-chat