Live Help


Skype Chat
Yahoo Chat

Client portal

VPS Service

Auto Restart httpd and mysql service

 May 26, 2013     0 Comments

The script below is useful if you want to automate your VPS to auto restart the httpd and mysql service after certain threshold exceeded.


batas=75 #Batas Max Memory dalam persen
memori=$(free | grep "Mem:" | awk '{print $2}')
pakai=$(free | grep "cache:" | awk '{print $3}')
hitung=$(echo "scale=0;100-$pakai * 100 / $memori" | bc -l)
akhir=$(echo "scale=0;100-$hitung" | bc -l)

if [ $akhir -gt $batas ]
        /sbin/service httpd restart
        /sbin/service mysqld restart

        echo "Apache dan Mysqld di restart - `date +'%d-%m-%Y %T'`. Status RAM akhir $akhir%" \
        >> /var/log/apache_mysql_restarter.log

Script written by Morhan Tambunan

How helpful was this article to you?

cPanel Partner NOC