守护进程 supervisor
守护进程 supervisor
安装配置 supervisor
安装 supervisor
# sudo su - #切换为root用户
# yum install epel-release
# yum install -y supervisor
# systemctl enable supervisord # 开机自启动
# systemctl start supervisord # 启动supervisord服务
# systemctl status supervisord # 查看supervisord服务状态
# ps -ef|grep supervisord # 查看是否存在supervisord进程
配置 Supervisor
1. 修改 /etc/supervisord.conf
文件内容
; files = supervisord.d/*.ini
files = /etc/supervisor/conf.d/*.conf
3. 在 /etc/supervisor/
下创建 conf.d 文件夹,及 ProjectName.conf (以项目名称命名的),添加内容如下:
[program:laravel]
process_name=%(program_name)s_%(process_num)02d
command=php /data/wwwroot/laravel/artisan queue:listen --tries=3
autostart=true
autorestart=true
user=www
numprocs=2
redirect_stderr=true
stdout_logfile=/data/wwwlogs/worker.log
4. 执行命令使配置文件生效
supervisorctl reread
supervisorctl update
5. 重启 supervisord 或者修改了 /etc/supervisord.conf
执行
supervisorctl reload
运行
supervisorctl start laravel:*
查看运行状态
supervisorctl status
//提示RUNNING代表成功
查看进程 (ps -ef | grep ProjectName)
ps -ef|grep laravel
常用命令
service supervisord start #启动
service supervisord stop #停止
service supervisord status #状态
supervisorctl reread
supervisorctl update
supervisorctl reload
supervisorctl status
supervisorctl shutdown #关闭所有任务
supervisorctl stop|start program_name #启动或停止服务
supervisorctl status #查看所有任务状态
TP队列任务进程守护
[program:hy_menglar_com_global_push_task] command=/usr/local/php/bin/php think queue:listen --queue=global_push_task directory=/data/wwwroot/hy.menglar.com/menglahy/ autorestart=true startsecs=3 startretries=3 stdout_logfile=/data/wwwlogs/supervisor/hy_menglar_com_global_push_task.out.log stderr_logfile=/data/wwwlogs/supervisor/hy_menglar_com_global_push_task.err.log stdout_logfile_maxbytes=2MB stderr_logfile_maxbytes=2MB user=www priority=999 numprocs=1 process_name=%(program_name)s_%(process_num)02d