1. yum安装supervisor
yum install supervisor -y
通过这种形式安装的supervisor,其配置文件的目录位于:
/etc/supervisord.conf (主配置文件),修改配置文件最后一行,表示要加载和supervisor.conf同级的supervisord.d下的所有.conf结尾的配置文件
[include]
files = supervisord.d/*.conf
/etc/supervisor.d (默认子进程配置文件,也就是需要我们根据程序配置的地方)
2. 以demo.jar为例,以下为相应配置,放在/etc/supervisor.d下的demo.conf文件配置如下
[program:demo]
directory=/app/ehl-server/backup
command=/app/jdk/jdk1.8.0_191/bin/java -Xmx128m -Xms128m -jar /app/ehl-server/backup/demo.jar # 启动命令
autorestart=true
autostart=true
startretries=3
logfile_maxbytes=10MB
logfile_backups=10
user=root
log_stdout=true
log_stderr=true
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/app/ehl-server/backup/logs/demo.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=10MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
stdout_syslog=false ; send stdout to syslog with process name (default false)
stderr_logfile=/app/ehl-server/backup/logs/demoerr.log ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=10MB ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false ; emit events on stderr writes (default false)
stderr_syslog=false ; send stderr to syslog with process name (default false)
;environment=A="1",B="2" ; process environment additions (def no adds)
3. 使用方法
针对supervisor的命令
supervisorctl update #更新配置文件
supervisorctl reload #重新启动配置的程序
supervisorctl stop all #停止全部管理进程
针对supervisor操作管理的子进程的命令
supervisorctl
demo RUNNING pid 18824, uptime 0:03:38
supervisor>
然后可以在supervisor>后执行一下命令,分别停止,启动,重启等
start demo # 开启demo
stop demo # 关闭demo
restart demo # 重启demo