ldap-agent-initscript.in 5.4 KB

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