#!/bin/bash

if [[ "$#" -ne "3" ]]; then
	echo "Usage: $0 "'"$HOSTNAME$" $HOSTSTATE$ $HOSTSTATETYPE$'
	exit 1
fi

. /home/nagios/.ssh/.ssh-agent

hname="$1"
hstate="$2"
htype="$3"

case $hstate in
	UP)   # Recovery
		if [[ "$htype" -ne "HARD" ]]; then exit 0; fi
		
		#/usr/bin/ssh $hname '/usr/bin/sudo /sbin/service mod_gearman_worker start alef && /usr/bin/sudo /sbin/service mod_gearman_worker start bet' 2>&1 | mail -s "RECOVERY: Gearman worker startup on $hname" networking@Princeton.EDU
		/usr/bin/ssh $hname '/usr/bin/sudo /sbin/service mod_gearman_worker start' 2>&1 | mail -s "RECOVERY: Gearman worker startup on $hname" networking@Princeton.EDU
		exit $?
	;;

	DOWN)  # Don't care
	;;

	UNREACHABLE)    # Don't care
	;;

	*)
		echo "Invalid host state passed"
		exit 1
	;;
esac

exit 0
