salt-api.init 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: salt-api
  4. # Required-Start: $remote_fs $network
  5. # Required-Stop: $remote_fs $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: REST API for Salt
  9. # Description: salt-api provides a REST interface to the Salt master
  10. ### END INIT INFO
  11. # Author: Michael Prokop <mika@debian.org>
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. DESC="REST API for Salt"
  14. NAME=salt-api
  15. DAEMON=/usr/bin/salt-api
  16. DAEMON_ARGS="-d"
  17. PIDFILE=/var/run/$NAME.pid
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. # Exit if the package is not installed
  20. [ -x "$DAEMON" ] || exit 0
  21. # Read configuration variable file if it is present
  22. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  23. . /lib/init/vars.sh
  24. . /lib/lsb/init-functions
  25. do_start() {
  26. pid=$(pidofproc -p $PIDFILE $DAEMON)
  27. if [ -n "$pid" ] ; then
  28. log_begin_msg "$DESC already running."
  29. log_end_msg 0
  30. exit 0
  31. fi
  32. log_daemon_msg "Starting salt-api daemon: "
  33. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
  34. log_end_msg $?
  35. }
  36. do_stop() {
  37. log_begin_msg "Stopping $DESC ..."
  38. start-stop-daemon --stop --retry TERM/5 --quiet --oknodo --pidfile $PIDFILE
  39. RC=$?
  40. [ $RC -eq 0 ] && rm -f $PIDFILE
  41. log_end_msg $RC
  42. }
  43. case "$1" in
  44. start)
  45. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  46. do_start
  47. case "$?" in
  48. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  49. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  50. esac
  51. ;;
  52. stop)
  53. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  54. do_stop
  55. case "$?" in
  56. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  57. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  58. esac
  59. ;;
  60. status)
  61. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  62. ;;
  63. #reload)
  64. # not implemented
  65. #;;
  66. restart|force-reload)
  67. log_daemon_msg "Restarting $DESC" "$NAME"
  68. do_stop
  69. case "$?" in
  70. 0|1)
  71. do_start
  72. case "$?" in
  73. 0) log_end_msg 0 ;;
  74. 1) log_end_msg 1 ;; # Old process is still running
  75. *) log_end_msg 1 ;; # Failed to start
  76. esac
  77. ;;
  78. *)
  79. # Failed to stop
  80. log_end_msg 1
  81. ;;
  82. esac
  83. ;;
  84. *)
  85. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  86. exit 3
  87. ;;
  88. esac
  89. exit 0