XHanch Studio Log in | Register | Cart

Forum

[Linux Shell Script...
 
Notifications
Clear all

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

1 Posts
1 Users
0 Likes
1,898 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

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

 
Posted : 22/07/2012 3:31 am
Share:

× Close Menu