corosync-qdevice.in 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!@BASHPATH@
  2. # Authors:
  3. # Jan Friesse <jfriesse@redhat.com>
  4. #
  5. # License: Revised BSD
  6. # chkconfig: - 20 80
  7. # description: Corosync Qdevice daemon
  8. # processname: corosync-qdevice
  9. #
  10. ### BEGIN INIT INFO
  11. # Provides: corosync-qdevice
  12. # Required-Start: corosync
  13. # Required-Stop: corosync
  14. # Default-Start:
  15. # Default-Stop:
  16. # Short-Description: Starts and stops Corosync Qdevice daemon.
  17. # Description: Starts and stops Corosync Qdevice daemon.
  18. ### END INIT INFO
  19. desc="Corosync Qdevice daemon"
  20. prog="corosync-qdevice"
  21. # set secure PATH
  22. PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@"
  23. success()
  24. {
  25. echo -ne "[ OK ]\r"
  26. }
  27. failure()
  28. {
  29. echo -ne "[FAILED]\r"
  30. }
  31. status()
  32. {
  33. pid=$(pidof $1 2>/dev/null)
  34. res=$?
  35. if [ $res -ne 0 ]; then
  36. echo "$1 is stopped"
  37. else
  38. echo "$1 (pid $pid) is running..."
  39. fi
  40. return $res
  41. }
  42. [ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog
  43. case '@INITCONFIGDIR@' in
  44. */sysconfig) # rpm based distros
  45. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  46. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";;
  47. */default) # deb based distros
  48. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";;
  49. esac
  50. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  51. # This means it matches scripts, including this one.
  52. # Redefine it here so that status (from the same file) works.
  53. # Otherwise simultaneous calls to stop() will loop forever
  54. __pids_pidof() {
  55. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  56. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  57. }
  58. cluster_disabled_at_boot()
  59. {
  60. if grep -q nocluster /proc/cmdline && \
  61. [ "$(tty)" = "/dev/console" ]; then
  62. echo -e "not configured to run at boot"
  63. failure
  64. return 1
  65. fi
  66. return 0
  67. }
  68. start()
  69. {
  70. echo -n "Starting $desc ($prog): "
  71. ! cluster_disabled_at_boot && return
  72. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  73. # to avoid to clean it up on every boot.
  74. # they also assume that init scripts will create
  75. # required subdirectories for proper operations
  76. if [ ! -d "@LOCALSTATEDIR@/run/corosync-qdevice" ];then
  77. mkdir -p "@LOCALSTATEDIR@/run/corosync-qdevice"
  78. chmod 0770 "@LOCALSTATEDIR@/run/corosync-qdevice"
  79. fi
  80. if status $prog > /dev/null 2>&1; then
  81. success
  82. else
  83. $prog $COROSYNC_QDEVICE_OPTIONS > /dev/null 2>&1
  84. if [ "$?" != 0 ]; then
  85. failure
  86. rtrn=1
  87. else
  88. touch $LOCK_FILE
  89. success
  90. fi
  91. fi
  92. echo
  93. }
  94. stop()
  95. {
  96. ! status $prog > /dev/null 2>&1 && return
  97. echo -n "Signaling $desc ($prog) to terminate: "
  98. kill -TERM $(pidof $prog) > /dev/null 2>&1
  99. success
  100. echo
  101. echo -n "Waiting for $prog services to unload:"
  102. while status $prog > /dev/null 2>&1; do
  103. sleep 1
  104. echo -n "."
  105. done
  106. rm -f $LOCK_FILE
  107. success
  108. echo
  109. }
  110. restart()
  111. {
  112. stop
  113. start
  114. }
  115. rtrn=0
  116. case "$1" in
  117. start)
  118. start
  119. ;;
  120. restart|reload|force-reload)
  121. restart
  122. ;;
  123. condrestart|try-restart)
  124. if status $prog > /dev/null 2>&1; then
  125. restart
  126. fi
  127. ;;
  128. status)
  129. status $prog
  130. rtrn=$?
  131. ;;
  132. stop)
  133. stop
  134. ;;
  135. *)
  136. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  137. rtrn=2
  138. ;;
  139. esac
  140. exit $rtrn