Dragon Boat Festival, Sleep, was awakened by the phone, the Web server hung up, irritated bad. A busy landing server, found that the Apache server and memcache server illegally shut down. Hey, in order to sleep well, hurry to write a little foot originally monitoring the Appach and Memcache bar. The following script is soon available:
#!/bin/bash-name= ' basename $ sh ' function showHelp () {echo "Usage: $name" echo "$name Test|dev "Exit 1} If [$#-ne 0-a $#-ne 1];" Then showHelp fi #正式/test environment test=0 IF [$#-eq 1]; Then # echo "$" if ["$" = "Dev"-o "$" = "test"]; Then test=1 else showHelp fi fi #echo $test websrvkey=/bin/httpd websrvb In=/etc/init.d/apachectl cachekey=/memcached cachebin=/usr/local/memcached/bin/memcached cachepid=/usr/local/ Memcached/memcached.pid cachedir=/usr/local/memcached #run Web server function Startweb () {echo ' ' date ' start we Bsrv. "If [!-f $websrvbin]; Then echo "' Date ' websrv bin [$websrvbin] not exist ..." return fi $websrvb
In start echo "' Date ' start websrv complete ..."} #run cache function StartCache () {echo "' Date ' start cache ..." If [$test-eq 1]; Then Cachebin=/usr/bin/memcached fi if [!-f $cachebin]; Then echo "' Date ' cache bin [$cachebin] not exist ..." return fi if [! -D $cachedir]; Then echo "' Date ' cache dir not exist ..." mkdir $cachedir echo "' Date ' CR Eate dir $cachedir "fi if [$test-eq 0]; Then $cachebin-D-M 100-uroot-l 0.0.0.0-p 11000-c 512-p $cachepid Else $cach
Ebin-d-M 128-l 192.168.119.60-p 12000-u ossh fi echo "' Date ' Start cache complete ..."} Cnt= ' Ps-ef | grep $websrvkey | GREP-VC grep ' # echo $cnt if [$cnt-le 0]; Then Startweb fi cnt= ' Ps-ef | grep $cachekey | GREP-VC grep ' #echo $cnt if [$cnt-le 0];
Then StartCache fi
Save the above script as monitorwebsrv.sh and give the file executable permission to do the following:
chmod +x /etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh
Then join the Crontab planning task as follows:
* * * * */etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh >>/tmp/monitorwebsrv.log * * * * * * * * * * *
SLE EP 30; /etc/app/slightphp/public/csevent/bin/crontab/monitorwebsrv.sh >>/tmp/monitorwebsrv.log
Why add two? To be executed every 30 seconds.
For shells and crontab, see previous Blog:shell script comparison operators and logical operator summaries, Introduction to Linux shell scripting logical operators, and a summary of Linux crontab commands