#!/bin/sh # # Startup script for the Audible Alarm # # author: Kirk Lawson # Horms # # description: sets an audible alarm running by beeping at a set interval # processname: alarm # config: /etc/AudibleAlarm/AudibleAlarm.conf - not yet implemented # # OCF parameters are as below: # OCF_RESKEY_nodelist # # License: GNU General Public License (GPL) ####################################################################### # Source function library. : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### PIDFILE=${HA_VARRUN}/heartbeat-bell #For testing #PIDFILE=/tmp/heartbeat-bell # What host are we running on? us=`uname -n` usage() { echo "Usage: $0 {start|stop|restart|status|monitor|meta-data|validate-all}" echo " The node list is an optional space delimited" echo " list of hosts that should never sound the alarm." } meta_data() { cat < 1.0 Resource script for AudibleAlarm. It sets an audible alarm running by beeping at a set interval. Emits audible beeps at a configurable interval The node list that should never sound the alarm. Node list END } audiblealarm_start () { ocf_log info "$0: Starting" if [ -f $PIDFILE ]; then PID=`head -n 1 $PIDFILE` if [ -n "$PID" ]; then ocf_log info "$0: Appears to already be running, killing [$PID]" kill $PID > /dev/null fi fi # Use () to create a subshell to make the redirection be synchronized. ( while [ 1 ]; do sleep 1 #Sleep first, incase we bail out printf "\a" > /dev/console # Uncomment this line to cause floppy drive light # to flash (requires fdutils package). # /usr/bin/floppycontrol --pollstate > /dev/null # # To avoid issues when called by lrmd, redirect stdout->stderr. done & if echo $! > $PIDFILE; then : else ocf_log info "$0: Could not write to pid file \"$PIDFILE\", bailing" kill $! return $OCF_ERR_GENERIC fi) >&2 return $? } audiblealarm_stop () { ocf_log info "$0: Shutting down" if [ -f $PIDFILE ]; then PID=`head -n 1 $PIDFILE` # ocf_log info "$0: Appears to already be running, killing [$PID]" # commented by Phost, since the confusion in the log. if [ -n "$PID" ]; then # Donnot remove PIDFILE in case the `kill` fails. kill $PID > /dev/null && rm -f $PIDFILE fi fi return $? } audiblealarm_restart () { audiblealarm_stop audiblealarm_start return $? } audiblealarm_status () { if [ -f $PIDFILE ]; then PID=`head -n 1 $PIDFILE` if [ -n "$PID" ]; then echo running return $OCF_SUCCESS fi fi echo stopped return $OCF_NOT_RUNNING } audiblealarm_validate_all () { check_binary printf echo "Validate OK" return $OCF_SUCCESS } if [ $# -ne 1 ]; then usage exit $OCF_ERR_ARGS fi case "$1" in meta-data) meta_data exit $OCF_SUCCESS ;; start) for arg in $OCF_RESKEY_nodelist do if [ "$us" = "$arg" ]; then # We should not start because we are on a host # listed in our argument list. exit $OCF_SUCCESS fi done audiblealarm_start ;; stop) audiblealarm_stop ;; restart) audiblealarm_restart ;; status|monitor) audiblealarm_status ;; validate-all) audiblealarm_validate_all ;; usage) usage exit $OCF_SUCCESS ;; *) usage exit $OCF_ERR_ARGS ;; esac exit $?