XHanch Studio Log in | Register | Cart

Forum

Notifications
Clear all

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

XHanch
(@xhanch-alt)
Member Admin

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.

#!/bin/bash

#Limit of RAM in MB
ram_max=1600

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
else
    echo "RAM OK"
fi

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

Quote
Topic starter Posted : 22/07/2012 3:31 am
Share:

× Close Menu