corosync-qnetd.in 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. # rpm based distros
  43. if [ -d @SYSCONFDIR@/sysconfig ]; then
  44. [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions
  45. [ -f @SYSCONFDIR@/sysconfig/$prog ] && . @SYSCONFDIR@/sysconfig/$prog
  46. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog"
  47. fi
  48. # deb based distros
  49. if [ -d @SYSCONFDIR@/default ]; then
  50. [ -f @SYSCONFDIR@/default/$prog ] && . @SYSCONFDIR@/default/$prog
  51. [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog"
  52. fi
  53. # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x
  54. # This means it matches scripts, including this one.
  55. # Redefine it here so that status (from the same file) works.
  56. # Otherwise simultaneous calls to stop() will loop forever
  57. __pids_pidof() {
  58. pidof -c -o $$ -o $PPID -o %PPID "$1" || \
  59. pidof -c -o $$ -o $PPID -o %PPID "${1##*/}"
  60. }
  61. cluster_disabled_at_boot()
  62. {
  63. if grep -q nocluster /proc/cmdline && \
  64. [ "$(tty)" = "/dev/console" ]; then
  65. echo -e "not configured to run at boot"
  66. failure
  67. return 1
  68. fi
  69. return 0
  70. }
  71. start()
  72. {
  73. echo -n "Starting $desc ($prog): "
  74. ! cluster_disabled_at_boot && return
  75. # most recent distributions use tmpfs for @LOCALSTATEDIR@/run
  76. # to avoid to clean it up on every boot.
  77. # they also assume that init scripts will create
  78. # required subdirectories for proper operations
  79. if [ ! -d "@LOCALSTATEDIR@/run/corosync-qnetd" ];then
  80. mkdir -p "@LOCALSTATEDIR@/run/corosync-qnetd"
  81. chmod 0770 "@LOCALSTATEDIR@/run/corosync-qnetd"
  82. if [ ! -z "$COROSYNC_QNETD_RUNAS" ];then
  83. chown "$COROSYNC_QNETD_RUNAS:$COROSYNC_QNETD_RUNAS" "@LOCALSTATEDIR@/run/corosync-qnetd"
  84. fi
  85. fi
  86. if status $prog > /dev/null 2>&1; then
  87. success
  88. else
  89. if [ -z "$COROSYNC_QNETD_RUNAS" ];then
  90. $prog $COROSYNC_QNETD_OPTIONS > /dev/null 2>&1
  91. else
  92. runuser -s @BASHPATH@ $COROSYNC_QNETD_RUNAS -c "$prog $COROSYNC_QNETD_OPTIONS > /dev/null 2>&1"
  93. fi
  94. if [ "$?" != 0 ]; then
  95. failure
  96. rtrn=1
  97. else
  98. touch $LOCK_FILE
  99. success
  100. fi
  101. fi
  102. echo
  103. }
  104. stop()
  105. {
  106. ! status $prog > /dev/null 2>&1 && return
  107. echo -n "Signaling $desc ($prog) to terminate: "
  108. kill -TERM $(pidof $prog) > /dev/null 2>&1
  109. success
  110. echo
  111. echo -n "Waiting for $prog services to unload:"
  112. while status $prog > /dev/null 2>&1; do
  113. sleep 1
  114. echo -n "."
  115. done
  116. rm -f $LOCK_FILE
  117. success
  118. echo
  119. }
  120. restart()
  121. {
  122. stop
  123. start
  124. }
  125. rtrn=0
  126. case "$1" in
  127. start)
  128. start
  129. ;;
  130. restart|reload|force-reload)
  131. restart
  132. ;;
  133. condrestart|try-restart)
  134. if status $prog > /dev/null 2>&1; then
  135. restart
  136. fi
  137. ;;
  138. status)
  139. status $prog
  140. rtrn=$?
  141. ;;
  142. stop)
  143. stop
  144. ;;
  145. *)
  146. echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}"
  147. rtrn=2
  148. ;;
  149. esac
  150. exit $rtrn