Restarto Apache nese serveri arrin nje limit te caktuar ngarkese

Scripti me poshte mund te perdoret nga administratoret e serverave Linux. Sa here qe ngarkesa e serverit ngrihet mbi nje vlere te caktuar (percaktuar ne variablin: HTTPD_RESTART_LOAD), scripti ben nje restart te procesit.
Me ane te ketij scripti eshte e lehte te parandalohen crashet e serverave qe jane ne pune. Per cdo rast te sherbimit web (httpd), scripti dergon nje email (ne adresen e percaktuar tek EMAIL_ADDRESS).

Perdorimi:

  1. Krijoni nje skedar me emer kontrApache.sh ne te cilin vendoset kodi me poshte.  (/home/root/.scripts/kontrApache.sh)
  2. Scripti duhet te jete i ekzekutueshem: chmod 775 /home/root/.scripts/kontrApache.sh
  3. Krijoni nje crontab (crontab -e per te edituar crontab) ku te therritet ky script cdo x min. Psh: */2     *       *       *       *       sh /home/root/.scripts/kontrApache.sh >/dev/null 2>&1

Meritat per scriptin:
?nobaloney.net

#!/bin/bash
# Kontrollo ngarkesen e serverit dhe nese kalon nje kufi e ri-fillon si sherbim
LOAD_TIME=`date '+%F %H:%M'`
SERVER_NAME="EmriIServerit.host.al"
EMAIL_ADDRESS="AdresaJuajeEmailit@"
UP_TIME=`uptime`
#101 means no warning emails.
LOAD_WARNING="101"
HTTPD_RESTART_LOAD="20"
TOP_OP=`top -b -n 1 | head -20`
TOP[1]=`echo "$UP_TIME"`
TOP[2]=`echo "$TOP_OP" | grep 'zombie'`
TOP[3]=`echo "$TOP_OP" | grep '%' | grep -v 'PID'`
TOP[4]=`echo "$TOP_OP" | grep '^Swap\:'`
TOP[5]=`echo "$TOP_OP" | grep '^Mem\:'`
ONE_LOAD=`echo "${TOP[1]}" | awk '{print $10}' | cut -c1-4`
#echo $ONE_LOAD
if [ "$ONE_LOAD" == "aver" ]; then
ONE_LOAD=`echo "${TOP[1]}" | awk '{print $11}'| cut -c1-4`
fi
#echo $ONE_LOAD
ONE_LOAD_CALC=`echo "${TOP[1]}" |awk '{print $10}' | cut -c1-4 | awk 'BEGIN {FS = "."}{print $1}'`
#echo $ONE_LOAD_CALC
if [ "$ONE_LOAD_CALC" == "aver" ]; then
ONE_LOAD_CALC=`echo "${TOP[1]}"| awk '{print $11}'| cut -c1-4 | awk 'BEGIN {FS = "."}{print $1}'`
fi
#echo $ONE_LOAD_CALC
ONE_LOAD_SUB="$ONE_LOAD(1min) - $LOAD_TIME"
#echo $ONE_LOAD_SUB
MAIL_OUTPUT=`echo -e "${TOP[1]}\n${TOP[2]}\n${TOP[3]}\n${TOP[4]}\n${TOP[5]}\n"`
#echo -e "\n$MAIL_OUTPUT\n"
if [ "$ONE_LOAD_CALC" -ge "$LOAD_WARNING" ]; then
echo -e "\nSERVER LOAD of $SERVER_NAME is $ONE_LOAD_SUB\n\n$MAIL_OUTPUT\n" | mail -s "LOAD WARNING : $SERVER_NAME - $ONE_LOAD_SUB" $EMAIL_ADDRESS
fi
if [ "$ONE_LOAD_CALC" -ge "$HTTPD_RESTART_LOAD" ]; then
/sbin/service httpd restart 2&> /var/log/cron_load.log  && echo -e "\nSERVER LOAD of $SERVER_NAME is $ONE_LOAD_SUB\n" >> /var/log/cron_load.log && echo -e "$MAIL_OUTPUT\n" >> /var/log/cron_load.log && cat /var/log/cron_load.log | mail -s "HTTPD RESTART : $SERVER_NAME - $ONE_LOAD_SUB" $EMAIL_ADDRESS
fi
exit 0
#END

3 Replies to “Restarto Apache nese serveri arrin nje limit te caktuar ngarkese”

Leave a Reply