You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. #!/bin/bash
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides: kubelet
  5. # Required-Start: $local_fs $network $syslog
  6. # Required-Stop:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: The Kubernetes node container manager
  10. # Description:
  11. # The Kubernetes container manager maintains docker state against a state file.
  12. ### END INIT INFO
  13. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="The Kubernetes container manager"
  16. NAME=kubelet
  17. DAEMON={{ bin_dir }}/kubelet
  18. DAEMON_ARGS=""
  19. DAEMON_LOG_FILE=/var/log/$NAME.log
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. DAEMON_USER=root
  23. # Exit if the package is not installed
  24. [ -x "$DAEMON" ] || exit 0
  25. # Read configuration variable file if it is present
  26. [ -r /etc/kubernetes/$NAME.env ] && . /etc/kubernetes/$NAME.env
  27. # Define LSB log_* functions.
  28. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  29. # and status_of_proc is working.
  30. . /lib/lsb/init-functions
  31. #
  32. # Function that starts the daemon/service
  33. #
  34. do_start()
  35. {
  36. /usr/bin/docker rm -f kubelet &>/dev/null || true
  37. sleep 1
  38. # Return
  39. # 0 if daemon has been started
  40. # 1 if daemon was already running
  41. # 2 if daemon could not be started
  42. start-stop-daemon --start --quiet --background --no-close \
  43. --make-pidfile --pidfile $PIDFILE \
  44. --exec $DAEMON -c $DAEMON_USER --test > /dev/null \
  45. || return 1
  46. start-stop-daemon --start --quiet --background --no-close \
  47. --make-pidfile --pidfile $PIDFILE \
  48. --exec $DAEMON -c $DAEMON_USER -- \
  49. $DAEMON_ARGS >> $DAEMON_LOG_FILE 2>&1 \
  50. || return 2
  51. }
  52. #
  53. # Function that stops the daemon/service
  54. #
  55. do_stop()
  56. {
  57. # Return
  58. # 0 if daemon has been stopped
  59. # 1 if daemon was already stopped
  60. # 2 if daemon could not be stopped
  61. # other if a failure occurred
  62. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  63. RETVAL="$?"
  64. [ "$RETVAL" = 2 ] && return 2
  65. # Many daemons don't delete their pidfiles when they exit.
  66. rm -f $PIDFILE
  67. return "$RETVAL"
  68. }
  69. case "$1" in
  70. start)
  71. log_daemon_msg "Starting $DESC" "$NAME"
  72. do_start
  73. case "$?" in
  74. 0|1) log_end_msg 0 || exit 0 ;;
  75. 2) log_end_msg 1 || exit 1 ;;
  76. esac
  77. ;;
  78. stop)
  79. log_daemon_msg "Stopping $DESC" "$NAME"
  80. do_stop
  81. case "$?" in
  82. 0|1) log_end_msg 0 ;;
  83. 2) exit 1 ;;
  84. esac
  85. ;;
  86. status)
  87. status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
  88. ;;
  89. restart|force-reload)
  90. log_daemon_msg "Restarting $DESC" "$NAME"
  91. do_stop
  92. case "$?" in
  93. 0|1)
  94. do_start
  95. case "$?" in
  96. 0) log_end_msg 0 ;;
  97. 1) log_end_msg 1 ;; # Old process is still running
  98. *) log_end_msg 1 ;; # Failed to start
  99. esac
  100. ;;
  101. *)
  102. # Failed to stop
  103. log_end_msg 1
  104. ;;
  105. esac
  106. ;;
  107. *)
  108. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  109. exit 3
  110. ;;
  111. esac