corosync.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. prog_pid_file="@LOCALSTATEDIR@/run/$prog.pid"
  23. # set secure PATH
  24. PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
  25. success()
  26. {
  27. echo -ne "[ OK ]\r"
  28. }
  29. failure()
  30. {
  31. echo -ne "[FAILED]\r"
  32. }
  33. # pid_var_run pid_file
  34. # Echo pid from given pid_file.
  35. # Returns LSB exit code for the 'status' action.
  36. pid_var_run()
  37. {
  38. local pid_file="$1"
  39. local pid
  40. if [ -f "$pid_file" ]; then
  41. [ ! -r "$pid_file" ] && return 4
  42. pid=$(cat "$pid_file")
  43. [ -z "$pid" ] && return 1
  44. [ -n "${pid//[0-9]/}" ] && return 1
  45. if kill -n 0 "$pid" 2>/dev/null;then
  46. echo "$pid"
  47. return 0
  48. else
  49. return 1
  50. fi
  51. fi
  52. return 3
  53. }
  54. # status [-p pid_file] {program}
  55. status()
  56. {
  57. local pid_file
  58. if [ "$1" = "-p" ]; then
  59. pid_file=$2
  60. shift 2
  61. fi
  62. pid=$(pid_var_run "$pid_file" 2>/dev/null)
  63. res=$?
  64. if [ $res -ne 0 -a -z "$pid_file" ]; then
  65. pid=$(__pids_pidof "$1")
  66. [ -n "$pid" ]
  67. res=$?
  68. fi
  69. if [ $res -ne 0 ]; then
  70. echo "$1 is stopped"
  71. else
  72. echo "$1 (pid $pid) is running..."
  73. fi
  74. return $res
  75. }
  76. [ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog
  77. case '@INITCONFIGDIR@' in
  78. */sysconfig) # rpm based distros
  79. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  80. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";;
  81. */default) # deb based distros
  82. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";;
  83. esac
  84. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  85. # This means it matches scripts, including this one.
  86. # Redefine it here so that status (from the same file) works.
  87. # Otherwise simultaneous calls to stop() will loop forever
  88. __pids_pidof() {
  89. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  90. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  91. }
  92. cluster_disabled_at_boot()
  93. {
  94. if grep -q nocluster /proc/cmdline && \
  95. [ "$(tty)" = "/dev/console" ]; then
  96. echo -e "not configured to run at boot"
  97. failure
  98. return 1
  99. fi
  100. return 0
  101. }
  102. wait_for_ipc()
  103. {
  104. try=0
  105. max_try=$((COROSYNC_INIT_TIMEOUT*2-1))
  106. [ "$max_try" -le "0" ] && max_try=120
  107. while [ "$try" -le "$max_try" ]; do
  108. if corosync-cfgtool -s > /dev/null 2>&1; then
  109. return 0
  110. fi
  111. sleep 0.5
  112. try=$((try + 1))
  113. done
  114. return 1
  115. }
  116. start()
  117. {
  118. echo -n "Starting $desc ($prog): "
  119. ! cluster_disabled_at_boot && return
  120. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  121. # to avoid to clean it up on every boot.
  122. # they also assume that init scripts will create
  123. # required subdirectories for proper operations
  124. mkdir -p @LOCALSTATEDIR@/run
  125. if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
  126. success
  127. else
  128. $prog $COROSYNC_OPTIONS > /dev/null 2>&1
  129. if [ "$?" != 0 ] || ! wait_for_ipc; then
  130. failure
  131. rtrn=1
  132. else
  133. touch $LOCK_FILE
  134. success
  135. fi
  136. fi
  137. echo
  138. }
  139. stop()
  140. {
  141. ! status -p "$prog_pid_file" "$prog" > /dev/null 2>&1 && return
  142. echo -n "Signaling $desc ($prog) to terminate: "
  143. kill -TERM "$(pid_var_run $prog_pid_file)" > /dev/null 2>&1
  144. success
  145. echo
  146. echo -n "Waiting for $prog services to unload:"
  147. while status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; do
  148. sleep 1
  149. echo -n "."
  150. done
  151. rm -f $LOCK_FILE
  152. success
  153. echo
  154. }
  155. restart()
  156. {
  157. stop
  158. start
  159. }
  160. rtrn=0
  161. case "$1" in
  162. start)
  163. start
  164. ;;
  165. restart|reload|force-reload)
  166. restart
  167. ;;
  168. condrestart|try-restart)
  169. if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
  170. restart
  171. fi
  172. ;;
  173. status)
  174. status -p "$prog_pid_file" "$prog"
  175. rtrn=$?
  176. ;;
  177. stop)
  178. stop
  179. ;;
  180. *)
  181. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  182. rtrn=2
  183. ;;
  184. esac
  185. exit $rtrn