upstart-20190417-Ubuntu 14.04 利用 upstart 守護 supervisord 進程

Intro

用 Ubuntu 的 upstart 守護 supervisord

Solution

# /etc/init/supervisord.conf

# supervisord - Upstarts the supervisor as service
# Put this file into /etc/init/supervisord.conf
#   sudo service supervisord start
#   sudo service supervisord stop
# Service gets started as root
# Needs `pgrep` available to root

description "Supervisord - Upstart"

stop on runlevel [016]

kill timeout 8

respawn

# change this to the directory which hosts the supervisord conf file
chdir /etc/supervisor/

env DAEMON=supervisord

# due to forking bug https://bugs.launchpad.net/upstart/+bug/406397/ this hack needs to be done
# 1. starts the daemon and a sleep operation keeping up with the daemon
# 2. stop will stop the sleep operation and manually stop the daemon

pre-start script
    exec $DAEMON
end script

script
    sleepWhileAppIsUp(){
        while pgrep $1 >/dev/null; do
            sleep 1
        done
    }

    sleepWhileAppIsUp $DAEMON
end script

post-stop script
    if pgrep $DAEMON;
    then
        kill `pgrep $DAEMON`
    fi
end script

刷新配置使其生效即可

# 刷新配置
initctl reload-configuration

# 加入 supervisord
initctl start supervisord
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章