Created
July 16, 2015 14:18
-
-
Save sitano/183670a626f63a4b77ac to your computer and use it in GitHub Desktop.
docker upstart redis startup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "Redis container" | |
author "Ivan Prisyazhnyy" | |
start on filesystem and started docker | |
stop on runlevel [!2345] or stopping docker | |
# Docker has a timeout of 10 seconds so as long as this | |
# is longer so we don't kill the wait process | |
kill timeout 20 | |
# We don't want to TERM the `docker wait` process so we fake the signal | |
# we send to it. The pre-stop script issues the `docker stop` command | |
# which causes the `docker wait` process to exit | |
kill signal CONT | |
# Due to a bug in upstart we need to set the modes we consider | |
# successful exists https://bugs.launchpad.net/upstart/+bug/568288 | |
normal exit 0 CONT | |
respawn | |
respawn limit 3 5 | |
limit nofile 65535 65535 | |
# instance $PORT | |
script | |
NAME="redis" | |
PORT=6379 | |
ID=`docker ps -a | grep ${NAME}-${PORT} | cut -f 1 -d ' '` | |
START=1 | |
if [ ! -z "${ID}" ]; then | |
if docker ps | grep -q "${ID}"; then | |
START=0 | |
else | |
NID=$(docker start ${ID}) | |
[ "${NID}" = "${ID}" ] && START=0 | |
fi | |
fi | |
if [ $START -ne 0 ]; then | |
ID=$(docker run -d --name ${NAME}-${PORT} \ | |
-h `hostname` \ | |
-p 127.0.0.1::6379 \ | |
-v /var/liv/redis/6379:/data \ | |
redis \ | |
redis-server \ | |
--appendonly yes) | |
fi | |
exec docker wait ${ID} | |
end script | |
pre-stop script | |
NAME="redis" | |
PORT=6379 | |
ID=`docker ps -a | grep ${NAME}-${PORT} | cut -f 1 -d ' '` | |
if [ ! -z "${ID}" ]; then | |
docker stop "${ID}" | |
fi | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment