1.安装
系统:Ubuntu
首先安装Supervisor服务:
- ubuntu安装:
sudo apt get install supervisor
- centos安装:
yum install -y supervisor
- 基于python库安装
pip2 install supervisor
easy_install supervisor
安装好之后,不出问题的话supervisor服务已经启动完成。
/etc/supervisor/conf.d/ 路径下添加配置文件
2.配置
下面是我supervisor管理进程的配置文件:
#新建一个应用并设置一个名称,这里设置为 hyperf
[program:hyperf]
#设置命令在指定的目录内执行
directory=/www/hyperf-admin/
#这里为您要管理的项目的启动命令
command=php ./bin/hyperf.php start
#以哪个用户来运行该进程
user=root
#supervisor 启动时自动该应用
autostart=true
#进程退出后自动重启进程
autorestart=true
#进程持续运行多久才认为是启动成功
startsecs=5
#重试次数
startretries=3
#stderr 日志输出位置
stderr_logfile=/www/hyperf-admin/runtime/stderr.log
#stdout 日志输出位置
stdout_logfile=/www/hyperf-admin/runtime/stdout.log
#当stop掉守护进程后,是否杀掉其子进程
stopasgroup=true
重要参数说明:
stopasgroup
:表示当stop掉守护进程后,是否杀掉其子进程;true表示会杀掉子进程。
然后执行如下命令让其生效,并且启动被守护的服务:
supervisorctl update
进程配置文件配好之后,然后执行:
supervisorctl reload
启动 Supervisor
运行下面的命令基于配置文件启动 Supervisor 程序:
supervisord -c /etc/supervisor/supervisord.conf
如果出现:No such file or directory: file: /usr/lib/python2.7/socket.
输入如下命令可以解决
sudo supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl -c /etc/supervisor/supervisord.conf
3.命令使用
使用 supervisorctl 管理项目
#启动 hyperf 应用
supervisorctl start hyperf
#重启 hyperf 应用
supervisorctl restart hyperf
#停止 hyperf 应用
supervisorctl stop hyperf
#查看所有被管理项目运行状态
supervisorctl status
#重新加载配置文件
supervisorctl update
#重新启动所有程序
supervisorctl reload