Created
March 25, 2014 20:08
-
-
Save akoenig/9770235 to your computer and use it in GitHub Desktop.
Debian init script for Docker
This file contains hidden or 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
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: docker | |
# Required-Start: $syslog $remote_fs | |
# Required-Stop: $syslog $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Linux container runtime | |
# Description: Linux container runtime | |
### END INIT INFO | |
DOCKER=/usr/bin/docker | |
# Check docker is present | |
[ -x $DOCKER ] || (log_failure_msg "docker not present"; exit 1) | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
# Get lsb functions | |
. /lib/lsb/init-functions | |
check_root_id () | |
{ | |
if [ "$(id -u)" != "0" ]; then | |
log_failure_msg "docker must be run as root"; exit 1 | |
fi | |
} | |
case "$1" in | |
start) | |
check_root_id || exit 1 | |
log_begin_msg "Starting docker" | |
mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup | |
start-stop-daemon --start --background --exec "$DOCKER" -- -d | |
log_end_msg $? | |
;; | |
stop) | |
check_root_id || exit 1 | |
log_begin_msg "Stopping docker" | |
docker_pid=`pgrep -f "$DOCKER -d"` | |
[ -n "$docker_pid" ] && kill $docker_pid | |
log_end_msg $? | |
;; | |
restart) | |
check_root_id || exit 1 | |
docker_pid=`pgrep -f "$DOCKER -d"` | |
[ -n "$docker_pid" ] && /etc/init.d/docker stop | |
/etc/init.d/docker start | |
;; | |
force-reload) | |
check_root_id || exit 1 | |
/etc/init.d/docker restart | |
;; | |
status) | |
docker_pid=`pgrep -f "$DOCKER -d"` | |
if [ -z "$docker_pid" ] ; then | |
echo "docker not running" | |
else | |
echo "docker running (pid $docker_pid)" | |
fi | |
;; | |
*) | |
echo "Usage: /etc/init.d/docker {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment