4
0

corosync.in 3.3 KB

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