github.com/wozhu6104/docker@v20.10.10+incompatible/contrib/init/sysvinit-redhat/docker (about) 1 #!/bin/sh 2 # 3 # /etc/rc.d/init.d/docker 4 # 5 # Daemon for docker.com 6 # 7 # chkconfig: 2345 95 95 8 # description: Daemon for docker.com 9 10 ### BEGIN INIT INFO 11 # Provides: docker 12 # Required-Start: $network cgconfig 13 # Required-Stop: 14 # Should-Start: 15 # Should-Stop: 16 # Default-Start: 2 3 4 5 17 # Default-Stop: 0 1 6 18 # Short-Description: start and stop docker 19 # Description: Daemon for docker.com 20 ### END INIT INFO 21 22 # Source function library. 23 . /etc/rc.d/init.d/functions 24 25 prog="docker" 26 unshare=/usr/bin/unshare 27 exec="/usr/bin/dockerd" 28 pidfile="/var/run/$prog.pid" 29 lockfile="/var/lock/subsys/$prog" 30 logfile="/var/log/$prog" 31 32 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog 33 34 prestart() { 35 service cgconfig status > /dev/null 36 37 if [[ $? != 0 ]]; then 38 service cgconfig start 39 fi 40 41 } 42 43 start() { 44 if [ ! -x $exec ]; then 45 if [ ! -e $exec ]; then 46 echo "Docker executable $exec not found" 47 else 48 echo "You do not have permission to execute the Docker executable $exec" 49 fi 50 exit 5 51 fi 52 53 check_for_cleanup 54 55 if ! [ -f $pidfile ]; then 56 prestart 57 printf "Starting $prog:\t" 58 echo "\n$(date)\n" >> $logfile 59 "$unshare" -m -- $exec $other_args >> $logfile 2>&1 & 60 pid=$! 61 touch $lockfile 62 # wait up to 10 seconds for the pidfile to exist. see 63 # https://github.com/docker/docker/issues/5359 64 tries=0 65 while [ ! -f $pidfile -a $tries -lt 10 ]; do 66 sleep 1 67 tries=$((tries + 1)) 68 echo -n '.' 69 done 70 if [ ! -f $pidfile ]; then 71 failure 72 echo 73 exit 1 74 fi 75 success 76 echo 77 else 78 failure 79 echo 80 printf "$pidfile still exists...\n" 81 exit 7 82 fi 83 } 84 85 stop() { 86 echo -n $"Stopping $prog: " 87 killproc -p $pidfile -d 300 $prog 88 retval=$? 89 echo 90 [ $retval -eq 0 ] && rm -f $lockfile 91 return $retval 92 } 93 94 restart() { 95 stop 96 start 97 } 98 99 reload() { 100 restart 101 } 102 103 force_reload() { 104 restart 105 } 106 107 rh_status() { 108 status -p $pidfile $prog 109 } 110 111 rh_status_q() { 112 rh_status > /dev/null 2>&1 113 } 114 115 check_for_cleanup() { 116 if [ -f ${pidfile} ]; then 117 /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile} 118 fi 119 } 120 121 case "$1" in 122 start) 123 rh_status_q && exit 0 124 $1 125 ;; 126 stop) 127 rh_status_q || exit 0 128 $1 129 ;; 130 restart) 131 $1 132 ;; 133 reload) 134 rh_status_q || exit 7 135 $1 136 ;; 137 force-reload) 138 force_reload 139 ;; 140 status) 141 rh_status 142 ;; 143 condrestart | try-restart) 144 rh_status_q || exit 0 145 restart 146 ;; 147 *) 148 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" 149 exit 2 150 ;; 151 esac 152 153 exit $?