corosync.in 3.2 KB

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