#!/bin/bash #Author: Tay Kratzer, tk@gwava.com # ---------------------------------------------------------------- #IMPLEMENTATION STEPS: 1,2,3(a-c) #1.) Place this bash script into a file on the server where the GW WebAccess Application is installed, for example in: /usr/sbin/hawebaccess.sh #2.) Make the script exectuable: chmod 777 /usr/sbin/hawebaccess.sh #3.) Configure the "cron" utility to run the the script every minute: #3a.) Edit the /etc/crontab file #3b.) Add a line that reads: */1 * * * * root /usr/sbin/hawebaccess #3c.) After editing the crontab and saving it restart cron: /etc/init.d/cron restart # ---------------------------------------------------------------- #CONFIGURATION SECTION BEGIN# # Do you want mail notification? Your server has to support this function. # ---------------------------------------------------------------- #CHANGE CONFIGURATION SETTINGS: 1,2,3 # 1.) Is WebAccess configured to use SSL (HTTPS) or not? 0 means HTTP and 1 means HTTPS declare -i SSL_ON_WEBACCESS_SERVER_ENABLED="1" # 2.) What version of Tomcat is on your server? SLES10 is typically version 5, SLES11 is typically version 6 TOMCAT_VERSION="5" # 3.) Configure who will get notified if this script restarted GroupWise WebAccess MAIL_FROM="webaccess@acme.com" MAIL_TO="admin@acme.com" #CONFIGURATION SECTION END# # ---------------------------------------------------------------- # CODE SECTION BEGIN - BEYOND THIS SECTION YOU ARE ON YOUR OWN # PROGRAM_NAME="GroupWise WebAccess High Availability Monitor" # // Variables for commands to contol Apache and Tomcat APACHE_STOP_COMMAND="rcapache2 stop" APACHE_START_COMMAND="rcapache2 start" case $TOMCAT_VERSION in 5) TOMCAT_STOP_COMMAND="rctomcat5 stop" TOMCAT_START_COMMAND="rctomcat5 start" ;; 6) TOMCAT_STOP_COMMAND="rctomcat6 stop" TOMCAT_START_COMMAND="rctomcat6 start" ;; *) TOMCAT_STOP_COMMAND="rctomcat6 stop" TOMCAT_START_COMMAND="rctomcat6 start" ;; esac # // Variables for file location LOG="/tmp/ap/apache_up.log" TEMP_DIR="/tmp/hawebaccess" LOCK_FILE="${TEMP_DIR}/lock.bin" # // Other variables PROCESS_LOCK_WAIT_TIME="300" # Make log directory mkdir -p ${TEMP_DIR} 2> /dev/null # // Function sections function LOG() { # Log function DATE=`date` echo "DATE:$DATE - $1" echo "DATE:$DATE - $1" >> $LOG } function MAIL_MESSAGE() { # A simple mail function MESSAGE_BODY_TEMP_FILE="${TEMP_DIR}\mailer.$$.bin" echo "$2" > $MESSAGE_BODY_TEMP_FILE mail -a "$LOG" -r $MAIL_FROM -s "$1" "$MAIL_TO" < $MESSAGE_BODY_TEMP_FILE sleep 20 rm $MESSAGE_BODY_TEMP_FILE } function UNLOCK_PROCESS() { # Remove a process lock file rm ${LOCK_FILE} 2> /dev/null } function LOCK_PROCESS() { # Lock the process so that this process will not try to load Apache and Tomcat multiple times in a short period of time declare -i AP_SLEEP_TIME="0" declare -i CURRENT_TIME=`date +%s` declare -i PAUSE=`echo "${PROCESS_LOCK_WAIT_TIME}"` let AP_SLEEP_TIME=${CURRENT_TIME}+${PAUSE} echo "AP_SLEEP_TIME=\"${AP_SLEEP_TIME}\"" >> ${LOCK_FILE} } function CHECK_LOCK_PROCESS() { # Create a process lock file declare -i AP_SLEEP_TIME=`date +%s` sleep 1 declare -i CURRENT_TIME=`date +%s` declare -i LOCK_FILE_EXISTS=`test -f ${LOCK_FILE} && echo "0" || echo "1"` if [ $LOCK_FILE_EXISTS -eq 0 ] then # Read in the lock file . ${LOCK_FILE} 2> /dev/null if [ ${CURRENT_TIME} -gt ${AP_SLEEP_TIME} ] then UNLOCK_PROCESS else LOG "Aborting ${PROGRAM_NAME} - This process ran too recently" exit 0 fi else : fi } function LOAD_APACHE_AND_TOMCAT() { #This function will attempt to load Apache and Tomcat CHECK_LOCK_PROCESS LOCK_PROCESS ${APACHE_STOP_COMMAND} LOG "Loading the Apache Server" ${APACHE_START_COMMAND} LOG "Loading the Tomcat Server" ${TOMCAT_STOP_COMMAND} ${TOMCAT_START_COMMAND} } function CHECK_WEBACCESS_RUNNING_STATUS() { #This function checks to see if GroupWise WebAccess is running on the local server echo "Running ${FUNCNAME}" cd ${TEMP_DIR} rm webacc* 2> /dev/null if [ $SSL_ON_WEBACCESS_SERVER_ENABLED -eq 0 ] then declare -i WEBACCESS_RUNNING=`wget http://localhost/gw/webacc && echo "0" || echo "1"` else declare -i WEBACCESS_RUNNING=`wget --no-check-certificate https://localhost/gw/webacc && echo "0" || echo "1"` fi if [ $WEBACCESS_RUNNING -eq 0 ] then rm webacc* 2> /dev/null else LOG "Detected that GroupWise WebAccess isn't loaded" LOAD_APACHE_AND_TOMCAT MAIL_MESSAGE "Detected that GroupWise WebAccess was not loaded." "Please see the attached log file for more information" fi } main() { # The main function # LOG "Checking WebAcess Status" CHECK_WEBACCESS_RUNNING_STATUS } main