2012-12-03 23:15:47 +01:00
|
|
|
#!/bin/sh
|
2017-03-21 22:32:03 +01:00
|
|
|
#
|
|
|
|
# fence_sanlockd - daemon for fence_sanlock agent
|
|
|
|
#
|
|
|
|
# chkconfig: 2345 20 80
|
|
|
|
# description: starts and stops fence_sanlockd
|
|
|
|
#
|
2012-12-03 23:15:47 +01:00
|
|
|
|
|
|
|
### 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
|
2017-03-21 22:32:03 +01:00
|
|
|
# Short-Description: starts and stops fence_sanlockd
|
|
|
|
# Description: starts and stops fence_sanlockd
|
2012-12-03 23:15:47 +01:00
|
|
|
### END INIT INFO
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
prog="fence_sanlockd"
|
|
|
|
agent="fence_sanlock"
|
|
|
|
daemonrundir="/var/run/$prog"
|
|
|
|
agentrundir="/var/run/$agent"
|
|
|
|
runfile="$daemonrundir/$prog.pid"
|
|
|
|
fifofile="$daemonrundir/$prog.fifo"
|
|
|
|
lockfile="/var/lock/subsys/$prog"
|
|
|
|
exec="/usr/sbin/$prog"
|
|
|
|
|
|
|
|
FENCESANLOCKDOPTS="-w"
|
2012-12-03 23:15:47 +01:00
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
test -x $exec || { echo "$exec not installed";
|
|
|
|
if [ "$1" = "stop" ]; then exit 0;
|
2012-12-03 23:15:47 +01:00
|
|
|
else exit 5; fi; }
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
|
|
|
|
|
2012-12-03 23:15:47 +01:00
|
|
|
. /etc/rc.status
|
|
|
|
rc_reset
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
case "$1" in
|
|
|
|
start)
|
2012-12-03 23:15:47 +01:00
|
|
|
# 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
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
if [ ! -d $daemonrundir ]; then
|
|
|
|
install -d -m 775 $daemonrundir
|
|
|
|
[ -x /sbin/restorecon ] && restorecon $daemonrundir
|
|
|
|
fi
|
|
|
|
if [ ! -d $agentrundir ]; then
|
|
|
|
install -d -m 775 $agentrundir
|
|
|
|
[ -x /sbin/restorecon ] && restorecon $agentrundir
|
|
|
|
fi
|
2012-12-03 23:15:47 +01:00
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
if [ -e $runfile ]; then
|
|
|
|
if checkproc $exec ; then
|
|
|
|
echo -n "$prog is already running."
|
2012-12-03 23:15:47 +01:00
|
|
|
rc_status -v
|
2017-03-21 22:32:03 +01:00
|
|
|
rc_exit
|
|
|
|
else
|
|
|
|
echo "Removing stale PID file $runfile."
|
|
|
|
rm -f $runfile
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "Starting $prog "
|
|
|
|
startproc $exec daemon $FENCESANLOCKDOPTS
|
|
|
|
rc_status -v
|
2012-12-03 23:15:47 +01:00
|
|
|
;;
|
2017-03-21 22:32:03 +01:00
|
|
|
stop)
|
|
|
|
agent_ps="$(ps ax -o pid,args | grep $agent | grep -v grep | grep -v $prog)"
|
2012-12-03 23:15:47 +01:00
|
|
|
|
|
|
|
[ -n "$agent_ps" ] && {
|
|
|
|
agent_pid="$(echo $agent_ps | awk '{print $1}')"
|
2017-03-21 22:32:03 +01:00
|
|
|
echo -n "cannot stop while $agent $agent_pid is running"
|
2012-12-03 23:15:47 +01:00
|
|
|
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
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
PID=$(pidofproc -p $runfile $prog)
|
2012-12-03 23:15:47 +01:00
|
|
|
|
|
|
|
# We have to use SIGHUP to mean stop because sanlock
|
|
|
|
# uses SIGTERM to mean that the lockspace failed.
|
2017-03-21 22:32:03 +01:00
|
|
|
echo -n $"Sending stop signal $prog ($PID)"
|
|
|
|
killproc -p $runfile $prog -HUP
|
2012-12-03 23:15:47 +01:00
|
|
|
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.
|
2017-03-21 22:32:03 +01:00
|
|
|
if [ -p $fifofile ]; then
|
|
|
|
echo "" > $fifofile
|
2012-12-03 23:15:47 +01:00
|
|
|
fi
|
|
|
|
|
2017-03-21 22:32:03 +01:00
|
|
|
echo -n $"Waiting for $prog ($PID) to stop"
|
2012-12-03 23:15:47 +01:00
|
|
|
timeout=10
|
|
|
|
while checkpid $PID; do
|
|
|
|
sleep 1
|
|
|
|
timeout=$((timeout - 1))
|
|
|
|
if [ "$timeout" -le 0 ]; then
|
2017-03-21 22:32:03 +01:00
|
|
|
echo -n "failed waiting for $prog ($PID) to stop"
|
|
|
|
rc_failed 1
|
|
|
|
rc_status -v
|
|
|
|
rc_exit
|
2012-12-03 23:15:47 +01:00
|
|
|
fi
|
|
|
|
done
|
2017-03-21 22:32:03 +01:00
|
|
|
|
|
|
|
rm -f $lockfile
|
2012-12-03 23:15:47 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
;;
|
2017-03-21 22:32:03 +01:00
|
|
|
try-restart)
|
|
|
|
$0 status >/dev/null && $0 restart
|
|
|
|
rc_status
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
rc_status
|
|
|
|
;;
|
|
|
|
reload)
|
|
|
|
killproc -HUP $exec
|
|
|
|
rc_status -v
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
echo -n "Checking status of $prog "
|
|
|
|
checkproc $exec
|
|
|
|
rc_status -v
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart|try-restart|reload|status}"
|
2012-12-03 23:15:47 +01:00
|
|
|
rc_failed 2
|
|
|
|
rc_exit
|
2017-03-21 22:32:03 +01:00
|
|
|
;;
|
2012-12-03 23:15:47 +01:00
|
|
|
esac
|
|
|
|
rc_exit
|