upstart开机脚本demo

upstart开机脚本demo

摘要

upstart开机脚本demo

脚本位置

/etc/init/xxxx.conf

mytest.conf

description "mytest"
author "bsspirit <http://blog.fens.me>"

env var=bar
export var

start on startup
stop on shutdown

respawn
respawn limit 2 5

console output

pre-start script
        logger "pre-start: before: var=$var"
        var=pre-start
        export var
        logger "pre-start: after: var=$var"
end script

post-start script
        logger "post-start: before: var=$var"
        var=post-start
        export var
        logger "post-start: after: var=$var"
end script

script
        logger "script: before: var=$var"
        var=main
        export var
        sleep 60000
        logger "script: after: var=$var"
end script

post-stop script
        logger "post-stop: before: var=$var"
        var=post-stop
        export var
        logger "post-stop: after: var=$var"
end script

启动docker容器 mydocker.conf

description "restart container"
author "zsl"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script

/usr/bin/docker restart  1b5e83201b84
nohup /usr/bin/docker exec -i 1b5e83201b84 /bin/bash "/root/restart-app5.sh" >/dev/null 2>&1 &
#nohup /usr/bin/docker exec -i 1b5e83201b84 /bin/bash "/root/restart-app3.sh" >/dev/null 2>&1 &
#/bin/bash /root/restart_bak.sh
end script