Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker daemon SysV init scripts with upstream improvements #297

Merged
merged 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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