1: Create check file:
cd /usr/local/ mkdir auto cd auto vi restart.sh
Paste script:
เช็คจาก Server Load
#!/bin/sh check=`cat /proc/loadavg | sed 's/\./ /' | awk '{print $1}'` if [ $check -gt 10 ] //10 is load average on 5 minutes then service httpd restart service nginx restart fi
เช็คจาก http process
#!/bin/sh check=`ps aux | grep 'httpd' | awk '{print $6;}' | awk '{avg += $1;} END {printf avg;}'` if [ $check -gt 200000 ] then service httpd restart service nginx restart printf $check fi
Save and chmod script to 755:
chmod 755 restart.sh
2: Create cron file:
cd ~ cd /etc/cron.d vi auto_restart
Paste script:
*/5 * * * * root /usr/local/auto/restart.sh >/dev/null 2>&1
Save cron file and finish.
http://www.webhostingtalk.com/showthread.php?t=971304