1
0

salt-minion 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. #
  3. # Salt minion
  4. ###################################
  5. # LSB header
  6. ### BEGIN INIT INFO
  7. # Provides: salt-minion
  8. # Required-Start: $local_fs $remote_fs $network $named $time
  9. # Should-Start: $time ypbind smtp
  10. # Required-Stop: $local_fs $remote_fs $network $named $time
  11. # Should-Stop: ypbind smtp
  12. # Default-Start: 3 5
  13. # Default-Stop: 0 1 2 6
  14. # Short-Description: Salt minion daemon
  15. # Description: This is the Salt minion daemon that can be controlled by the
  16. # Salt master.
  17. ### END INIT INFO
  18. # chkconfig header
  19. # chkconfig: 345 97 04
  20. # description: This is the Salt minion daemon that can be controlled by the Salt master.
  21. #
  22. # processname: /usr/bin/salt-minion
  23. DEBIAN_VERSION=/etc/debian_version
  24. SUSE_RELEASE=/etc/SuSE-release
  25. # Source function library.
  26. if [ -f $DEBIAN_VERSION ]; then
  27. break
  28. elif [ -f $SUSE_RELEASE -a -r /etc/rc.status ]; then
  29. . /etc/rc.status
  30. else
  31. . /etc/rc.d/init.d/functions
  32. fi
  33. # Default values (can be overridden below)
  34. SALTMINION=/usr/bin/salt-minion
  35. PYTHON=/usr/bin/python
  36. MINION_ARGS=""
  37. if [ -f /etc/default/salt ]; then
  38. . /etc/default/salt
  39. fi
  40. SERVICE=salt-minion
  41. PROCESS=salt-minion
  42. RETVAL=0
  43. WATCHDOG_CRON="/etc/cron.d/salt-minion"
  44. set_watchdog() {
  45. if [ ! -f $WATCHDOG_CRON ]; then
  46. echo -e '* * * * * root /usr/bin/salt-daemon-watcher --with-init\n' > $WATCHDOG_CRON
  47. # Kick the watcher for 1 minute immediately, because cron will wake up only afterwards
  48. /usr/bin/salt-daemon-watcher --with-init & disown
  49. fi
  50. }
  51. remove_watchdog() {
  52. rm $WATCHDOG_CRON 2>/dev/null || true
  53. kill -9 $(ps uax | grep [s]alt-daemon-watcher | awk '{print $2}') 2>/dev/null
  54. }
  55. start() {
  56. set_watchdog;
  57. echo -n $"Starting salt-minion daemon: "
  58. if [ -f $SUSE_RELEASE ]; then
  59. startproc -p /var/run/$SERVICE.pid $SALTMINION -d $MINION_ARGS
  60. rc_status -v
  61. RETVAL=$?
  62. elif [ -e $DEBIAN_VERSION ]; then
  63. if [ -f $LOCKFILE ]; then
  64. echo -n "already started, lock file found"
  65. RETVAL=1
  66. elif $PYTHON $SALTMINION -d $MINION_ARGS >& /dev/null; then
  67. echo -n "OK"
  68. RETVAL=0
  69. fi
  70. else
  71. if [[ $(pidofproc $PROCESS) ]]; then
  72. RETVAL=$?
  73. echo -n "already running"
  74. else
  75. daemon --check $SERVICE $SALTMINION -d $MINION_ARGS
  76. RETVAL=$?
  77. fi
  78. fi
  79. echo
  80. return $RETVAL
  81. }
  82. stop() {
  83. IS_RESTARTING=$1
  84. if [ -z $IS_RESTARTING ]; then
  85. remove_watchdog;
  86. fi
  87. echo -n $"Stopping salt-minion daemon: "
  88. if [ -f $SUSE_RELEASE ]; then
  89. killproc -TERM $SALTMINION
  90. rc_status -v
  91. elif [ -f $DEBIAN_VERSION ]; then
  92. # Added this since Debian's start-stop-daemon doesn't support spawned processes
  93. if ps -ef | grep "$PYTHON $SALTMINION" | grep -v grep | awk '{print $2}' | xargs kill &> /dev/null; then
  94. echo -n "OK"
  95. RETVAL=0
  96. else
  97. echo -n "Daemon is not started"
  98. RETVAL=1
  99. fi
  100. else
  101. killproc $PROCESS
  102. fi
  103. RETVAL=$?
  104. echo
  105. }
  106. restart() {
  107. stop 1;
  108. start;
  109. }
  110. # See how we were called.
  111. case "$1" in
  112. start|stop|restart)
  113. $1
  114. ;;
  115. status)
  116. if [ -f $SUSE_RELEASE ]; then
  117. echo -n "Checking for service salt-minion "
  118. checkproc $SALTMINION
  119. rc_status -v
  120. RETVAL=$?
  121. elif [ -f $DEBIAN_VERSION ]; then
  122. if [ -f $LOCKFILE ]; then
  123. RETVAL=0
  124. echo "salt-minion is running."
  125. else
  126. RETVAL=1
  127. echo "salt-minion is stopped."
  128. fi
  129. else
  130. status $PROCESS
  131. RETVAL=$?
  132. fi
  133. ;;
  134. condrestart|try-restart)
  135. [ -f $LOCKFILE ] && restart || :
  136. ;;
  137. reload)
  138. echo "can't reload configuration, you have to restart it"
  139. RETVAL=1
  140. ;;
  141. *)
  142. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
  143. exit 1
  144. ;;
  145. esac
  146. exit $RETVAL