@@ -35,122 +35,83 @@ DOCKER_DESC="Docker"
3535. /lib/lsb/init-functions
3636
3737if [ -f /etc/default/$BASE ]; then
38- . /etc/default/$BASE
38+ . /etc/default/$BASE
3939fi
4040
4141# Check docker is present
4242if [ ! -x $DOCKERD ]; then
43- log_failure_msg " $DOCKERD not present or not executable"
44- exit 1
43+ log_failure_msg " $DOCKERD not present or not executable"
44+ exit 1
4545fi
4646
47- check_init () {
48- # see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it directly)
49- if [ -x /sbin/initctl ] && /sbin/initctl version 2> /dev/null | grep -q upstart; then
50- log_failure_msg " $DOCKER_DESC is managed via upstart, try using service $BASE $1 "
51- exit 1
52- fi
53- }
54-
5547fail_unless_root () {
56- if [ " $( id -u) " != ' 0' ]; then
57- log_failure_msg " $DOCKER_DESC must be run as root"
58- exit 1
59- fi
60- }
61-
62- cgroupfs_mount () {
63- # see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
64- if grep -v ' ^#' /etc/fstab | grep -q cgroup \
65- || [ ! -e /proc/cgroups ] \
66- || [ ! -d /sys/fs/cgroup ]; then
67- return
68- fi
69- if ! mountpoint -q /sys/fs/cgroup; then
70- mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
71- fi
72- (
73- cd /sys/fs/cgroup
74- for sys in $( awk ' !/^#/ { if ($4 == 1) print $1 }' /proc/cgroups) ; do
75- mkdir -p $sys
76- if ! mountpoint -q $sys ; then
77- if ! mount -n -t cgroup -o $sys cgroup $sys ; then
78- rmdir $sys || true
79- fi
80- fi
81- done
82- )
48+ if [ " $( id -u) " != ' 0' ]; then
49+ log_failure_msg " $DOCKER_DESC must be run as root"
50+ exit 1
51+ fi
8352}
8453
8554case " $1 " in
86- start)
87- check_init
88-
89- fail_unless_root
90-
91- cgroupfs_mount
92-
93- touch " $DOCKER_LOGFILE "
94- chgrp docker " $DOCKER_LOGFILE "
95-
96- ulimit -n 1048576
97-
98- # Having non-zero limits causes performance problems due to accounting overhead
99- # in the kernel. We recommend using cgroups to do container-local accounting.
100- if [ " $BASH " ]; then
101- ulimit -u unlimited
102- else
103- ulimit -p unlimited
104- fi
105-
106- log_begin_msg " Starting $DOCKER_DESC : $BASE "
107- start-stop-daemon --start --background \
108- --no-close \
109- --exec " $DOCKERD " \
110- --pidfile " $DOCKER_SSD_PIDFILE " \
111- --make-pidfile \
112- -- \
113- -p " $DOCKER_PIDFILE " \
114- $DOCKER_OPTS \
115- >> " $DOCKER_LOGFILE " 2>&1
116- log_end_msg $?
117- ;;
118-
119- stop)
120- check_init
121- fail_unless_root
122- if [ -f " $DOCKER_SSD_PIDFILE " ]; then
123- log_begin_msg " Stopping $DOCKER_DESC : $BASE "
124- start-stop-daemon --stop --pidfile " $DOCKER_SSD_PIDFILE " --retry 10
125- log_end_msg $?
126- else
127- log_warning_msg " Docker already stopped - file $DOCKER_SSD_PIDFILE not found."
128- fi
129- ;;
130-
131- restart)
132- check_init
133- fail_unless_root
134- docker_pid=` cat " $DOCKER_SSD_PIDFILE " 2> /dev/null`
135- [ -n " $docker_pid " ] \
136- && ps -p $docker_pid > /dev/null 2>&1 \
137- && $0 stop
138- $0 start
139- ;;
140-
141- force-reload)
142- check_init
143- fail_unless_root
144- $0 restart
145- ;;
146-
147- status)
148- check_init
149- status_of_proc -p " $DOCKER_SSD_PIDFILE " " $DOCKERD " " $DOCKER_DESC "
150- ;;
151-
152- * )
153- echo " Usage: service docker {start|stop|restart|status}"
154- exit 1
155- ;;
156- esac
55+ start)
56+ fail_unless_root
57+
58+ touch " $DOCKER_LOGFILE "
59+ chgrp docker " $DOCKER_LOGFILE "
60+
61+ ulimit -n 524288
62+
63+ # Having non-zero limits causes performance problems due to accounting overhead
64+ # in the kernel. We recommend using cgroups to do container-local accounting.
65+ if [ " $BASH " ]; then
66+ ulimit -u unlimited
67+ else
68+ ulimit -p unlimited
69+ fi
70+
71+ log_begin_msg " Starting $DOCKER_DESC : $BASE "
72+ start-stop-daemon --start --background \
73+ --no-close \
74+ --exec " $DOCKERD " \
75+ --pidfile " $DOCKER_SSD_PIDFILE " \
76+ --make-pidfile \
77+ -- \
78+ -p " $DOCKER_PIDFILE " \
79+ $DOCKER_OPTS \
80+ >> " $DOCKER_LOGFILE " 2>&1
81+ log_end_msg $?
82+ ;;
83+
84+ stop)
85+ fail_unless_root
86+ if [ -f " $DOCKER_SSD_PIDFILE " ]; then
87+ log_begin_msg " Stopping $DOCKER_DESC : $BASE "
88+ start-stop-daemon --stop --pidfile " $DOCKER_SSD_PIDFILE " --retry 10
89+ log_end_msg $?
90+ else
91+ log_warning_msg " Docker already stopped - file $DOCKER_SSD_PIDFILE not found."
92+ fi
93+ ;;
94+
95+ restart)
96+ fail_unless_root
97+ docker_pid=$( cat " $DOCKER_SSD_PIDFILE " 2> /dev/null || true)
98+ [ -n " $docker_pid " ] \
99+ && ps -p $docker_pid > /dev/null 2>&1 \
100+ && $0 stop
101+ $0 start
102+ ;;
103+
104+ force-reload)
105+ fail_unless_root
106+ $0 restart
107+ ;;
108+
109+ status)
110+ status_of_proc -p " $DOCKER_SSD_PIDFILE " " $DOCKERD " " $DOCKER_DESC "
111+ ;;
112+
113+ * )
114+ echo " Usage: service docker {start|stop|restart|status}"
115+ exit 1
116+ ;;
117+ esac
0 commit comments