salt-master 3.2 KB

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