github.com/torfuzx/docker@v1.8.1/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=$(basename $0) 23 24 # modify these in /etc/default/$BASE (/etc/default/docker) 25 DOCKER=/usr/bin/$BASE 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 $DOCKER ]; then 43 log_failure_msg "$DOCKER 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 if [ "$BASH" ]; then 98 ulimit -u 1048576 99 else 100 ulimit -p 1048576 101 fi 102 103 log_begin_msg "Starting $DOCKER_DESC: $BASE" 104 start-stop-daemon --start --background \ 105 --no-close \ 106 --exec "$DOCKER" \ 107 --pidfile "$DOCKER_SSD_PIDFILE" \ 108 --make-pidfile \ 109 -- \ 110 daemon -p "$DOCKER_PIDFILE" \ 111 $DOCKER_OPTS \ 112 >> "$DOCKER_LOGFILE" 2>&1 113 log_end_msg $? 114 ;; 115 116 stop) 117 check_init 118 fail_unless_root 119 log_begin_msg "Stopping $DOCKER_DESC: $BASE" 120 start-stop-daemon --stop --pidfile "$DOCKER_SSD_PIDFILE" 121 log_end_msg $? 122 ;; 123 124 restart) 125 check_init 126 fail_unless_root 127 docker_pid=`cat "$DOCKER_SSD_PIDFILE" 2>/dev/null` 128 [ -n "$docker_pid" ] \ 129 && ps -p $docker_pid > /dev/null 2>&1 \ 130 && $0 stop 131 $0 start 132 ;; 133 134 force-reload) 135 check_init 136 fail_unless_root 137 $0 restart 138 ;; 139 140 status) 141 check_init 142 status_of_proc -p "$DOCKER_SSD_PIDFILE" "$DOCKER" "$DOCKER_DESC" 143 ;; 144 145 *) 146 echo "Usage: service docker {start|stop|restart|status}" 147 exit 1 148 ;; 149 esac