#!/bin/bash

# Developed by Rajani Chand for SpiritHosting.NET Limited.

# Load at or above which actions to be taken.
LMAX=9;

# Services to be killed if the load is high.
SRV=( httpd exim );

# Finding Load
load=`uptime | awk '{ print $10 }' | cut -d '.' -f 1`;

if [ $load -ge $LMAX ]
then

/sbin/service chkservd stop;

#Stopping Services
for sk in ${SRV[@]}
do
 /sbin/service $sk stop;
 pkill -9 $sk;
 killall -9 $sk;
 killall -9 $sk;
done

sleep 10;

#Starting Services
for sk in ${SRV[@]}
do
 if [ $sk = "httpd" ]
  then
        /sbin/service $sk startssl;
        if [ $? -ne 0 ]
        then
                /sbin/service $sk start;
        fi
  else
        /sbin/service $sk start;
 fi
done

/sbin/service chkservd start;

fi


