#!/bin/bash
# A Heartbeat lsb-RA to produce a .html output of crm_mon.
# Copyright (C) 2008 Johan Granath (johan@artcraft.se)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
declare PIDFILE="/tmp/crm_mon.pid"
declare STATUSFILE="/path/to/wwwdata/status.html"
declare TMPFIL="/tmp/crm_mon.temp$$"
declare CRMMON="/usr/sbin/crm_mon"
declare OPTIONS="-p ${PIDFILE} -d --as-html ${STATUSFILE}"
case $1 in
start)
if [ -e ${PIDFILE} ] ; then
PID=`cat ${PIDFILE} | sed 's/ //g'`
echo "Already running (PID ${PID})...exit"
exit 0
else
`${CRMMON} -s > ${TMPFIL}`
CRITICAL=`cat ${TMPFIL} | grep "Critical:" | wc -l`
rm -f ${TMPFIL}
if [ ${CRITICAL} == "1" ] ; then
echo "Critical error...exit"
exit 0
else
echo -n "Starting..."
`${CRMMON} ${OPTIONS}`
echo "done"
exit 0
fi
fi
;;
stop)
if [ -e ${PIDFILE} ] ; then
echo -n "Closing..."
PID=`cat ${PIDFILE} | sed 's/ //g'`
kill -9 ${PID}
rm -f ${PIDFILE}
echo "done"
exit 0
else
echo "Not running...exit"
exit 0
fi
;;
status)
if [ -e ${PIDFILE} ] ; then
PID=`cat ${PIDFILE} | sed 's/ //g'`
echo "Running...(PID ${PID})"
exit 0
else
echo "Not running..."
exit 0
fi
;;
*)
echo "Usage: ${0} (start|stop|status)"
exit 0
;;
esac