generic.in 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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
  14. # Should-Start: $syslog
  15. # Required-Stop: $network
  16. # Default-Start:
  17. # Default-Stop:
  18. # Short-Description: Starts and stops Corosync Cluster Engine.
  19. # Description: Starts and stops Corosync Cluster Engine.
  20. ### END INIT INFO
  21. desc="Corosync Cluster Engine"
  22. prog="corosync"
  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. status()
  34. {
  35. pid=$(pidof $1 2>/dev/null)
  36. rtrn=$?
  37. if [ $rtrn -ne 0 ]; then
  38. echo "$1 is stopped"
  39. else
  40. echo "$1 (pid $pid) is running..."
  41. fi
  42. return $rtrn
  43. }
  44. # rpm based distros
  45. if [ -d @SYSCONFDIR@/sysconfig ]; then
  46. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  47. [ -f @SYSCONFDIR@/sysconfig/$prog ] && . @SYSCONFDIR@/sysconfig/$prog
  48. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog"
  49. fi
  50. # deb based distros
  51. if [ -d @SYSCONFDIR@/default ]; then
  52. [ -f @SYSCONFDIR@/default/$prog ] && . @SYSCONFDIR@/default/$prog
  53. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog"
  54. fi
  55. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  56. # This means it matches scripts, including this one.
  57. # Redefine it here so that status (from the same file) works.
  58. # Otherwise simultaneous calls to stop() will loop forever
  59. __pids_pidof() {
  60. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  61. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  62. }
  63. start()
  64. {
  65. echo -n "Starting $desc ($prog): "
  66. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  67. # to avoid to clean it up on every boot.
  68. # they also assume that init scripts will create
  69. # required subdirectories for proper operations
  70. mkdir -p @LOCALSTATEDIR@/run
  71. if status $prog > /dev/null 2>&1; then
  72. success
  73. else
  74. $prog > /dev/null 2>&1
  75. # give it time to fail
  76. sleep 2
  77. if status $prog > /dev/null 2>&1; then
  78. touch $LOCK_FILE
  79. success
  80. else
  81. failure
  82. rtrn=1
  83. fi
  84. fi
  85. echo
  86. }
  87. executed_by_cman()
  88. {
  89. [ -f @LOCALSTATEDIR@/run/cman.pid ] || return 0
  90. read cman_pid foo < @LOCALSTATEDIR@/run/cman.pid
  91. if [ "$(pidof $prog)" == "$cman_pid" ];then
  92. echo -n "$desc was executed by cman"
  93. failure
  94. echo
  95. return 1
  96. fi
  97. return 0
  98. }
  99. stop()
  100. {
  101. ! status $prog > /dev/null 2>&1 && return
  102. ! executed_by_cman && return
  103. echo -n "Signaling $desc ($prog) to terminate: "
  104. kill -TERM $(pidof $prog) > /dev/null 2>&1
  105. success
  106. echo
  107. echo -n "Waiting for $prog services to unload:"
  108. while status $prog > /dev/null 2>&1; do
  109. sleep 1
  110. echo -n "."
  111. done
  112. rm -f $LOCK_FILE
  113. success
  114. echo
  115. }
  116. restart()
  117. {
  118. stop
  119. start
  120. }
  121. rtrn=0
  122. case "$1" in
  123. start)
  124. start
  125. ;;
  126. restart|reload|force-reload)
  127. restart
  128. ;;
  129. condrestart|try-restart)
  130. if status $prog > /dev/null 2>&1; then
  131. restart
  132. fi
  133. ;;
  134. status)
  135. status $prog
  136. rtrn=$?
  137. ;;
  138. stop)
  139. stop
  140. ;;
  141. *)
  142. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  143. rtrn=2
  144. ;;
  145. esac
  146. exit $rtrn