github.com/afein/docker@v1.8.2/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/$prog"
    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      [ -x $exec ] || exit 5
    45  
    46      check_for_cleanup
    47  
    48      if ! [ -f $pidfile ]; then
    49          prestart
    50          printf "Starting $prog:\t"
    51          echo "\n$(date)\n" >> $logfile
    52          "$unshare" -m -- $exec daemon $other_args &>> $logfile &
    53          pid=$!
    54          touch $lockfile
    55          # wait up to 10 seconds for the pidfile to exist.  see
    56          # https://github.com/docker/docker/issues/5359
    57          tries=0
    58          while [ ! -f $pidfile -a $tries -lt 10 ]; do
    59              sleep 1
    60              tries=$((tries + 1))
    61          done
    62          success
    63          echo
    64      else
    65          failure
    66          echo
    67          printf "$pidfile still exists...\n"
    68          exit 7
    69      fi
    70  }
    71  
    72  stop() {
    73      echo -n $"Stopping $prog: "
    74      killproc -p $pidfile -d 300 $prog
    75      retval=$?
    76      echo
    77      [ $retval -eq 0 ] && rm -f $lockfile
    78      return $retval
    79  }
    80  
    81  restart() {
    82      stop
    83      start
    84  }
    85  
    86  reload() {
    87      restart
    88  }
    89  
    90  force_reload() {
    91      restart
    92  }
    93  
    94  rh_status() {
    95      status -p $pidfile $prog
    96  }
    97  
    98  rh_status_q() {
    99      rh_status >/dev/null 2>&1
   100  }
   101  
   102  
   103  check_for_cleanup() {
   104      if [ -f ${pidfile} ]; then
   105          /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
   106      fi
   107  }
   108  
   109  case "$1" in
   110      start)
   111          rh_status_q && exit 0
   112          $1
   113          ;;
   114      stop)
   115          rh_status_q || exit 0
   116          $1
   117          ;;
   118      restart)
   119          $1
   120          ;;
   121      reload)
   122          rh_status_q || exit 7
   123          $1
   124          ;;
   125      force-reload)
   126          force_reload
   127          ;;
   128      status)
   129          rh_status
   130          ;;
   131      condrestart|try-restart)
   132          rh_status_q || exit 0
   133          restart
   134          ;;
   135      *)
   136          echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
   137          exit 2
   138  esac
   139  
   140  exit $?