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.

119 lines
3.3 KiB

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. # Return
  37. # 0 if daemon has been started
  38. # 1 if daemon was already running
  39. # 2 if daemon could not be started
  40. start-stop-daemon --start --quiet --background --no-close \
  41. --make-pidfile --pidfile $PIDFILE \
  42. --exec $DAEMON -c $DAEMON_USER --test > /dev/null \
  43. || return 1
  44. start-stop-daemon --start --quiet --background --no-close \
  45. --make-pidfile --pidfile $PIDFILE \
  46. --exec $DAEMON -c $DAEMON_USER -- \
  47. $DAEMON_ARGS >> $DAEMON_LOG_FILE 2>&1 \
  48. || return 2
  49. }
  50. #
  51. # Function that stops the daemon/service
  52. #
  53. do_stop()
  54. {
  55. # Return
  56. # 0 if daemon has been stopped
  57. # 1 if daemon was already stopped
  58. # 2 if daemon could not be stopped
  59. # other if a failure occurred
  60. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  61. RETVAL="$?"
  62. [ "$RETVAL" = 2 ] && return 2
  63. # Many daemons don't delete their pidfiles when they exit.
  64. rm -f $PIDFILE
  65. return "$RETVAL"
  66. }
  67. case "$1" in
  68. start)
  69. log_daemon_msg "Starting $DESC" "$NAME"
  70. do_start
  71. case "$?" in
  72. 0|1) log_end_msg 0 || exit 0 ;;
  73. 2) log_end_msg 1 || exit 1 ;;
  74. esac
  75. ;;
  76. stop)
  77. log_daemon_msg "Stopping $DESC" "$NAME"
  78. do_stop
  79. case "$?" in
  80. 0|1) log_end_msg 0 ;;
  81. 2) exit 1 ;;
  82. esac
  83. ;;
  84. status)
  85. status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
  86. ;;
  87. restart|force-reload)
  88. log_daemon_msg "Restarting $DESC" "$NAME"
  89. do_stop
  90. case "$?" in
  91. 0|1)
  92. do_start
  93. case "$?" in
  94. 0) log_end_msg 0 ;;
  95. 1) log_end_msg 1 ;; # Old process is still running
  96. *) log_end_msg 1 ;; # Failed to start
  97. esac
  98. ;;
  99. *)
  100. # Failed to stop
  101. log_end_msg 1
  102. ;;
  103. esac
  104. ;;
  105. *)
  106. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  107. exit 3
  108. ;;
  109. esac