#!/bin/bash

if [ "$#" -eq 0 ]; then 
    echo "No web service specified"
    exit 1
fi

restart_httpd() {
    if [ `whoami` != "root" ]; then
        echo "$1 httpd monitor must be run as root!"
        exit 1
    fi

    if [ `hostname` != $1 ]; then
        echo "Web service \"$1\" does not match hostname \"`hostname`\""
        exit 1
    fi

    date && /sbin/service httpd status 
    if [ "$?" -eq 3 ]; then
        # httpd is stopped, restart
        echo "Attempting to restart httpd on `hostname`..."
#        /sbin/service httpd start
    fi
}

case "$1" in
"lcls-archapp"|"mccelog")
    restart_httpd $1
    ;;
*)  
    echo "Unsupported web service $1"
    exit 1
    ;;
esac
