corosync-qdevice.in 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. prog_pid_file="@LOCALSTATEDIR@/run/corosync-qdevice/$prog.pid"
  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. # pid_var_run pid_file
  33. # Echo pid from given pid_file.
  34. # Returns LSB exit code for the 'status' action.
  35. pid_var_run()
  36. {
  37. local pid_file="$1"
  38. local pid
  39. if [ -f "$pid_file" ]; then
  40. [ ! -r "$pid_file" ] && return 4
  41. pid=$(cat "$pid_file")
  42. [ -z "$pid" ] && return 1
  43. [ -n "${pid//[0-9]/}" ] && return 1
  44. if kill -n 0 "$pid" 2>/dev/null;then
  45. echo "$pid"
  46. return 0
  47. else
  48. return 1
  49. fi
  50. fi
  51. return 3
  52. }
  53. # status [-p pid_file] {program}
  54. status()
  55. {
  56. local pid_file
  57. if [ "$1" = "-p" ]; then
  58. pid_file=$2
  59. shift 2
  60. fi
  61. pid=$(pid_var_run "$pid_file" 2>/dev/null)
  62. res=$?
  63. if [ $res -ne 0 -a -z "$pid_file" ]; then
  64. pid=$(__pids_pidof "$1")
  65. [ -n "$pid" ]
  66. res=$?
  67. fi
  68. if [ $res -ne 0 ]; then
  69. echo "$1 is stopped"
  70. else
  71. echo "$1 (pid $pid) is running..."
  72. fi
  73. return $res
  74. }
  75. [ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog
  76. case '@INITCONFIGDIR@' in
  77. */sysconfig) # rpm based distros
  78. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  79. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";;
  80. */default) # deb based distros
  81. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";;
  82. esac
  83. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  84. # This means it matches scripts, including this one.
  85. # Redefine it here so that status (from the same file) works.
  86. # Otherwise simultaneous calls to stop() will loop forever
  87. __pids_pidof() {
  88. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  89. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  90. }
  91. cluster_disabled_at_boot()
  92. {
  93. if grep -q nocluster /proc/cmdline && \
  94. [ "$(tty)" = "/dev/console" ]; then
  95. echo -e "not configured to run at boot"
  96. failure
  97. return 1
  98. fi
  99. return 0
  100. }
  101. start()
  102. {
  103. echo -n "Starting $desc ($prog): "
  104. ! cluster_disabled_at_boot && return
  105. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  106. # to avoid to clean it up on every boot.
  107. # they also assume that init scripts will create
  108. # required subdirectories for proper operations
  109. if [ ! -d "@LOCALSTATEDIR@/run/corosync-qdevice" ];then
  110. mkdir -p "@LOCALSTATEDIR@/run/corosync-qdevice"
  111. chmod 0770 "@LOCALSTATEDIR@/run/corosync-qdevice"
  112. fi
  113. if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
  114. success
  115. else
  116. $prog $COROSYNC_QDEVICE_OPTIONS > /dev/null 2>&1
  117. if [ "$?" != 0 ]; then
  118. failure
  119. rtrn=1
  120. else
  121. touch $LOCK_FILE
  122. success
  123. fi
  124. fi
  125. echo
  126. }
  127. stop()
  128. {
  129. ! status -p "$prog_pid_file" "$prog" > /dev/null 2>&1 && return
  130. echo -n "Signaling $desc ($prog) to terminate: "
  131. kill -TERM "$(pid_var_run $prog_pid_file)" > /dev/null 2>&1
  132. success
  133. echo
  134. echo -n "Waiting for $prog services to unload:"
  135. while status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; do
  136. sleep 1
  137. echo -n "."
  138. done
  139. rm -f $LOCK_FILE
  140. success
  141. echo
  142. }
  143. restart()
  144. {
  145. stop
  146. start
  147. }
  148. rtrn=0
  149. case "$1" in
  150. start)
  151. start
  152. ;;
  153. restart|reload|force-reload)
  154. restart
  155. ;;
  156. condrestart|try-restart)
  157. if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then
  158. restart
  159. fi
  160. ;;
  161. status)
  162. status -p "$prog_pid_file" "$prog"
  163. rtrn=$?
  164. ;;
  165. stop)
  166. stop
  167. ;;
  168. *)
  169. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  170. rtrn=2
  171. ;;
  172. esac
  173. exit $rtrn