Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

For development purposes, I'm running an Apache server on my windows machine. Its very non-critical, but sometimes I'll be running processes that take a long time and Apache will stop server requests. Restarting the Apache service works just fine when this happens.

Is there a script out there somewhere that can detect if Apache is failing to load pages and then restart the service if it is?

It would probably look something like this:

LOAD localhost/index.php
IF LOAD FAILED:
   RESTART APACHE SERVICE
share|improve this question
    
" I'll be running processes that take a long time and Apache will stop server requests. " Is this with respect to Apache? Or are you referring to other external process which place highload on your machine, blocking Apache? –  Jason Huntley Apr 4 '12 at 20:14
    
They place maybe a medium load on the machine. Apache seems to be locking up periodically due to whatever is going on. Sometimes it crashes, sometimes it just stops servicing requests. –  Chris Dutrow Apr 5 '12 at 2:07

1 Answer 1

up vote 3 down vote accepted

You can do it externally with WGet.exe and the scheduler service:

wget -o:foo http://localhost/page_of_interest.php || powershell.exe restart-service apache

Not sure which OS you're using, so YMMV with this task scheduler config:

Assume your batch script is called c:\bin\files\ca.cmd, type this at the command line:

schtasks.exe /create /u administrator /p password /sc minute /mo 2 /tn "Check Apache every 2 minutes" /tr c:\bin\files\ca.cmd
share|improve this answer
    
That's awesome, thanks so much! Do you know how I could set this command to run every minute or so? –  Chris Dutrow Apr 5 '12 at 2:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.