supervisord 负责管理进程的server端
supervisorctl client端的命令行工具,管理子进程
#安装supervisor
$ yum install -y supervisor
#开机启动
$ systemctl enable supervisord
#启动supervisord
$ systemctl start supervisord
#查看状态
$ systemctl status supervisord
#修改配置文件
$ vim /etc/supervisord.conf
#开启web界面访问
把[inet_http_server]模块的注释去掉,并修改IP、用户名与密码
[inet_http_server] ; inet (TCP) server disabled by default
port=10.64.56.159:9001 ; (ip_address:port specifier, *:port for all iface)
username=*** ; (default is no username (open server))
password=*** ; (default is no password (open server))
#重新加载配置文件
$ supervisorctl reload
#访问
http://192.168.1.108:9001
#注意:
Supervisor只能管理非daemon的进程,也就是说Supervisor不能管理守护进程。否则提示Exited too quickly (process log may have details)异常
php laravel 配置 Supervisor示例
#修改 /etc/supervisord.conf 文件内容
; files = supervisord.d/*.ini
files = /etc/supervisor/conf.d/*.conf
复制代码#在 /etc/supervisord.d/下创建文件test.conf,内容如下:
[program:sync_goods_to_es]
process_name=%(program_name)s_%(process_num)02d
command=php artisan command.sync.goods.to.es ;被监控的进程路径
priority=999 ;优先级,数值越低越先启动而越后关闭 (default 999)
autostart=true ;随着supervisord的启动而启动
autorestart=true ;自动重启
user=root ;用哪个用户启动进程,默认是root
numprocs=1 ;启动几个进程
redirect_stderr=true ;重定向stderr到stdout
stdout_logfile=/data0/log-data/service.log; # stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
#执行命令使配置文件生效
$ supervisorctl reload
$ supervisorctl update
#如果修改了 /etc/supervisord.conf,重启 supervisord
$ systemctl restart supervisord
#运行
$ supervisorctl start sync_goods_to_es:*
#查看运行状态
$ supervisorctl status #提示RUNNING代表成功
#查看进程
$ ps -ef | grep sync_goods_to_es
#常用命令
$ systemctl start supervisord #启动
$ systemctl stop supervisord #停止
$ systemctl status supervisord #状态
$ supervisorctl reread
$ supervisorctl update
$ supervisorctl reload
$ supervisorctl status
$ supervisorctl shutdown #关闭所有任务
$ supervisorctl stop|start program_name #启动或停止服务
$ supervisorctl status #查看所有任务状态