1. yum install supervisor
2. vim /etc/supervisord.conf
chose unix_http_server or inet_http_server
[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; sockef file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
可以使用浏览器查看和控制进程状态 http://172.16.5.20:9001 登录
[inet_http_server] ; inet (TCP) server disabled by default
port=172.16.5.20:9001 ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))
3. vim /etc/supervisord.d/docker_fluentd.ini
[program:fluentd2kafka]
command=fluentd -c /data/fluentd/docker_cp/in_docker.conf
diredctory=/data/fluentd/docker_cp
user=root
autorestart=true
startretries=3
stdout_logfile=/home/lzz/temp/super/%(program_name)s.log
stderr_logfile=/home/lzz/temp/super/%(program_name)s.log
模板
;*为必须填写项
;*[program:应用名称]
[program:cat]
;*命令路径,如果使用python启动的程序应该为 python /home/test.py,
;不建议放入/home/user/, 对于非user用户一般情况下是不能访问
command=/bin/cat
;当numprocs为1时,process_name=%(program_name)s
;当numprocs>=2时,%(program_name)s_%(process_num)02d
process_name=%(program_name)s
;进程数量
numprocs=1
;执行目录,若有/home/supervisor_test/test1.py
;将directory设置成/home/supervisor_test
;则command只需设置成python test1.py
;否则command必须设置成绝对执行目录
directory=/tmp
;掩码:--- -w- -w-, 转换后rwx r-x w-x
umask=022
;优先级,值越高,最后启动,最先被关闭,默认值999
priority=999
;如果是true,当supervisor启动时,程序将会自动启动
autostart=true
;*自动重启
autorestart=true
;启动延时执行,默认1秒
startsecs=10
;启动尝试次数,默认3次
startretries=3
;当退出码是0,2时,执行重启,默认值0,2
exitcodes=0,2
;停止信号,默认TERM
;中断:INT(类似于Ctrl+C)(kill -INT pid),退出后会将写文件或日志(推荐)
;终止:TERM(kill -TERM pid)
;挂起:HUP(kill -HUP pid),注意与Ctrl+Z/kill -stop pid不同
;从容停止:QUIT(kill -QUIT pid)
;KILL, USR1, USR2其他见命令(kill -l),说明1
stopsignal=TERM
stopwaitsecs=10
;*以root用户执行
user=root
;重定向
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
;环境变量设置
environment=A="1",B="2"
serverurl=AUTO
4. supervisord -c /etc/supervisord.conf
5. supervisorctl reload 重新加载配置文件
supervisorctl update
supervisorctl shutdown
supervisorctl status
6. supervisorctl 命令行
> help status
# supervisorctl
fluentd2kafka RUNNING pid 8094, uptime 0:12:10
supervisor>
# supervisorctl status
fluentd2kafka RUNNING pid 8094, uptime 0:12:28
7. supervisorctl start fluentd2kafka #启动这里改为start
supervisorctl stop fluentd2kafka # 停止
8. ps -ef | grep super