安装
sudo apt-get install supervisor
如果想开放web界面端口
vim /etc/supervisor/supervisord.conf
将这两句加进去
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0:9001 ; (ip_address:port specifier, *:port for all iface)
supervisord.conf
最后的[include]
部分配置作用是,将conf.d/下所有.conf结尾的项目作为子进程启动,所以要添加子进程项目,在该目录下添加.conf结尾的项目即可
[include]
files = /etc/supervisor/conf.d/*.conf
启动
supervisord -c /etc/supervisor/supervisord.conf
启动后进入 127.0.0.1:9001 可以打开web管理界面
新增子进程配置
在/etc/supervisor/conf.d/
新增子进程配置文件 echo_time.conf
:
[program:echo_time]
command=sh /tmp/echo_time.sh
priority=999 ; the relative start priority (default 999)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10)
user=root ; setuid to this UNIX account to run the program
log_stdout=true
log_stderr=true ; if true, log program stderr (def false)
logfile=/tmp/echo_time.log
logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
logfile_backups=10 ; # of logfile backups (default 10)
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups=20 ; stdout 日志文件备份数
stdout_logfile=/tmp/echo_time.stdout.log
其他命令使用
# 查看状态
supervisorctl
# 讲所有新加的项目加入群组
supervisorctl update
# 制定更新某个
supervisorctl update program_name
#重载
supervisorctl reload
# 启动某个项目
supervisorctl start program_name
# 关闭某个项目
supervisorctl stop program_name
# 重启
supervisorctl restart program_name
# 启动/关闭/重启全部
supervisorctl start/stop/restart all