logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> How-to's & Documentation & Tips View previous topic :: View next topic
Reply to topic   Topic: Apache Watchdog
Author
Kanashii



Joined: 17 Jul 2006
Posts: 155
Location: Porando

PostPosted: Sun 05 Sep '10 18:27    Post subject: Apache Watchdog Reply with quote

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

PostPosted: Wed 15 Sep '10 22:16    Post subject: Reply with quote

I like that script. Do you run it over the task scheduler?
Back to top
Kanashii



Joined: 17 Jul 2006
Posts: 155
Location: Porando

PostPosted: Thu 16 Sep '10 1:47    Post subject: Reply with quote

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

PostPosted: Thu 16 Sep '10 11:58    Post subject: Reply with quote

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

PostPosted: Thu 16 Sep '10 14:19    Post subject: Reply with quote

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

PostPosted: Thu 16 Sep '10 15:27    Post subject: Reply with quote

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

PostPosted: Thu 23 Sep '10 23:32    Post subject: Reply with quote

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

PostPosted: Fri 24 Sep '10 17:08    Post subject: Re: Apache Watchdog Reply with quote

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

PostPosted: Sat 25 Sep '10 12:03    Post subject: Reply with quote

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

PostPosted: Wed 29 Sep '10 0:46    Post subject: Reply with quote

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


Reply to topic   Topic: Apache Watchdog View previous topic :: View next topic
Post new topic   Forum Index -> How-to's & Documentation & Tips