Created
July 29, 2013 06:45
-
-
Save cs-sonar/6102514 to your computer and use it in GitHub Desktop.
netstatとかロードアベレージの閾値を超えたらログを残しつつApache再起動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
###### | |
# netstatの80が400越えたら再起動 | |
##### | |
apacheprocess=`netstat -an | grep :80 | wc -l` | |
if [ $apacheprocess -gt 400 ]; then | |
stopdate=`date` | |
echo "$stopdate apache stoped. try restart." >> /usr/local/hosting/apache_restart_log.txt | |
netstat -an > /usr/local/hosting/apache_restart_netstat.txt | |
/usr/local/apache2/bin/apachectl stop | |
echo "$stopdate apache stoped (done)" >> /usr/local/hosting/apache_restart_log.txt | |
sleep 60 | |
/usr/local/apache2/bin/apachectl start | |
echo "$stopdate apache started." >> /usr/local/hosting/apache_restart_log.txt | |
echo 'apache netstat restart' | mail mailaddr@example.com -s "Apache Restart "`hostname` | |
fi | |
###### | |
# ロードアベレージが50越えたら再起動 | |
##### | |
LOAD=`cat /proc/loadavg | awk '{print $1}' | sed 's/\..*//'` | |
if [ $LOAD -gt 50 ]; then | |
stopdate=`date` | |
echo "$stopdate loadAvg is too high. apache stopping." >> /usr/local/hosting/apache_restart_log.txt | |
/usr/local/apache2/bin/apachectl stop | |
echo "$stopdate apache stoped (done)" >> /usr/local/hosting/apache_restart_log.txt | |
sleep 60 | |
/usr/local/apache2/bin/apachectl start | |
echo "$stopdate apache started." >> /usr/local/hosting/apache_restart_log.txt | |
echo 'apache LA restart' | mail mailaddr@example.com -s "Apache Restart "`hostname` | |
fi | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment