github.com/skanehira/moby@v17.12.1-ce-rc2+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  
   116  check_for_cleanup() {
   117  	if [ -f ${pidfile} ]; then
   118  		/bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
   119  	fi
   120  }
   121  
   122  case "$1" in
   123  	start)
   124  		rh_status_q && exit 0
   125  		$1
   126  		;;
   127  	stop)
   128  		rh_status_q || exit 0
   129  		$1
   130  		;;
   131  	restart)
   132  		$1
   133  		;;
   134  	reload)
   135  		rh_status_q || exit 7
   136  		$1
   137  		;;
   138  	force-reload)
   139  		force_reload
   140  		;;
   141  	status)
   142  		rh_status
   143  		;;
   144  	condrestart|try-restart)
   145  		rh_status_q || exit 0
   146  		restart
   147  		;;
   148  	*)
   149  		echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
   150  		exit 2
   151  esac
   152  
   153  exit $?