1
0

salt-minion.init 2.9 KB

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