2013年10月10日星期四

shell script , apache automatically restart

downtime Recently , apache always reported a similar error :
child process 3732 still did not exit, sending a SIGKILL
caught SIGTERM, shutting down

httpd already increased maxchild value, but limited system memory or above error will be reported

limited understanding of the shell , the following code , a role here ?
pgrep httpd
if [ $? -eq 0 ]; then service httpd restart; fi


Or should simulate open a page, if 500 error , and then restart apache?

expert help to the segment and reliable bar code, thank you.
------ Solution ---------------------------------------- ----

reference:
curl -I http://www.mydomain.com/check.php 2>/dev/null | head -1 | grep -q " 200 OK"
if [ $? -eq 0 ]; then
    echo "The URL works fine"
fi

------ For reference only ----------------------------------- ----
pgrep httpd process to find success is to return 0 , so you should determine error conditions

if [ $? -ne 0 ]

------ For reference only ----------------------------------- ----
thank upstairs master , just tried to change if [$?-ne 0] then an operation will restart apache, as long as there is not an error error_log OK will restart ?

There is no way to simulate open a page , such as php / var / www / html / check.html
then parse the page header information returned is 302 or 500 , if the return 500 to restart it ?
------ For reference only ------------------------------------ ---

curl can simulate the behavior of the browser .
------ For reference only -------------------------------------- -


shell can also simulate curl it ?
I know php can , the problem is apache is dead , can not run curl up .
------ For reference only -------------------------------------- -

  
shell can also simulate curl it ?   
I know php can , the problem is apache is dead , can not run curl up .  
Oh, that with php simulations , this one I would not use .
Your monitoring scripts do not run alone ?
I understand the wording something like this:

1. curl-v 127.0.0.1/check.html
2. According to curl output judge
------ For reference only -------------------------- -------------


This is indeed a way , you can create a blank page http://www.mydomain.com/check.php

then curl-v http://www.mydomain.com/check.php see if it is connection timeout ? Half empty pages, 1 second or less will be returned.

but the specific shell how to write it ? Not to write .
------ For reference only -------------------------------------- -

not .
It is based on the existence of the httpd process to decide whether to restart , with the error_log without a dime .
------ For reference only -------------------------------------- -
pgrep httpd
if [$?-ne 0]; then service httpd restart; fi
httpd does not exist, then restart the httpd service
------ For reference only ------------------------ ---------------


Awesome code, it works .

curl -I http://www.mydomain.com/check.php 2>/dev/null | head -1 | grep -q " 200 OK"
if [ $? -eq 0 ]; then echo ""; else service httpd restart; fi

没有评论:

发表评论