github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/contrib/init/sysvinit-debian/docker (about) 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 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 55 fail_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 ) 83 } 84 85 case "$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