Custom startup script to the next supervisord management

ubuntu14.04 system can be installed directly by the apt-get

apt-get install supervisord

Official website: http: //www.supervisord.org/

The main configuration file

This configuration was /etc/supervisor/supervisord.conf
configured as follows:

root@xxx:/etc/supervisor/conf.d# grep -vE "(^;|^$)" /etc/supervisor/supervisord.conf
[unix_http_server]
file=/var/log/supervisord/supervisor.sock   ; (the path to the socket file)
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/var/log/supervisord/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/log/supervisord/supervisor.sock ; use a unix:// URL  for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf

Application configuration file

In this configuration/etc/supervisor/conf.d

root@xxx:/etc/supervisor/conf.d# cat C9019_app.conf
[program:C9019_app]  # 这段要注意,改成你自己的
command=/opt/C9019/webapps/start.sh start   # 启动脚本,有什么参数都给添加上,这个脚本是自己写的
directory=/opt/C9019/webapps   # 在哪个目录下启动程序
autostart=true
exitcodes=0
autorestart=true
startretries=3
exitcodes=0,2
#stopsignal=TERM
#stopasgroup=true
stopwaitsecs=2
user=root
export JAVA_HOME=/opt/jdk1.8.0_121
export JRE_HOME=/opt/jdk1.8.0_121/jre
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:$PATH
stdout_logfile=/var/log/supervisord/C9019_app_stdout.log
stderr_logfile=/var/log/supervisord/C9019_app_stderr.log

Other parameters refer to the examiner cafe

start up

supervisord -c /etc/supervisor/supervisord.conf

Customize how the startup script to the managed supervisord

First we look at the custom script contents:

#!/bin/bash
'''省略N行
function start(){
        c="`ps -ef |grep config.type| grep -c ${MAIN_CLASS}`"

        if [ $c -le 1 ]; then
                echo "starting ${COMPONENT_NAME}..."
                java xxx(省略N多内容) >$LOGDIR/error.log  2>&1 >$LOGDIR/error.log  &  # 注意看这个&号
                echo $! > $LOGDIR/pid.log
                echo "started ${COMPONENT_NAME} pid:$!"
        else
                echo "already started ${COMPONENT_NAME} pid:`cat $LOGDIR/pid.log`"
        fi
}
function stop(){
        echo "stoping ${COMPONENT_NAME}..."
        for pid in $(ps aux|grep java|grep config.type| grep ${MAIN_CLASS}|awk '{print $2}')
        do
                echo "kill -9 ${pid}"
                kill -9 ${pid}
        done
        echo "stopped ${COMPONENT_NAME}"
}
function restart(){
        stop
        sleep 10
        start
}

case    "${COMMAND}"    in
start)
        start
;;
stop)
        stop
;;
restart)
        restart
;;
*)
        echo "require:start|stop|restart"
esac
exit 0

I had a custom script when you start the program with the & let the program running in the background, thus leading to supervisord not control the program, so it is necessary to & to delete.
In line with the time & have started, resulting in the following error, the solution is java xxx(省略N多内容) >$LOGDIR/error.log 2>&1 >$LOGDIR/error.log &the last one & deleted, so keep the foreground, supervisor able to control this procedure.

root@xxx:/etc/supervisor/conf.d# supervisorctl
C9019_app                        FATAL      Exited too quickly (process log may have details)
supervisor> restart C9019_app
C9019_app: ERROR (not running)
C9019_app: ERROR (abnormal termination

After removing the & perfect control procedures

root@xxx:/opt/C9019/webapps# supervisorctl
C9019_app                        RUNNING    pid 14464, uptime 0:25:53
supervisor> status
C9019_app                        RUNNING    pid 14464, uptime 0:25:54
supervisor> restart C9019_app
C9019_app: stopped
C9019_app: started

summary of the issue

Can not manage the program

Program into the background lead supervisor unmanageable, and this time you can put in the foreground.

Guess you like

Origin www.cnblogs.com/liaojiafa/p/11543261.html