Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统
它能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启php
1、安装html
一、可使用python的pip安装 pip install supervisor 二、在mac下使用brew安装 brew install supervisor 1)安装事后在/usr/local/etc目录下存在supervisord.ini配置文件。为主配置文件,通常不用修改参数配置,具体参数值参考手册:http://www.supervisord.org/configuration.html 2)在主配置文件最后一行:files = /usr/local/etc/supervisor.d/*.ini 表明子配置文件目录,即咱们要监控的程序命令配置 3)启动直接使用brew services start supervisor(linux其余系统按照正常启动便可)
2、应用配置python
一、子程序配置说明 #项目名 [program:redis] #脚本目录 directory=/user/local/bin #脚本执行命令 command=php /usr/local/www/test.php #supervisor启动的时候是否随着同时启动,默认True autostart=true #当程序exit的时候,这个program不会自动重启,默认unexpected,设置子进程挂掉后自动重启的状况,有三个选项,false,unexpected和true。若是为false的时候,不管什么状况下,都不会被从新启动,若是为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的 autorestart=false #这个选项是子进程启动多少秒以后,此时状态若是是running,则咱们认为启动成功了。默认值为1 startsecs=1 #脚本运行的用户身份 user = test #日志输出 stderr_logfile= stdout_logfile= #把stderr重定向到stdout,默认 false redirect_stderr = true #stdout日志文件大小,默认 50MB stdout_logfile_maxbytes = 20M #stdout日志文件备份数 stdout_logfile_backups = 20
3、客户端命令linux
#查看进程的状态 supervisorctl status #中止进程 supervisorctl stop all || 进程名称 #启动进程 supervisorctl start all || 进程名称 #重启进程 supervisorctl restart all || 进程名称 #从新加载配置文件启动 supervisorctl update #重启全部程序 supervisorctl reload supervisorctl为客户端命令 注意:直接使用supervisorctl可能会报错(http://localhost:9001 refused connection),注意加上-c /usr/local/etc/supervisord.ini配置路径。