docker 2.4 KB

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