4
0

corosync-notifyd.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # rpm based distros
  43. if [ -d @SYSCONFDIR@/sysconfig ]; then
  44. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  45. [ -f @SYSCONFDIR@/sysconfig/$prog ] && . @SYSCONFDIR@/sysconfig/$prog
  46. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog"
  47. fi
  48. # deb based distros
  49. if [ -d @SYSCONFDIR@/default ]; then
  50. [ -f @SYSCONFDIR@/default/$prog ] && . @SYSCONFDIR@/default/$prog
  51. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog"
  52. fi
  53. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  54. # This means it matches scripts, including this one.
  55. # Redefine it here so that status (from the same file) works.
  56. # Otherwise simultaneous calls to stop() will loop forever
  57. __pids_pidof() {
  58. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  59. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  60. }
  61. start()
  62. {
  63. echo -n "Starting $desc ($prog): "
  64. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  65. # to avoid to clean it up on every boot.
  66. # they also assume that init scripts will create
  67. # required subdirectories for proper operations
  68. mkdir -p @LOCALSTATEDIR@/run
  69. if status $prog > /dev/null 2>&1; then
  70. success
  71. else
  72. $prog $OPTIONS > /dev/null 2>&1
  73. # give it time to fail
  74. sleep 2
  75. if status $prog > /dev/null 2>&1; then
  76. touch $LOCK_FILE
  77. success
  78. else
  79. failure
  80. rtrn=1
  81. fi
  82. fi
  83. echo
  84. }
  85. stop()
  86. {
  87. ! status $prog > /dev/null 2>&1 && return
  88. echo -n "Signaling $desc ($prog) to terminate: "
  89. kill -TERM $(pidof $prog) > /dev/null 2>&1
  90. success
  91. echo
  92. echo -n "Waiting for $prog services to unload:"
  93. while status $prog > /dev/null 2>&1; do
  94. sleep 1
  95. echo -n "."
  96. done
  97. rm -f $LOCK_FILE
  98. success
  99. echo
  100. }
  101. restart()
  102. {
  103. stop
  104. start
  105. }
  106. rtrn=0
  107. case "$1" in
  108. start)
  109. start
  110. ;;
  111. restart|reload|force-reload)
  112. restart
  113. ;;
  114. condrestart|try-restart)
  115. if status $prog > /dev/null 2>&1; then
  116. restart
  117. fi
  118. ;;
  119. status)
  120. status $prog
  121. rtrn=$?
  122. ;;
  123. stop)
  124. stop
  125. ;;
  126. *)
  127. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  128. rtrn=2
  129. ;;
  130. esac
  131. exit $rtrn