docker 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. exec="/usr/bin/$prog"
  24. pidfile="/var/run/$prog.pid"
  25. lockfile="/var/lock/subsys/$prog"
  26. logfile="/var/log/$prog"
  27. [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
  28. prestart() {
  29. service cgconfig status > /dev/null
  30. if [[ $? != 0 ]]; then
  31. service cgconfig start
  32. fi
  33. }
  34. start() {
  35. [ -x $exec ] || exit 5
  36. if ! [ -f $pidfile ]; then
  37. prestart
  38. printf "Starting $prog:\t"
  39. echo "\n$(date)\n" >> $logfile
  40. $exec -d $other_args &>> $logfile &
  41. pid=$!
  42. touch $lockfile
  43. # wait up to 10 seconds for the pidfile to exist. see
  44. # https://github.com/docker/docker/issues/5359
  45. tries=0
  46. while [ ! -f $pidfile -a $tries -lt 10 ]; do
  47. sleep 1
  48. tries=$((tries + 1))
  49. done
  50. success
  51. echo
  52. else
  53. failure
  54. echo
  55. printf "$pidfile still exists...\n"
  56. exit 7
  57. fi
  58. }
  59. stop() {
  60. echo -n $"Stopping $prog: "
  61. killproc -p $pidfile -d 300 $prog
  62. retval=$?
  63. echo
  64. [ $retval -eq 0 ] && rm -f $lockfile
  65. return $retval
  66. }
  67. restart() {
  68. stop
  69. start
  70. }
  71. reload() {
  72. restart
  73. }
  74. force_reload() {
  75. restart
  76. }
  77. rh_status() {
  78. status -p $pidfile $prog
  79. }
  80. rh_status_q() {
  81. rh_status >/dev/null 2>&1
  82. }
  83. case "$1" in
  84. start)
  85. rh_status_q && exit 0
  86. $1
  87. ;;
  88. stop)
  89. rh_status_q || exit 0
  90. $1
  91. ;;
  92. restart)
  93. $1
  94. ;;
  95. reload)
  96. rh_status_q || exit 7
  97. $1
  98. ;;
  99. force-reload)
  100. force_reload
  101. ;;
  102. status)
  103. rh_status
  104. ;;
  105. condrestart|try-restart)
  106. rh_status_q || exit 0
  107. restart
  108. ;;
  109. *)
  110. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  111. exit 2
  112. esac
  113. exit $?