Portal Home > Knowledgebase > Articles Database > how do I automatically restart httpd on http time out?


how do I automatically restart httpd on http time out?




Posted by Ogg, 02-10-2007, 07:45 PM
So this morning my httpd started timing out but the service itself was running. All the other services were running fine except for httpd. Unfortunately, I didn't notice this til about 5 hours later! Does anyone have any ideas on how to get the httpd service restarted automatically if it's timed out for say, 5 minutes in a row? I'm sure I can do this somehow with a cron job but what code would I need to run/is it safe to allow a service restart command in a script?

Posted by horizon, 02-10-2007, 08:19 PM
As a first step, you could apply the following command in your console (also depending on the distribution you installed): or:

Posted by Ogg, 02-11-2007, 12:43 AM
Oh the service is running fine now, I restarted it before I posted here. I was just hoping that someone had a way of restarting the service automatically if it started timing out.

Posted by Xeentech, 02-11-2007, 01:27 AM
When you say the HTTPd is 'timing out', what do you mean. You can't load the site because the connection times out? Thats the only thing I can think.. If thats the case, first that shouldn't be happening. This is why Apache pre-forks and the children only live so long so you should try and work out why your HTTPd does this.. What you could do is setup a cron to test your site every so often and restart the httpd if the command fails. Personally I'd do it in perl with the LWP lib becuse you can set the connection timeout to something low like 5 seconds. You could do this in any language though. You could do it in sh/bash with wget, if the wget fails restart httpd.

Posted by layer0, 02-11-2007, 09:59 AM

Posted by Barti1987, 02-11-2007, 11:47 AM
I would do the above in a loop until it is restarted. If you are using directadmin, the service will need to be restarted a couple of times until it wakes up Peace,

Posted by Ogg, 02-12-2007, 04:46 PM
I'll give that a try! Thanks guys, you rock.

Posted by KansasHosting, 01-22-2012, 12:45 PM
I know this thread is old but I hate when an old thread comes up first in a google search but has a poor answer. You want to run daemon tools with supervise scripts. MAN: http://cr.yp.to/daemontools.html How to: http://mailman.linuxchix.org/piperma...il/018220.html

Posted by jdilegge, 01-23-2012, 03:07 PM
Layer0's solution is perfect. Though if you have cPanel, you can set monitoring in your WHM under SERVICES.

Posted by CoderJosh, 01-23-2012, 03:13 PM
monit works great for monitoring all kinds of services, and restarting them if they crash or hang.

Posted by josephgarbett, 01-24-2012, 04:44 AM
A little dangerous restarting apache all the time? Surely its better to solve the problem then to just quick-fix it every time?

Posted by SunShellHosting, 01-24-2012, 08:40 AM
Hi You can use freeware monitoring program such as Monit to monitor apache and restart it if it is down http://blog.vivekv.com/installing-mo...matically.html

Posted by jdilegge, 01-24-2012, 10:18 AM
It's not dangerous at all. In fact most control panels like plesk auto restart in preset increments. However you are right, the issues should be fixed. The causes can typically be found in the apache error log(s) and using apachectl, you can see any issues straight away most of the time. My guess would be memory related or module related. Last edited by jdilegge; 01-24-2012 at 10:19 AM. Reason: typo

Posted by HostingBig, 01-24-2012, 10:22 AM
rfx networks has built a script to monitor all your services http://www.rfxn.com/projects/system-integrity-monitor/

Posted by viGeek, 01-25-2012, 01:49 PM
Something like this. I would more than likely loop until the site becomes response, then exit the script. This is just a very rough copy to show you an example, should have considerably more error handling.

Posted by hodgeemory, 01-28-2012, 03:11 AM
Monit conducts automatic maintenance and repair and can execute .... protocol http then restart group server depends on httpd.conf, httpd.bin check



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
BitNinja (Views: 537)
turn-key resellers (Views: 486)