ldap-agent-initscript.in 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/bin/sh
  2. #
  3. # @package_name@-snmp This starts and stops @package_name@-snmp
  4. #
  5. # chkconfig: - 22 78
  6. # description: @capbrand@ Directory Server SNMP Subagent
  7. # processname: ldap-agent-bin
  8. # config: @sysconfdir@/@package_name@/config/ldap-agent.conf
  9. # pidfile: @localstatedir@/run/ldap-agent.pid
  10. #
  11. # Source function library.
  12. if [ -f /etc/rc.d/init.d/functions ] ; then
  13. . /etc/rc.d/init.d/functions
  14. fi
  15. # Source networking configuration.
  16. if [ -f /etc/sysconfig/network ] ; then
  17. . /etc/sysconfig/network
  18. fi
  19. # Check that networking is up.
  20. if [ "${NETWORKING}" = "no" ]
  21. then
  22. echo "Networking is down"
  23. if [ "$1" = "status" ]; then
  24. # exit code 4 means unknown status for status action
  25. exit 4
  26. else
  27. # exit code 1 means unspecified error for non-status actions
  28. exit 1
  29. fi
  30. fi
  31. echo_n()
  32. {
  33. printf '%s' "$*"
  34. }
  35. # failure and success are not defined on some platforms
  36. which failure > /dev/null 2>&1 || {
  37. failure()
  38. {
  39. echo_n " FAILED"
  40. }
  41. }
  42. which success > /dev/null 2>&1 || {
  43. success()
  44. {
  45. echo_n " SUCCESS"
  46. }
  47. }
  48. baseexec="ldap-agent"
  49. exec="@sbindir@/$baseexec"
  50. processname="ldap-agent-bin"
  51. prog="@package_name@-snmp"
  52. pidfile="@localstatedir@/run/ldap-agent.pid"
  53. configfile="@sysconfdir@/@package_name@/config/ldap-agent.conf"
  54. # Check if ldap-agent exists
  55. if [ ! -f $exec ]; then
  56. if [ "$1" = "status" ]; then
  57. # exit code 4 means unknown status for status action
  58. exit 4
  59. else
  60. # exit code 5 means program is not installed for non-status actions
  61. exit 5
  62. fi
  63. fi
  64. umask 077
  65. start() {
  66. echo_n "Starting $prog: "
  67. ret=0
  68. subagent_running=0
  69. subagent_started=0
  70. # the subagent creates a pidfile and writes
  71. # the pid to it when it is fully started.
  72. if [ -f $pidfile ]; then
  73. pid=`cat $pidfile`
  74. name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
  75. if kill -s 0 $pid && [ $name = "$processname" ]; then
  76. echo_n " already running"
  77. success; echo
  78. subagent_running=1
  79. else
  80. echo " not running, but pid file exists"
  81. echo_n " ... attempting to start anyway"
  82. fi
  83. fi
  84. if [ $subagent_running -eq 0 ] ; then
  85. rm -f $pidfile
  86. $exec $configfile > /dev/null 2>&1
  87. if [ $? -eq 0 ]; then
  88. subagent_started=1 # well, perhaps not running, but started ok
  89. else
  90. failure; echo
  91. ret=1
  92. fi
  93. fi
  94. # ok, if we started the subagent successfully, let's see
  95. # if it is really running and ready to serve requests.
  96. if [ $subagent_started -eq 1 ] ; then
  97. loop_counter=1
  98. # wait for 10 seconds
  99. max_count=10
  100. while test $loop_counter -le $max_count ; do
  101. loop_counter=`expr $loop_counter + 1`
  102. if test ! -f $pidfile ; then
  103. if kill -s 0 $pid > /dev/null 2>&1 ; then
  104. sleep 1
  105. else
  106. break
  107. fi
  108. else
  109. pid=`cat $pidfile`
  110. break
  111. fi
  112. done
  113. if kill -s 0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
  114. success; echo
  115. else
  116. failure; echo
  117. ret=1
  118. fi
  119. fi
  120. exit $ret
  121. }
  122. stop() {
  123. echo_n "Shutting down $prog: "
  124. if [ -f $pidfile ]; then
  125. pid=`cat $pidfile`
  126. subagent_stopped=0
  127. if kill -s 0 $pid > /dev/null 2>&1 ; then
  128. kill $pid
  129. if [ $? -eq 0 ]; then
  130. subagent_stopped=1
  131. else
  132. failure; echo
  133. fi
  134. else
  135. echo_n " subagent not running"
  136. failure; echo
  137. fi
  138. if [ $subagent_stopped -eq 1 ] ; then
  139. loop_counter=1
  140. # wait for 10 seconds
  141. max_count=10
  142. while test $loop_counter -le $max_count; do
  143. loop_counter=`expr $loop_counter + 1`
  144. if kill -s 0 $pid > /dev/null 2>&1 ; then
  145. sleep 1
  146. else
  147. if test -f $pidfile ; then
  148. rm -f $pidfile
  149. fi
  150. break
  151. fi
  152. done
  153. if test -f $pidfile ; then
  154. failure; echo
  155. else
  156. success; echo
  157. rm -f $pidfile
  158. fi
  159. fi
  160. else
  161. echo_n " subagent already stopped"
  162. failure; echo
  163. fi
  164. }
  165. reload() {
  166. stop
  167. start
  168. }
  169. restart() {
  170. stop
  171. start
  172. }
  173. condrestart() {
  174. if [ -f $pidfile ]; then
  175. pid=`cat $pidfile`
  176. name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
  177. if kill -s 0 $pid && [ $name = "$processname" ]; then
  178. restart
  179. fi
  180. fi
  181. }
  182. status() {
  183. ret=0
  184. if [ -f $pidfile ]; then
  185. pid=`cat $pidfile`
  186. if kill -s 0 $pid > /dev/null 2>&1 ; then
  187. echo "$prog (pid $pid) is running..."
  188. else
  189. echo "$prog dead but pid file exists"
  190. ret=1
  191. fi
  192. else
  193. echo "$prog is stopped"
  194. ret=3
  195. fi
  196. exit $ret
  197. }
  198. case "$1" in
  199. start|stop|restart|reload|condrestart|status)
  200. $1
  201. ;;
  202. *)
  203. echo Unknown command $1
  204. echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"
  205. exit 2
  206. esac