forked from pool/sanlock
161 lines
4.2 KiB
Plaintext
161 lines
4.2 KiB
Plaintext
|
#!/bin/sh
|
||
|
|
||
|
### BEGIN INIT INFO
|
||
|
# Provides: fence_sanlockd
|
||
|
# Required-Start: $time $syslog $remote_fs
|
||
|
# Required-Stop: $syslog
|
||
|
# Should-Start:
|
||
|
# Should-Stop:
|
||
|
# Default-Start: 2 3 4 5
|
||
|
# Default-Stop: 0 1 6
|
||
|
# Short-Description: Starts and stops fence_sanlockd
|
||
|
# Description: Starts and stops fence_sanlockd. See fence_sanlockd(8).
|
||
|
### END INIT INFO
|
||
|
PROG=fence_sanlockd
|
||
|
FENCE_SANLOCKD_BIN=/usr/sbin/$PROG
|
||
|
FENCE_SANLOCKD_RUNDIR=/var/run/$PROG
|
||
|
FENCE_SANLOCKD_PIDFILE=$FENCE_SANLOCKD_RUNDIR/$PROG.pid
|
||
|
FENCE_SANLOCKD_FIFOFILE=$FENCE_SANLOCKD_RUNDIR/$PROG.fifo
|
||
|
FENCESANLOCKDOPTS="-w"
|
||
|
|
||
|
FENCE_SANLOCK_AGENT_RUNDIR=/var/run/fence_sanlock
|
||
|
|
||
|
test -x $FENCE_SANLOCKD_BIN || { echo "$FENCE_SANLOCKD_BIN not installed";
|
||
|
if [ "$1" = "stop" ]; then exit 0;
|
||
|
else exit 5; fi; }
|
||
|
|
||
|
. /etc/rc.status
|
||
|
rc_reset
|
||
|
|
||
|
|
||
|
|
||
|
case "$1" in
|
||
|
start)
|
||
|
# start wdmd and sanlock daemons if they aren't running
|
||
|
service wdmd status > /dev/null 2>&1 || service wdmd start
|
||
|
service sanlock status > /dev/null 2>&1 || service sanlock start
|
||
|
|
||
|
[ ! -d $FENCE_SANLOCKD_RUNDIR ] && \
|
||
|
install -d -m 775 $FENCE_SANLOCKD_RUNDIR
|
||
|
|
||
|
[ ! -d $FENCE_SANLOCK_AGENT_RUNDIR ] && \
|
||
|
install -d -m 775 $FENCE_SANLOCK_AGENT_RUNDIR
|
||
|
|
||
|
[ -n "$(which restorecon)" ] && \
|
||
|
[ -x "$(which restorecon)" ] && \
|
||
|
restorecon $FENCE_SANLOCKD_RUNDIR
|
||
|
|
||
|
[ -n "$(which restorecon)" ] && \
|
||
|
[ -x "$(which restorecon)" ] && \
|
||
|
restorecon $FENCE_SANLOCK_AGENT_RUNDIR
|
||
|
|
||
|
if [ -e $FENCE_SANLOCKD_PIDFILE ]; then
|
||
|
if checkproc $FENCE_SANLOCKD_BIN ; then
|
||
|
echo -n "$PROG is already running."
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
else
|
||
|
echo "Removing stale PID file $FENCE_SANLOCKD_PIDFILE."
|
||
|
rm -f $FENCE_SANLOCKD_PIDFILE
|
||
|
fi
|
||
|
fi
|
||
|
echo -n "Starting $PROG "
|
||
|
startproc $FENCE_SANLOCKD_BIN $FENCESANLOCKDOPTS
|
||
|
rc_status -v
|
||
|
;;
|
||
|
stop)
|
||
|
echo -n "Shutting down $PROG "
|
||
|
agent_ps="$(ps ax -o pid,args | grep fence_sanlock | grep -v grep | grep -v fence_sanlockd)"
|
||
|
|
||
|
[ -n "$agent_ps" ] && {
|
||
|
agent_pid="$(echo $agent_ps | awk '{print $1}')"
|
||
|
echo -n "cannot stop while fence_sanlock $agent_pid is running"
|
||
|
rc_failed 1
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
}
|
||
|
|
||
|
# Ideally, we'd like a general way to check if anything
|
||
|
# needs fencing to continue running, but without that,
|
||
|
# check what we know, which is that dlm requires it.
|
||
|
if [ -d /sys/kernel/dlm/ ]; then
|
||
|
count="$(ls -A /sys/kernel/dlm/ | wc -l)"
|
||
|
if [ $count -ne 0 ]; then
|
||
|
echo -n "cannot stop while dlm lockspaces exist"
|
||
|
rc_failed 1
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
if [ -d /sys/kernel/config/dlm/cluster ]; then
|
||
|
# this dir exists while dlm_controld is running
|
||
|
echo -n "cannot stop while dlm is running"
|
||
|
rc_failed 1
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
fi
|
||
|
|
||
|
PID=$(pidofproc -p $FENCE_SANLOCKD_PIDFILE $PROG)
|
||
|
|
||
|
# We have to use SIGHUP to mean stop because sanlock
|
||
|
# uses SIGTERM to mean that the lockspace failed.
|
||
|
killproc -p $FENCE_SANLOCKD_PIDFILE $PROG -HUP > /dev/null 2>&1
|
||
|
retval=$?
|
||
|
if [ $retval -ne 0 ]; then
|
||
|
rc_failed 1
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
fi
|
||
|
|
||
|
# fence_sanlockd won't see the SIGHUP if it's
|
||
|
# still waiting for config from the fifo, so
|
||
|
# send invalid config to the fifo to make it fail.
|
||
|
if [ -p $FENCE_SANLOCKD_FIFOFILE ]; then
|
||
|
echo "" > $FENCE_SANLOCKD_FIFOFILE
|
||
|
fi
|
||
|
|
||
|
timeout=10
|
||
|
while checkpid $PID; do
|
||
|
sleep 1
|
||
|
timeout=$((timeout - 1))
|
||
|
if [ "$timeout" -le 0 ]; then
|
||
|
echo -n "failed waiting for $PROG ($PID) to stop"
|
||
|
rc_failed 1
|
||
|
rc_status -v
|
||
|
rc_exit
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
# stop wdmd and sanlock daemons if they are running
|
||
|
service sanlock status > /dev/null 2>&1 && service sanlock stop
|
||
|
service wdmd status > /dev/null 2>&1 && service wdmd stop
|
||
|
|
||
|
rc_status -v
|
||
|
;;
|
||
|
try-restart)
|
||
|
$0 status >/dev/null && $0 restart
|
||
|
rc_status
|
||
|
;;
|
||
|
restart)
|
||
|
$0 stop
|
||
|
$0 start
|
||
|
rc_status
|
||
|
;;
|
||
|
reload)
|
||
|
killproc -HUP $FENCE_SANLOCKD_BIN
|
||
|
rc_status -v
|
||
|
;;
|
||
|
status)
|
||
|
echo -n "Checking status of $PROG "
|
||
|
checkproc $FENCE_SANLOCKD_BIN
|
||
|
rc_status -v
|
||
|
;;
|
||
|
*)
|
||
|
echo "Usage: $0 {start|stop|restart|try-restart|reload|status}"
|
||
|
rc_failed 2
|
||
|
rc_exit
|
||
|
;;
|
||
|
esac
|
||
|
rc_exit
|