• CozWeAreFriends Banner. Nice isn't it?
  • CozWeAreFriends Banner. Nice isn't it?
  • Previous:
    Next:

    Siebel Restart WebServer Script When Memory Reaching Threshold

    Posted on April 27th, 2012 by fath

    Hello All,

    There’s this occasion whereby Siebel will somehow crash if the server memory reaching certain level. To encounter/as a workaround for this, I wrote a monitoring script that will check the server utilization and perform Siebel’s WebServer restart whenever only small amount of memory left in the server. Please have a look at the script below 🙂

     

    #!/usr/bin/sh
    # Script to grep Free RAM
    # Perform Web Server restart once the RAM meet threshold
    # Written by Fath

    # THRESHOLD IN ‘K’ bytes UNIT
    THRESHOLD=1400000

    WEB_SERVICE_DIR=/opt/hpws/apache32/bin

    FREE_RAM_OUTPUT=/home/admin/FREE_RAM_OUTPUT.txt
    TOP_OUTPUT=/home/admin/TOP_OUTPUT.txt
    top -d1 -f ${TOP_OUTPUT}

    MEMORY_ALL=`grep “Memory:” ${TOP_OUTPUT}`
    FREE_RAM=`echo ${MEMORY_ALL} | awk ‘{print $8}’`
    FREE_RAM_NO=`echo $FREE_RAM | awk ‘{gsub (/K/,””); print}’`

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    date >> ${FREE_RAM_OUTPUT}

    if [ “$FREE_RAM_NO” -lt “$THRESHOLD” ];then
    echo “Free RAM is less than ${THRESHOLD}K (${FREE_RAM_NO}K). Performing Web Service restart…” >> ${FREE_RAM_OUTPUT}
    echo “httpd processes running in server:” >> ${FREE_RAM_OUTPUT}
    ps -ef | grep httpd | grep apache32 >> ${FREE_RAM_OUTPUT}
    echo “Shutting down.. ” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/stopapa >> ${FREE_RAM_OUTPUT}
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    while [ “$PROC_COUNT” -ne “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “0 httpd process running. Starting up..” >> ${FREE_RAM_OUTPUT}
    . ${WEB_SERVICE_DIR}/startapa >> ${FREE_RAM_OUTPUT}
    while [ “$PROC_COUNT” -eq “0” ]
    do
    sleep 1
    PROC_COUNT=`ps -ef | grep httpd | grep apache32 | wc -l`
    done
    echo “OK! httpd processes are running!” >> ${FREE_RAM_OUTPUT}
    else
    echo “There’s enough free RAM (${FREE_RAM_NO}K).” >> ${FREE_RAM_OUTPUT}
    fi

    echo “———————————————–” >> ${FREE_RAM_OUTPUT}
    rm ${TOP_OUTPUT}

     



    Leave a Reply