Skip to content

Commit

Permalink
Merge pull request #297 from bflad/sysv-upstream
Browse files Browse the repository at this point in the history
Update docker daemon SysV init scripts with upstream improvements
  • Loading branch information
bflad committed Apr 14, 2015
2 parents 3ed08c0 + a135c1f commit 1ab77f0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
22 changes: 18 additions & 4 deletions templates/debian/docker.sysv.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides: docker
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: cgroupfs-mount cgroup-lite
# Should-Stop: cgroupfs-mount cgroup-lite
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Create lightweight, portable, self-sufficient containers.
Expand All @@ -20,7 +23,10 @@ BASE=$(basename $0)

# modify these in /etc/default/$BASE (/etc/default/docker)
DOCKER=/usr/bin/$BASE
# This is the pid file managed by docker itself
DOCKER_PIDFILE=/var/run/$BASE.pid
# This is the pid file created/managed by start-stop-daemon
DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid
DOCKER_LOGFILE=/var/log/$BASE.log
DOCKER_OPTS=
DOCKER_DESC="Docker"
Expand Down Expand Up @@ -83,11 +89,19 @@ case "$1" in
touch "$DOCKER_LOGFILE"
chgrp docker "$DOCKER_LOGFILE"

ulimit -n 1048576
if [ "$BASH" ]; then
ulimit -u 1048576
else
ulimit -p 1048576
fi

log_begin_msg "Starting $DOCKER_DESC: $BASE"
start-stop-daemon --start --background \
--no-close \
--exec "$DOCKER" \
--pidfile "$DOCKER_PIDFILE" \
--pidfile "$DOCKER_SSD_PIDFILE" \
--make-pidfile \
-- \
-d -p "$DOCKER_PIDFILE" \
$DOCKER_OPTS \
Expand All @@ -98,13 +112,13 @@ case "$1" in
stop)
fail_unless_root
log_begin_msg "Stopping $DOCKER_DESC: $BASE"
start-stop-daemon --stop --pidfile "$DOCKER_PIDFILE"
start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE"
log_end_msg $?
;;

restart)
fail_unless_root
docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
docker_pid=`cat "$DOCKER_SSD_PIDFILE" 2>/dev/null`
[ -n "$docker_pid" ] \
&& ps -p $docker_pid > /dev/null 2>&1 \
&& $0 stop
Expand All @@ -117,7 +131,7 @@ case "$1" in
;;

status)
status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKER" "$DOCKER_DESC"
;;

*)
Expand Down
13 changes: 11 additions & 2 deletions templates/default/docker.sysv.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

exec="<%= Docker::Helpers.executable(node) %>"
prog="docker"
unshare=/usr/bin/unshare
<% if node['docker']['pidfile'] -%>
pidfile="<%= node['docker']['pidfile'] %>"
<% else -%>
Expand Down Expand Up @@ -58,11 +59,13 @@ prestart() {
start() {
[ -x $exec ] || exit 5

check_for_cleanup

if ! [ -f $pidfile ]; then
prestart
printf "Starting $prog:\t"
echo "\n$(date)\n" >> $logfile
$exec -d $DOCKER_OPTS &>> $logfile &
"$unshare" -m -- $exec -d $DOCKER_OPTS &>> $logfile &
pid=$!
touch $lockfile
# wait up to 10 seconds for the pidfile to exist. see
Expand All @@ -84,7 +87,7 @@ start() {

stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
killproc -p $pidfile -d 300 $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
Expand Down Expand Up @@ -112,6 +115,12 @@ rh_status_q() {
rh_status >/dev/null 2>&1
}

check_for_cleanup() {
if [ -f ${pidfile} ]; then
/bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
fi
}

case "$1" in
start)
rh_status_q && exit 0
Expand Down

0 comments on commit 1ab77f0

Please sign in to comment.