From e5ff643aed78fb5dfb5e3fef518dfe56b82b3023 Mon Sep 17 00:00:00 2001 From: Steven Richards Date: Wed, 6 May 2015 17:37:49 -0700 Subject: [PATCH] Fixes #13031 - Check for upstart or init is not detecting properly This will now properly check whether /etc/init.d/docker or service docker is invoking the script and respond to the user accordingly. Signed-off-by: Steven Richards --- contrib/init/sysvinit-debian/docker | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/contrib/init/sysvinit-debian/docker b/contrib/init/sysvinit-debian/docker index 35fd71f13e..0022400ff1 100755 --- a/contrib/init/sysvinit-debian/docker +++ b/contrib/init/sysvinit-debian/docker @@ -39,18 +39,20 @@ if [ -f /etc/default/$BASE ]; then . /etc/default/$BASE fi -# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it) -if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then - log_failure_msg "$DOCKER_DESC is managed via upstart, try using service $BASE $1" - exit 1 -fi - # Check docker is present if [ ! -x $DOCKER ]; then log_failure_msg "$DOCKER not present or not executable" exit 1 fi +check_init() { + # see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it directly) + if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then + log_failure_msg "$DOCKER_DESC is managed via upstart, try using service $BASE $1" + exit 1 + fi +} + fail_unless_root() { if [ "$(id -u)" != '0' ]; then log_failure_msg "$DOCKER_DESC must be run as root" @@ -83,6 +85,8 @@ cgroupfs_mount() { case "$1" in start) + check_init + fail_unless_root cgroupfs_mount @@ -111,6 +115,7 @@ case "$1" in ;; stop) + check_init fail_unless_root log_begin_msg "Stopping $DOCKER_DESC: $BASE" start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" @@ -118,6 +123,7 @@ case "$1" in ;; restart) + check_init fail_unless_root docker_pid=`cat "$DOCKER_SSD_PIDFILE" 2>/dev/null` [ -n "$docker_pid" ] \ @@ -127,16 +133,18 @@ case "$1" in ;; force-reload) + check_init fail_unless_root $0 restart ;; status) + check_init status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKER" "$DOCKER_DESC" ;; *) - echo "Usage: $0 {start|stop|restart|status}" + echo "Usage: service docker {start|stop|restart|status}" exit 1 ;; esac