2013-10-15 11:37:18 -04:00
|
|
|
#!/bin/sh
|
2014-08-07 18:45:22 -04:00
|
|
|
set -e
|
2013-10-15 11:37:18 -04:00
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: docker
|
|
|
|
# Required-Start: $syslog $remote_fs
|
|
|
|
# Required-Stop: $syslog $remote_fs
|
2014-05-07 11:46:41 -04:00
|
|
|
# Should-Start: cgroupfs-mount cgroup-lite
|
|
|
|
# Should-Stop: cgroupfs-mount cgroup-lite
|
2013-10-15 11:37:18 -04:00
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2013-10-23 18:03:04 -04:00
|
|
|
# Short-Description: Create lightweight, portable, self-sufficient containers.
|
|
|
|
# Description:
|
|
|
|
# Docker is an open-source project to easily create lightweight, portable,
|
|
|
|
# self-sufficient containers from any application. The same container that a
|
|
|
|
# developer builds and tests on a laptop can run at scale, in production, on
|
|
|
|
# VMs, bare metal, OpenStack clusters, public clouds and more.
|
2013-10-15 11:37:18 -04:00
|
|
|
### END INIT INFO
|
|
|
|
|
2014-03-10 01:16:42 -04:00
|
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
|
|
|
2015-09-23 07:23:01 -04:00
|
|
|
BASE=docker
|
2013-10-23 18:03:04 -04:00
|
|
|
|
2014-03-10 01:16:42 -04:00
|
|
|
# modify these in /etc/default/$BASE (/etc/default/docker)
|
2013-10-23 18:03:04 -04:00
|
|
|
DOCKER=/usr/bin/$BASE
|
2014-06-03 19:28:06 -04:00
|
|
|
# This is the pid file managed by docker itself
|
2013-10-23 18:03:04 -04:00
|
|
|
DOCKER_PIDFILE=/var/run/$BASE.pid
|
2014-06-03 19:28:06 -04:00
|
|
|
# This is the pid file created/managed by start-stop-daemon
|
|
|
|
DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid
|
2014-03-11 03:40:31 -04:00
|
|
|
DOCKER_LOGFILE=/var/log/$BASE.log
|
2013-10-15 11:37:18 -04:00
|
|
|
DOCKER_OPTS=
|
2014-03-10 01:16:42 -04:00
|
|
|
DOCKER_DESC="Docker"
|
2013-10-15 11:37:18 -04:00
|
|
|
|
|
|
|
# Get lsb functions
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
2013-10-23 18:03:04 -04:00
|
|
|
if [ -f /etc/default/$BASE ]; then
|
|
|
|
. /etc/default/$BASE
|
2013-10-15 11:37:18 -04:00
|
|
|
fi
|
|
|
|
|
2013-10-23 18:03:04 -04:00
|
|
|
# Check docker is present
|
|
|
|
if [ ! -x $DOCKER ]; then
|
|
|
|
log_failure_msg "$DOCKER not present or not executable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-05-06 20:37:49 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-10-23 18:03:04 -04:00
|
|
|
fail_unless_root() {
|
|
|
|
if [ "$(id -u)" != '0' ]; then
|
2014-03-10 01:16:42 -04:00
|
|
|
log_failure_msg "$DOCKER_DESC must be run as root"
|
2013-10-23 18:03:04 -04:00
|
|
|
exit 1
|
2013-10-15 11:37:18 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-03-11 03:21:59 -04:00
|
|
|
cgroupfs_mount() {
|
|
|
|
# see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
|
|
|
|
if grep -v '^#' /etc/fstab | grep -q cgroup \
|
|
|
|
|| [ ! -e /proc/cgroups ] \
|
|
|
|
|| [ ! -d /sys/fs/cgroup ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if ! mountpoint -q /sys/fs/cgroup; then
|
|
|
|
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
|
|
|
|
fi
|
|
|
|
(
|
|
|
|
cd /sys/fs/cgroup
|
|
|
|
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
|
|
|
|
mkdir -p $sys
|
|
|
|
if ! mountpoint -q $sys; then
|
|
|
|
if ! mount -n -t cgroup -o $sys cgroup $sys; then
|
|
|
|
rmdir $sys || true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2013-10-15 11:37:18 -04:00
|
|
|
case "$1" in
|
|
|
|
start)
|
2015-05-06 20:37:49 -04:00
|
|
|
check_init
|
|
|
|
|
2013-10-23 18:03:04 -04:00
|
|
|
fail_unless_root
|
2014-03-10 01:16:42 -04:00
|
|
|
|
2014-03-11 03:21:59 -04:00
|
|
|
cgroupfs_mount
|
2014-03-10 01:16:42 -04:00
|
|
|
|
2014-03-11 03:40:31 -04:00
|
|
|
touch "$DOCKER_LOGFILE"
|
|
|
|
chgrp docker "$DOCKER_LOGFILE"
|
2014-03-10 01:16:42 -04:00
|
|
|
|
2014-07-02 11:38:19 -04:00
|
|
|
ulimit -n 1048576
|
2014-07-14 14:34:04 -04:00
|
|
|
if [ "$BASH" ]; then
|
|
|
|
ulimit -u 1048576
|
|
|
|
else
|
|
|
|
ulimit -p 1048576
|
|
|
|
fi
|
2014-07-02 11:38:19 -04:00
|
|
|
|
2014-03-10 01:16:42 -04:00
|
|
|
log_begin_msg "Starting $DOCKER_DESC: $BASE"
|
2013-10-23 18:03:04 -04:00
|
|
|
start-stop-daemon --start --background \
|
2014-03-10 01:16:42 -04:00
|
|
|
--no-close \
|
2015-06-15 13:34:59 -04:00
|
|
|
--exec "$DOCKER" \
|
2014-06-03 19:28:06 -04:00
|
|
|
--pidfile "$DOCKER_SSD_PIDFILE" \
|
|
|
|
--make-pidfile \
|
2015-06-15 13:34:59 -04:00
|
|
|
-- \
|
2015-07-22 14:24:38 -04:00
|
|
|
daemon -p "$DOCKER_PIDFILE" \
|
2014-03-10 01:16:42 -04:00
|
|
|
$DOCKER_OPTS \
|
2014-03-11 03:40:31 -04:00
|
|
|
>> "$DOCKER_LOGFILE" 2>&1
|
2013-10-15 11:37:18 -04:00
|
|
|
log_end_msg $?
|
|
|
|
;;
|
|
|
|
|
|
|
|
stop)
|
2015-05-06 20:37:49 -04:00
|
|
|
check_init
|
2013-10-23 18:03:04 -04:00
|
|
|
fail_unless_root
|
2014-03-10 01:16:42 -04:00
|
|
|
log_begin_msg "Stopping $DOCKER_DESC: $BASE"
|
2014-06-03 19:28:06 -04:00
|
|
|
start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE"
|
2013-10-15 11:37:18 -04:00
|
|
|
log_end_msg $?
|
|
|
|
;;
|
|
|
|
|
|
|
|
restart)
|
2015-05-06 20:37:49 -04:00
|
|
|
check_init
|
2013-10-23 18:03:04 -04:00
|
|
|
fail_unless_root
|
2014-06-03 19:28:06 -04:00
|
|
|
docker_pid=`cat "$DOCKER_SSD_PIDFILE" 2>/dev/null`
|
2013-10-15 11:37:18 -04:00
|
|
|
[ -n "$docker_pid" ] \
|
|
|
|
&& ps -p $docker_pid > /dev/null 2>&1 \
|
|
|
|
&& $0 stop
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
|
|
|
|
force-reload)
|
2015-05-06 20:37:49 -04:00
|
|
|
check_init
|
2013-10-23 18:03:04 -04:00
|
|
|
fail_unless_root
|
2013-10-15 11:37:18 -04:00
|
|
|
$0 restart
|
|
|
|
;;
|
|
|
|
|
|
|
|
status)
|
2015-05-06 20:37:49 -04:00
|
|
|
check_init
|
2014-08-07 18:45:22 -04:00
|
|
|
status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKER" "$DOCKER_DESC"
|
2013-10-15 11:37:18 -04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2015-05-06 20:37:49 -04:00
|
|
|
echo "Usage: service docker {start|stop|restart|status}"
|
2013-10-15 11:37:18 -04:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|