generic.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 20
  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. stop()
  88. {
  89. ! status $prog > /dev/null 2>&1 && return
  90. echo -n "Signaling $desc ($prog) to terminate: "
  91. kill -TERM $(pidof $prog) > /dev/null 2>&1
  92. success
  93. echo
  94. echo -n "Waiting for $prog services to unload:"
  95. while status $prog > /dev/null 2>&1; do
  96. sleep 1
  97. echo -n "."
  98. done
  99. rm -f $LOCK_FILE
  100. success
  101. echo
  102. }
  103. restart()
  104. {
  105. stop
  106. start
  107. }
  108. rtrn=0
  109. case "$1" in
  110. start)
  111. start
  112. ;;
  113. restart|reload|force-reload)
  114. restart
  115. ;;
  116. condrestart|try-restart)
  117. if status $prog > /dev/null 2>&1; then
  118. restart
  119. fi
  120. ;;
  121. status)
  122. status $prog
  123. rtrn=$?
  124. ;;
  125. stop)
  126. stop
  127. ;;
  128. *)
  129. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  130. rtrn=2
  131. ;;
  132. esac
  133. exit $rtrn