corosync-qnetd.in 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!@BASHPATH@
  2. # Authors:
  3. # Jan Friesse <jfriesse@redhat.com>
  4. #
  5. # License: Revised BSD
  6. # chkconfig: - 20 80
  7. # description: Corosync Qdevice Network daemon
  8. # processname: corosync-qnetd
  9. #
  10. ### BEGIN INIT INFO
  11. # Provides: corosync-qnetd
  12. # Required-Start: $network $syslog
  13. # Required-Stop: $network $syslog
  14. # Default-Start:
  15. # Default-Stop:
  16. # Short-Description: Starts and stops Corosync Qdevice Network daemon.
  17. # Description: Starts and stops Corosync Qdevice Network daemon.
  18. ### END INIT INFO
  19. desc="Corosync Qdevice Network daemon"
  20. prog="corosync-qnetd"
  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-qnetd" ];then
  77. mkdir -p "@LOCALSTATEDIR@/run/corosync-qnetd"
  78. chmod 0770 "@LOCALSTATEDIR@/run/corosync-qnetd"
  79. if [ ! -z "$COROSYNC_QNETD_RUNAS" ];then
  80. chown "$COROSYNC_QNETD_RUNAS:$COROSYNC_QNETD_RUNAS" "@LOCALSTATEDIR@/run/corosync-qnetd"
  81. fi
  82. fi
  83. if status $prog > /dev/null 2>&1; then
  84. success
  85. else
  86. if [ -z "$COROSYNC_QNETD_RUNAS" ];then
  87. $prog $COROSYNC_QNETD_OPTIONS > /dev/null 2>&1
  88. else
  89. runuser -s @BASHPATH@ $COROSYNC_QNETD_RUNAS -c "$prog $COROSYNC_QNETD_OPTIONS > /dev/null 2>&1"
  90. fi
  91. if [ "$?" != 0 ]; then
  92. failure
  93. rtrn=1
  94. else
  95. touch $LOCK_FILE
  96. success
  97. fi
  98. fi
  99. echo
  100. }
  101. stop()
  102. {
  103. ! status $prog > /dev/null 2>&1 && return
  104. echo -n "Signaling $desc ($prog) to terminate: "
  105. kill -TERM "$(pidof $prog)" > /dev/null 2>&1
  106. success
  107. echo
  108. echo -n "Waiting for $prog services to unload:"
  109. while status $prog > /dev/null 2>&1; do
  110. sleep 1
  111. echo -n "."
  112. done
  113. rm -f $LOCK_FILE
  114. success
  115. echo
  116. }
  117. restart()
  118. {
  119. stop
  120. start
  121. }
  122. rtrn=0
  123. case "$1" in
  124. start)
  125. start
  126. ;;
  127. restart|reload|force-reload)
  128. restart
  129. ;;
  130. condrestart|try-restart)
  131. if status $prog > /dev/null 2>&1; then
  132. restart
  133. fi
  134. ;;
  135. status)
  136. status $prog
  137. rtrn=$?
  138. ;;
  139. stop)
  140. stop
  141. ;;
  142. *)
  143. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  144. rtrn=2
  145. ;;
  146. esac
  147. exit $rtrn