generic.in 3.1 KB

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