salt-master.init 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: salt-master
  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: The Salt Master daemon
  9. # Description: The Salt Master is the central server (management
  10. # component) to which all Salt Minions connect
  11. ### END INIT INFO
  12. # Author: Michael Prokop <mika@debian.org>
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="The Salt Master daemon"
  15. NAME=salt-master
  16. DAEMON=/usr/bin/salt-master
  17. DAEMON_ARGS="-d"
  18. PIDFILE=/var/run/$NAME.pid
  19. SCRIPTNAME=/etc/init.d/$NAME
  20. # Exit if the package is not installed
  21. [ -x "$DAEMON" ] || exit 0
  22. # Read configuration variable file if it is present
  23. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  24. . /lib/lsb/init-functions
  25. do_start() {
  26. # Return
  27. # 0 if daemon has been started
  28. # 1 if daemon was already running
  29. # 2 if daemon could not be started
  30. pid=$(pidofproc -p $PIDFILE $DAEMON)
  31. if [ -n "$pid" ] ; then
  32. return 1
  33. fi
  34. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  35. $DAEMON_ARGS \
  36. || return 2
  37. }
  38. do_stop() {
  39. # Return
  40. # 0 if daemon has been stopped
  41. # 1 if daemon was already stopped
  42. # 2 if daemon could not be stopped
  43. # other if a failure occurred
  44. pids=$(pidof -x $DAEMON)
  45. if [ $? -eq 0 ] ; then
  46. echo $pids | xargs kill 2&1> /dev/null
  47. RETVAL=0
  48. else
  49. RETVAL=1
  50. fi
  51. [ "$RETVAL" = 2 ] && return 2
  52. rm -f $PIDFILE
  53. return "$RETVAL"
  54. }
  55. case "$1" in
  56. start)
  57. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  58. do_start
  59. case "$?" in
  60. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  61. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  62. esac
  63. ;;
  64. stop)
  65. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  66. do_stop
  67. case "$?" in
  68. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  69. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  70. esac
  71. ;;
  72. status)
  73. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  74. ;;
  75. #reload)
  76. # not implemented
  77. #;;
  78. restart|force-reload)
  79. log_daemon_msg "Restarting $DESC" "$NAME"
  80. do_stop
  81. case "$?" in
  82. 0|1)
  83. do_start
  84. case "$?" in
  85. 0) log_end_msg 0 ;;
  86. 1) log_end_msg 1 ;; # Old process is still running
  87. *) log_end_msg 1 ;; # Failed to start
  88. esac
  89. ;;
  90. *)
  91. # Failed to stop
  92. log_end_msg 1
  93. ;;
  94. esac
  95. ;;
  96. *)
  97. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  98. exit 3
  99. ;;
  100. esac
  101. exit 0