#!/bin/sh # Owen Mcshane 25/01/11 # A. Forti Modified 03/04/2011 Using ldapsearch instead of netstat to detect when the process exist but is not responsive instead of being dead # A. Forti Modified 30/10/2011 Added check on freshness and changed how the presence of the proc is detected to take slapd2.4 and slapd into account sendalert(){ subject=$1 body=$2 #echo $subject $body sendEmail -f root@tier2.hep.manchester.ac.uk -u $subject -m $body -t ops@tier2.hep.manchester.ac.uk -s mercury 2>1 > /dev/null } ######## # Main # ######## # Get the local machine hostname hn=`hostname -s` # Check if the bdii is responsive and get the last time stamp now=`date +%s`; time_stamp=`(ldapsearch -xLLL -b CompressionType=zip,o=infosys -p 2170 -h $hn modifyTimestamp|grep mod|cut -c26-31| perl -ne 'if (/(\d\d)(\d\d)(\d\d)/) { print "$1:$2:$3\n" }') 2> /dev/null` # If it isn't if [ -z "$time_stamp" ]; then proc=`ps ax o fname|grep slapd` if [ -n "$proc" ]; then # Check if there is a slapd process, processes might be still running but they might not be responsive sendalert "slapd exist but not responding on $hn" "Restarted bdii service on $hn" else # if there are no processes running just start the bdii sendalert "slapd died on $hn" "Restarted bdii service on $hn" fi /sbin/service bdii restart else ldap=`date -d "$time_stamp" +%s`; diff=$(($now-$ldap)); echo $diff tt if [ $diff -gt 900 ]; then # if the modify date is older than 15 mins restart the bdii sendalert "bdii freshness is more than 900s old on $hn" "Restarted bdii service on $hn" /sbin/service bdii restart fi fi