salt-master 3.2 KB

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