github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/debian/docker.io.docker.init (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/sbin/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 cgroupfs_mount() { 55 # see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount 56 if grep -v '^#' /etc/fstab | grep -q cgroup \ 57 || [ ! -e /proc/cgroups ] \ 58 || [ ! -d /sys/fs/cgroup ]; then 59 return 60 fi 61 if ! mountpoint -q /sys/fs/cgroup; then 62 mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup 63 fi 64 ( 65 cd /sys/fs/cgroup 66 for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do 67 mkdir -p $sys 68 if ! mountpoint -q $sys; then 69 if ! mount -n -t cgroup -o $sys cgroup $sys; then 70 rmdir $sys || true 71 fi 72 fi 73 done 74 ) 75 } 76 77 case "$1" in 78 start) 79 fail_unless_root 80 81 cgroupfs_mount 82 83 touch "$DOCKER_LOGFILE" 84 chgrp docker "$DOCKER_LOGFILE" 85 86 ulimit -n 1048576 87 88 # Having non-zero limits causes performance problems due to accounting overhead 89 # in the kernel. We recommend using cgroups to do container-local accounting. 90 if [ "$BASH" ]; then 91 ulimit -u unlimited 92 else 93 ulimit -p unlimited 94 fi 95 96 log_begin_msg "Starting $DOCKER_DESC: $BASE" 97 $0 status >>/dev/null \ 98 || start-stop-daemon --start --background \ 99 --no-close \ 100 --exec "$DOCKERD" \ 101 --pidfile "$DOCKER_SSD_PIDFILE" \ 102 --make-pidfile \ 103 -- \ 104 -p "$DOCKER_PIDFILE" \ 105 $DOCKER_OPTS \ 106 >> "$DOCKER_LOGFILE" 2>&1 107 log_end_msg $? 108 ;; 109 110 stop) 111 fail_unless_root 112 if [ -f "$DOCKER_SSD_PIDFILE" ]; then 113 log_begin_msg "Stopping $DOCKER_DESC: $BASE" 114 start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" --remove-pidfile --retry 10 115 log_end_msg $? 116 else 117 log_warning_msg "Docker already stopped - file $DOCKER_SSD_PIDFILE not found." 118 fi 119 ;; 120 121 restart) 122 fail_unless_root 123 docker_pid=$(cat "$DOCKER_SSD_PIDFILE" 2> /dev/null) 124 [ -n "$docker_pid" ] \ 125 && ps -p $docker_pid > /dev/null 2>&1 \ 126 && $0 stop 127 $0 start 128 ;; 129 130 force-reload) 131 fail_unless_root 132 $0 restart 133 ;; 134 135 status) 136 status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKERD" "$DOCKER_DESC" 137 ;; 138 139 *) 140 echo "Usage: service docker {start|stop|restart|status}" 141 exit 1 142 ;; 143 esac