Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。
#使用yum安装supervisor
yum install supervisor
#加入开机自启
systemctl enable supervisord.service
编辑/etc/supervisord.conf以下内容:
#注释掉原来的模块加载路径 ;[include] ;files = supervisord.d/*.ini #支持子模块 [include] files = supervisord.d/conf.d/*.conf #用于停止进程组,即停止所有通过“uwsgi.ini”配置启动的进程。 stopasgroup = true #用于关闭进程组,即关闭所有通过“uwsgi.ini”配置启动的进程。 killasgroup = true
#创建子模块目录,用于存放新建的守护进程的配置文件。
mkdir /etc/supervisord.d/conf.d
#添加守护进程配置文件
sudo vim /etc/supervisord.d/conf/php.woker.conf
内容如下,具体根据你实际业务来定,一下代码就是以root身份启动了4个守护进程,开启自动启动和自动重启:
[program:yii-queue-worker] process_name=%(program_name)s_%(process_num)02d command=php /www/wwwroot/host/yii queue/listen --verbose=1 --color=0 autostart=true autorestart=true user=root numprocs=4 redirect_stderr=true stdout_logfile=/www/wwwroot/host/yii-queue-worker.log
#首次使用或者修改配置以及子模块时,需要执行以此来生效配置
supervisord -c /etc/supervisord.conf
如果出现:Error: Another program is already listening on a port that one of our HTTP servers is configured to
解决方法:
find / -name supervisor.sock unlink /name/supervisor.sock
或者直接去/run/supervisor/目录找加锁的文件,把他删了
unlink /run/supervisor/supervisor.sock unlink /run/supervisor/supervisor.sock && supervisord -c /etc/supervisord.conf
supervisor常用操作
#查看所有program的状态 supervisorctl status all #启动所有program supervisorctl start all #停止所有program supervisorctl stop all #重启所有program supervisorctl restart all
无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。