#!/bin/bash
# need over check-utils 3.0.2

export LANG=C

[ -f "/etc/sysconfig/lighttpd-monitor" ] && source /etc/sysconfig/lighttpd-monitor

cmd="/usr/bin/httpwatch"

logfile=${logfile:="/var/log/httpd/httpwatch.log"}
ctimeout=${ctimeout:=5}
rtimeout=${rtimeout:=5}
target=${target:="$(hostname)"}
uri=${uri:="/robots.txt"}


if [ ! -x "${cmd}" ]; then
	echo "$(date "+%Y.%m.%d %H:%M:%S") ${cmd} not found" >> ${logfile}
fi

${cmd} -c ${ctimeout} -r ${rtimeout} -l ${logfile} http://${target}${uri}
ret=$?

if [ $ret -ne 0 ]; then
	killall -9 lighttpd &> /dev/null || true
	/sbin/service lighttpd restart &> /dev/null || true
fi

exit 0
