supervisor管理启动重启,Java,Go程序Demo

简介
Supervisor 是一款 Python 开发的进程管理系统,允许用户监视和控制 Linux 上的进程,能将一个普通命令行进程变为后台守护进程,异常退出时能自动重启

1、安装

yum -y install supervisor

2、配置默认配置文件

echo_supervisord_conf > /etc/supervisord.conf

3、修改主配置文件配置

vim /etc/supervisord.conf
... ...
# 其他配置保持默认即可
[include]
files = /etc/supervisord.d/*.ini

4、创建子进程 supervisor.ini
giftpanel go程序
recharge java程序

[program:giftpanel]
directory=/opt/gs/giftpanel/
command=/opt/gs/giftpanel/gift-panel  -DserviceCenter=ip -Dnamespace=gs-test -DserverPort=9082
numprocs=1
autostart=true
startretries=3
autorestart=true
redirect_stderr=false
stdout_logfile=/opt/supervisorlogs/giftpanel.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stderr_logfile=/opt/supervisorlogs/giftpanel.err.log
stderr_logfile_maxbytes=10MB 

[program:recharge]
command=/usr/lib/jvm/java-1.8.0/bin/java -jar -server -Xms512M -Xmx2048M  -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/gs/recharge/heapdump.hprof -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/data/gs/recharge/gc.log -DserverId=500 -DserviceCenter=ip  -Dnamespace=gs-test -DserverPort=9090 /opt/gs/recharge/recharge-1.0-SNAPSHOT-gs.jar
numprocs=1
autostart=true
startretries=3
autorestart=true
redirect_stderr=false
stdout_logfile=/opt/supervisorlogs/recharge.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stderr_logfile=/opt/supervisorlogs/recharge.log
stderr_logfile_maxbytes=10MB


#如果需要配置分组 后面添加配置
[group:gs]
programs=giftpanel,recharge

5、启动

第一次配置需要重启supervisord

systemctl start supervisord.service

之后添加子配置(*.ini)文件 只需要update即可

supervisorctl update

6,1启动项目未分组情况下

重启所有
supervisorctl restart all
supervisorctl restart recharge
supervisorctl restart giftpanel

停止所有
supervisorctl stop all
supervisorctl stop giftpanel
supervisorctl stop recharge

6,2启动项目分组情况下


重启所有
supervisorctl restart gs:*
重启
supervisorctl restart gs:recharge
supervisorctl restart gs:giftpanel

停止所有
supervisorctl stop gs:*
停止
supervisorctl stop gs:giftpanel
supervisorctl stop gs:recharge

查看log
tail -f /data/supervisorlogs/gs/giftpanel.log

你可能感兴趣的:(liunx,java,GoLang,Liunx,golang,java,jar,python)