Selaa lähdekoodia

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 <steven@axiomzen.co>
Steven Richards 10 vuotta sitten
vanhempi
commit
e5ff643aed
1 muutettua tiedostoa jossa 15 lisäystä ja 7 poistoa
  1. 15 7
      contrib/init/sysvinit-debian/docker

+ 15 - 7
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