Author |
|
Kanashii
Joined: 17 Jul 2006 Posts: 155 Location: Porando
|
Posted: Sun 05 Sep '10 18:27 Post subject: Apache Watchdog |
|
|
Somtimes my httpd just crash php-cgi.exe stop and i had 503 error so i create a simple script that check is php is runing. Cant be modified to check is httpd.exe process runing not php-cgi.exe
Requirement PATH to php.exe
Quote: |
@echo off
:loop
timeout /t 30 /nobreak
REM #> NUL
echo .
tasklist /FI "IMAGENAME eq php-cgi.exe" 2>NUL | find /I /N "php-cgi.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
:Process_Found
timeout /t 20 /nobreak > NUL
goto END
:Process_NotFound
TASKKILL /F /IM php-cgi.exe
%PATH_TO_HTTPD%\httpd -n Apache -k stop
TASKKILL /F /IM httpd.exe
%PATH_TO_HTTPD%\httpd -n Apache -k start
ping 127.0.0.1 -n 3
cls
php.exe -r "$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://webpage.url/'); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch);"
REM ping 127.0.0.1 -n 2
goto END
:END
goto loop
|
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Wed 15 Sep '10 22:16 Post subject: |
|
|
I like that script. Do you run it over the task scheduler? |
|
Back to top |
|
Kanashii
Joined: 17 Jul 2006 Posts: 155 Location: Porando
|
Posted: Thu 16 Sep '10 1:47 Post subject: |
|
|
Sorry for long time response i whose in datacenter
I run just script on my server on local accaunt
hmm noo need to run from cron [task] its loping and check erery 30 second
or just run once on specyfi accaunt: runas.exe /user:accaut_name scriptname.bat
on windows xp home need to copy program tasklist from xp pro to system32 directory to run |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Thu 16 Sep '10 11:58 Post subject: |
|
|
Well at least on the company pc with XP there is not <b>timeout</b> on my win7 it works fine. |
|
Back to top |
|
Kanashii
Joined: 17 Jul 2006 Posts: 155 Location: Porando
|
Posted: Thu 16 Sep '10 14:19 Post subject: |
|
|
try
ping 127.0.0.1 -n 30 |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Thu 16 Sep '10 15:27 Post subject: |
|
|
Well than it is also better to push the output into the nirvana as with timeout
ping 127.0.0.1 -n 30 > nul |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Thu 23 Sep '10 23:32 Post subject: |
|
|
I had an idea to use php function sleep instead of ping if there is no timeout since the script already uses php.
One more question, why don't you use -k restart? |
|
Back to top |
|
Kanashii
Joined: 17 Jul 2006 Posts: 155 Location: Porando
|
Posted: Fri 24 Sep '10 17:08 Post subject: Re: Apache Watchdog |
|
|
I had an idea to use php function sleep instead of ping if there is no timeout since the script already uses php.
php use lot of memory eq from 4 to event 8mb
sleep use kb not MB
but is possible this is concept you can modified as well
Quote: | One more question, why don't you use -k restart? |
In my cfg is better to kill php-cgi and kill Apache instance and start again
I had 100000 request until php-cgi.exe [ wincache not flush memory ] will be restart, so if Apache fail better is to stop, kill and run again
Maybe a some modification
TASKKILL /F /IM php-cgi.exe
%PATH_TO_HTTPD%\httpd -n Apache -k stop
TASKKILL /F /IM httpd.exe
%PATH_TO_HTTPD%\httpd -n Apache -k start
###
To
###
TASKKILL /F /IM php-cgi.exe
%PATH_TO_HTTPD%\httpd -n Apache -k restart
##
timeout /t 5 /nobreak > NUL
Check is Apache still ruining [ php script and some eq request to graphic ] if not do old code witch - stop and -start
----------
of course -restart in you situation will be better idea eq all request to apache still response not 3 - 4 second offline |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
Posted: Sat 25 Sep '10 12:03 Post subject: |
|
|
Well if there is a need for high accessibility I use a load balancer where I can restart the backend servers one after another. With enough RAM it is also possile to do that on one server apaches listing on different ports.
of cause ideal it is to have two loadbalancers. One in hot standby the other serving the requests. Each with a bunch of backend server behind with real hardware. |
|
Back to top |
|
Kanashii
Joined: 17 Jul 2006 Posts: 155 Location: Porando
|
Posted: Wed 29 Sep '10 0:46 Post subject: |
|
|
Some modification for difrent OS
IF %allusersprofile%"=="C:\ProgramData"
timeout /t 20 /nobreak > NUL
ELSE
ping 127.0.0.1 -n 20 > nul
ENDIF
if i had time in weekend i try to make some extended version
eq
Check is page alive sometimes some php-cgi.exe freezing for one of host
[warn] [client XX.XX.XXX.XXX] mod_fcgid: read timeout from pipe
[warn] [client XX.XX.XXX.XXX] mod_fcgid: can't apply process slot for
Auto Block scanners witch add to baned IP firewall { need be check fast for fast block }
[error] [client XX.XX.XXX.XXX] client sent HTTP/1.1 request without hostname cv (see RFC2616 section 14.23): /w00tw00t.at.ISC.SANS.DFind:)
[error] katalogowanie [client XX.XX.1XX.XX] File does not exist: X:/X/X/phpmyadmin
[error] [client 187.45.214.10] client sent HTTP/1.1 request without hostname |
|
Back to top |
|