supervisor提供进程异常退出自动启动的功能,基本配置如下。
下载supervisor安装工具
wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
执行脚本
sh setuptools-0.6c11-py2.6.egg
下载安装包
wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0b1.tar.gz
tar -zxvf supervisor-3.0b1.tar.gz
cd supervisor-3.0b1
python setup.py install
拷贝配置文件
echo_supervisord_conf >/etc/supervisord.conf
此处可以取消注释,可以提供web页面观察,ip换成对应主机的ip
;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1: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))
此处为需要监控的进程信息,program名称随便起,command为进程名
[program:Jetty]
command=/home/work/jdk1.8.0_20/bin/java -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -Xss256k -server -Xms4G -Xmx4G -Djetty.logs=/home/work/jetty/logs -Djetty.home=/home/work/jetty -Djetty.base=/home/work/jetty -Djava.io.tmpdir=/tmp -jar /home/work/jetty/start.jar jetty.state=/home/work/jetty/jetty.state jetty-logging.xml jetty-started.xml ; the program (relative uses PATH, can take args)
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
directory=/tmp ; directory to cwd to before exec (def no cwd)
umask=022 ; umask for process (default None)
priority=999 ; the relative start priority (default 999)
autostart=true ; start at supervisord start (default: true)
autorestart=unexpected ; whether/when to restart (default: unexpected)
startsecs=1 ; number of secs prog must stay running (def. 1)
;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 b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
然后启动服务:supervisord
查看状态
supervisorctl status
Jetty RUNNING pid 27600, uptime 0:00:02
配置文件重载为 supervisorctl reload 重载后要重新启动进程。