[Linux Shell Script] Automatically restart Apache/httpd server when it reaches certain amount of RAM

Started by Xhanch Studio, July 21, 2012, 09:31:14 PM

previous topic - next topic
Go Down

Xhanch Studio

Here's is a Linux shell script that will automatically restart your Apache/httpd server when your ram/memory usage reaches a certain value/number/limit.

Code Select

#Limit of RAM in MB

ram_usg="$($_CMD free -mto | grep Mem: | awk '{ print $3 }')"

if [ "$ram_usg" -ge "$ram_max" ]; then
    /sbin/service httpd restart
    echo "RAM WARNING" | mail -s "Ram Limit Reached" your-email@example.com
    echo "RAM OK"

The above script will restart your Apache/httpd server when it hits 1600 MB RAM usage.
You can modify the value of ram_max as you wish
Best Regards,
Susanto B.Sc
Web development services, WordPress plugin and theme development, PSD to XHTML conversion - http://xhanch.com
Read free manga online - http://authrone.com

Go Up