corosync-notifyd.in 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!@BASHPATH@
  2. # Authors:
  3. # Angus Salkeld <asalkeld@redhat.com>
  4. #
  5. # License: Revised BSD
  6. # chkconfig: - 23 77
  7. # description: Corosync Dbus and snmp notifier
  8. # processname: corosync-notifyd
  9. #
  10. ### BEGIN INIT INFO
  11. # Provides: corosync-notifyd
  12. # Required-Start: corosync cman
  13. # Required-Stop: corosync cman
  14. # Default-Start:
  15. # Default-Stop:
  16. # Short-Description: Starts and stops Corosync Notifier.
  17. # Description: Starts and stops Corosync Notifier.
  18. ### END INIT INFO
  19. desc="Corosync Notifier"
  20. prog="corosync-notifyd"
  21. # set secure PATH
  22. PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
  23. success()
  24. {
  25. echo -ne "[ OK ]\r"
  26. }
  27. failure()
  28. {
  29. echo -ne "[FAILED]\r"
  30. }
  31. status()
  32. {
  33. pid=$(pidof $1 2>/dev/null)
  34. rtrn=$?
  35. if [ $rtrn -ne 0 ]; then
  36. echo "$1 is stopped"
  37. else
  38. echo "$1 (pid $pid) is running..."
  39. fi
  40. return $rtrn
  41. }
  42. [ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog
  43. case '@INITCONFIGDIR@' in
  44. */sysconfig) # rpm based distros
  45. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  46. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";;
  47. */default) # deb based distros
  48. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";;
  49. esac
  50. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  51. # This means it matches scripts, including this one.
  52. # Redefine it here so that status (from the same file) works.
  53. # Otherwise simultaneous calls to stop() will loop forever
  54. __pids_pidof() {
  55. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  56. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  57. }
  58. start()
  59. {
  60. echo -n "Starting $desc ($prog): "
  61. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  62. # to avoid to clean it up on every boot.
  63. # they also assume that init scripts will create
  64. # required subdirectories for proper operations
  65. mkdir -p @LOCALSTATEDIR@/run
  66. if status $prog > /dev/null 2>&1; then
  67. success
  68. else
  69. $prog $OPTIONS > /dev/null 2>&1
  70. # give it time to fail
  71. sleep 2
  72. if status $prog > /dev/null 2>&1; then
  73. touch $LOCK_FILE
  74. success
  75. else
  76. failure
  77. rtrn=1
  78. fi
  79. fi
  80. echo
  81. }
  82. stop()
  83. {
  84. ! status $prog > /dev/null 2>&1 && return
  85. echo -n "Signaling $desc ($prog) to terminate: "
  86. kill -TERM "$(pidof $prog)" > /dev/null 2>&1
  87. success
  88. echo
  89. echo -n "Waiting for $prog services to unload:"
  90. while status $prog > /dev/null 2>&1; do
  91. sleep 1
  92. echo -n "."
  93. done
  94. rm -f $LOCK_FILE
  95. success
  96. echo
  97. }
  98. restart()
  99. {
  100. stop
  101. start
  102. }
  103. rtrn=0
  104. case "$1" in
  105. start)
  106. start
  107. ;;
  108. restart|reload|force-reload)
  109. restart
  110. ;;
  111. condrestart|try-restart)
  112. if status $prog > /dev/null 2>&1; then
  113. restart
  114. fi
  115. ;;
  116. status)
  117. status $prog
  118. rtrn=$?
  119. ;;
  120. stop)
  121. stop
  122. ;;
  123. *)
  124. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  125. rtrn=2
  126. ;;
  127. esac
  128. exit $rtrn