4
0

generic.in 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/bin/bash
  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. rtrn=$?
  36. if [ $rtrn -ne 0 ]; then
  37. echo "$1 is stopped"
  38. else
  39. echo "$1 (pid $pid) is running..."
  40. fi
  41. return $rtrn
  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. start()
  73. {
  74. echo -n "Starting $desc ($prog): "
  75. ! cluster_disabled_at_boot && return
  76. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  77. # to avoid to clean it up on every boot.
  78. # they also assume that init scripts will create
  79. # required subdirectories for proper operations
  80. mkdir -p @LOCALSTATEDIR@/run
  81. if status $prog > /dev/null 2>&1; then
  82. success
  83. else
  84. $prog > /dev/null 2>&1
  85. # give it time to fail
  86. sleep 2
  87. if status $prog > /dev/null 2>&1; then
  88. touch $LOCK_FILE
  89. success
  90. else
  91. failure
  92. rtrn=1
  93. fi
  94. fi
  95. echo
  96. }
  97. executed_by_cman()
  98. {
  99. [ -f @LOCALSTATEDIR@/run/cman.pid ] || return 0
  100. read cman_pid foo < @LOCALSTATEDIR@/run/cman.pid
  101. if [ "$(pidof $prog)" == "$cman_pid" ];then
  102. echo -n "$desc was executed by cman"
  103. failure
  104. echo
  105. return 1
  106. fi
  107. return 0
  108. }
  109. stop()
  110. {
  111. ! status $prog > /dev/null 2>&1 && return
  112. ! executed_by_cman && return
  113. echo -n "Signaling $desc ($prog) to terminate: "
  114. kill -TERM $(pidof $prog) > /dev/null 2>&1
  115. success
  116. echo
  117. echo -n "Waiting for $prog services to unload:"
  118. while status $prog > /dev/null 2>&1; do
  119. sleep 1
  120. echo -n "."
  121. done
  122. rm -f $LOCK_FILE
  123. success
  124. echo
  125. }
  126. restart()
  127. {
  128. stop
  129. start
  130. }
  131. rtrn=0
  132. case "$1" in
  133. start)
  134. start
  135. ;;
  136. restart|reload|force-reload)
  137. restart
  138. ;;
  139. condrestart|try-restart)
  140. if status $prog > /dev/null 2>&1; then
  141. restart
  142. fi
  143. ;;
  144. status)
  145. status $prog
  146. rtrn=$?
  147. ;;
  148. stop)
  149. stop
  150. ;;
  151. *)
  152. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  153. rtrn=2
  154. ;;
  155. esac
  156. exit $rtrn