ldap-agent-initscript.in 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. exit 0
  24. fi
  25. # figure out which echo we're using
  26. ECHO_N=`echo -n`
  27. # some shells echo cannot use -n - linux echo by default cannot use \c
  28. echo_n()
  29. {
  30. if [ "$ECHO_N" = '-n' ] ; then
  31. echo "$*\c"
  32. else
  33. echo -n "$*"
  34. fi
  35. }
  36. # failure and success are not defined on some platforms
  37. type failure > /dev/null 2>&1 || {
  38. failure()
  39. {
  40. echo_n " FAILED"
  41. }
  42. }
  43. type success > /dev/null 2>&1 || {
  44. success()
  45. {
  46. echo_n " SUCCESS"
  47. }
  48. }
  49. baseexec="ldap-agent"
  50. exec="@sbindir@/$baseexec"
  51. processname="ldap-agent-bin"
  52. prog="@package_name@-snmp"
  53. pidfile="@localstatedir@/run/ldap-agent.pid"
  54. configfile="@sysconfdir@/@package_name@/config/ldap-agent.conf"
  55. [ -f $exec ] || exit 0
  56. umask 077
  57. start() {
  58. echo_n "Starting $prog: "
  59. ret=0
  60. subagent_running=0
  61. subagent_started=0
  62. # the subagent creates a pidfile and writes
  63. # the pid to it when it is fully started.
  64. if [ -f $pidfile ]; then
  65. pid=`cat $pidfile`
  66. name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
  67. if kill -0 $pid && [ $name = "$processname" ]; then
  68. echo_n " already running"
  69. success; echo
  70. subagent_running=1
  71. else
  72. echo " not running, but pid file exists"
  73. echo_n " ... attempting to start anyway"
  74. fi
  75. fi
  76. if [ $subagent_running -eq 0 ] ; then
  77. rm -f $pidfile
  78. $exec $configfile > /dev/null 2>&1
  79. if [ $? -eq 0 ]; then
  80. subagent_started=1 # well, perhaps not running, but started ok
  81. else
  82. failure; echo
  83. ret=1
  84. fi
  85. fi
  86. # ok, if we started the subagent successfully, let's see
  87. # if it is really running and ready to serve requests.
  88. if [ $subagent_started -eq 1 ] ; then
  89. loop_counter=1
  90. # wait for 10 seconds
  91. max_count=10
  92. while test $loop_counter -le $max_count ; do
  93. loop_counter=`expr $loop_counter + 1`
  94. if test ! -f $pidfile ; then
  95. if kill -0 $pid > /dev/null 2>&1 ; then
  96. sleep 1
  97. else
  98. break
  99. fi
  100. else
  101. pid=`cat $pidfile`
  102. break
  103. fi
  104. done
  105. if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
  106. success; echo
  107. else
  108. failure; echo
  109. ret=1
  110. fi
  111. fi
  112. exit $ret
  113. }
  114. stop() {
  115. echo_n "Shutting down $prog: "
  116. if [ -f $pidfile ]; then
  117. pid=`cat $pidfile`
  118. subagent_stopped=0
  119. if kill -0 $pid > /dev/null 2>&1 ; then
  120. kill $pid
  121. if [ $? -eq 0 ]; then
  122. subagent_stopped=1
  123. else
  124. failure; echo
  125. fi
  126. else
  127. echo_n " subagent not running"
  128. failure; echo
  129. fi
  130. if [ $subagent_stopped -eq 1 ] ; then
  131. loop_counter=1
  132. # wait for 10 seconds
  133. max_count=10
  134. while test $loop_counter -le $max_count; do
  135. loop_counter=`expr $loop_counter + 1`
  136. if kill -0 $pid > /dev/null 2>&1 ; then
  137. sleep 1
  138. else
  139. if test -f $pidfile ; then
  140. rm -f $pidfile
  141. fi
  142. break
  143. fi
  144. done
  145. if test -f $pidfile ; then
  146. failure; echo
  147. else
  148. success; echo
  149. rm -f $pidfile
  150. fi
  151. fi
  152. else
  153. echo_n " subagent already stopped"
  154. failure; echo
  155. fi
  156. }
  157. reload() {
  158. stop
  159. start
  160. }
  161. restart() {
  162. stop
  163. start
  164. }
  165. condrestart() {
  166. if [ -f $pidfile ]; then
  167. pid=`cat $pidfile`
  168. name=`ps -p $pid | tail -1 | awk '{ print $4 }'`
  169. if kill -0 $pid && [ $name = "$processname" ]; then
  170. restart
  171. fi
  172. fi
  173. }
  174. status() {
  175. ret=0
  176. if [ -f $pidfile ]; then
  177. pid=`cat $pidfile`
  178. if kill -0 $pid > /dev/null 2>&1 ; then
  179. echo "$prog (pid $pid) is running..."
  180. else
  181. echo "$prog dead but pid file exists"
  182. ret=1
  183. fi
  184. else
  185. echo "$prog is stopped"
  186. ret=3
  187. fi
  188. exit $ret
  189. }
  190. case "$1" in
  191. start|stop|restart|reload|condrestart|status)
  192. $1
  193. ;;
  194. *)
  195. echo Unknown command $1
  196. echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"
  197. exit 2
  198. esac