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.

118 lines
3.2 KiB

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