Debian Codegraph @

engine/contrib/init/sysvinit-debian/docker

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2 set -e
3
4 ### BEGIN INIT INFO
5 # Provides: docker
6 # Required-Start: $syslog $remote_fs
7 # Required-Stop: $syslog $remote_fs
8 # Should-Start: cgroupfs-mount cgroup-lite
9 # Should-Stop: cgroupfs-mount cgroup-lite
10 # Default-Start: 2 3 4 5
11 # Default-Stop: 0 1 6
12 # Short-Description: Create lightweight, portable, self-sufficient containers.
13 # Description:
14 # Docker is an open-source project to easily create lightweight, portable,
15 # self-sufficient containers from any application. The same container that a
16 # developer builds and tests on a laptop can run at scale, in production, on
17 # VMs, bare metal, OpenStack clusters, public clouds and more.
18 ### END INIT INFO
19
20 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
21
22 BASE=docker
23
24 # modify these in /etc/default/$BASE (/etc/default/docker)
25 DOCKERD=/usr/bin/dockerd
26 # This is the pid file managed by docker itself
27 DOCKER_PIDFILE=/var/run/$BASE.pid
28 # This is the pid file created/managed by start-stop-daemon
29 DOCKER_SSD_PIDFILE=/var/run/$BASE-ssd.pid
30 DOCKER_LOGFILE=/var/log/$BASE.log
31 DOCKER_OPTS=
32 DOCKER_DESC="Docker"
33
34 # Get lsb functions
35 . /lib/lsb/init-functions
36
37 if [ -f /etc/default/$BASE ]; then
38 . /etc/default/$BASE
39 fi
40
41 # Check docker is present
42 if [ ! -x $DOCKERD ]; then
43 log_failure_msg "$DOCKERD not present or not executable"
44 exit 1
45 fi
46
47 fail_unless_root() {
48 if [ "$(id -u)" != '0' ]; then
49 log_failure_msg "$DOCKER_DESC must be run as root"
50 exit 1
51 fi
52 }
53
54 case "$1" in
55 start)
56 fail_unless_root
57
58 touch "$DOCKER_LOGFILE"
59 chgrp docker "$DOCKER_LOGFILE"
60
61 # Only set the hard limit (soft limit should remain as the system default of 1024):
62 ulimit -Hn 524288
63
64 # Having non-zero limits causes performance problems due to accounting overhead
65 # in the kernel. We recommend using cgroups to do container-local accounting.
66 if [ "$BASH" ]; then
67 ulimit -u unlimited
68 else
69 ulimit -p unlimited
70 fi
71
72 log_begin_msg "Starting $DOCKER_DESC: $BASE"
73 start-stop-daemon --start --background \
74 --no-close \
75 --exec "$DOCKERD" \
76 --pidfile "$DOCKER_SSD_PIDFILE" \
77 --make-pidfile \
78 -- \
79 -p "$DOCKER_PIDFILE" \
80 $DOCKER_OPTS \
81 >> "$DOCKER_LOGFILE" 2>&1
82 log_end_msg $?
83 ;;
84
85 stop)
86 fail_unless_root
87 if [ -f "$DOCKER_SSD_PIDFILE" ]; then
88 log_begin_msg "Stopping $DOCKER_DESC: $BASE"
89 start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" --retry 10
90 log_end_msg $?
91 else
92 log_warning_msg "Docker already stopped - file $DOCKER_SSD_PIDFILE not found."
93 fi
94 ;;
95
96 restart)
97 fail_unless_root
98 docker_pid=$(cat "$DOCKER_SSD_PIDFILE" 2> /dev/null || true)
99 [ -n "$docker_pid" ] \
100 && ps -p $docker_pid > /dev/null 2>&1 \
101 && $0 stop
102 $0 start
103 ;;
104
105 force-reload)
106 fail_unless_root
107 $0 restart
108 ;;
109
110 status)
111 status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKERD" "$DOCKER_DESC"
112 ;;
113
114 *)
115 echo "Usage: service docker {start|stop|restart|status}"
116 exit 1
117 ;;
118 esac