salt-api 3.6 KB

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