Knowledgebase

How to restart apache when idle

Posted by luckwaski, 06-29-2011, 08:42 AM
Hey there, I found a bunch of scripts that restarts httpd when it's under high load. I would like to aproach it from other way: restart apache only if there is no ongoing php processes. I know that there's that -graceful thing - which actually still kills loading of some php scripts in fcgi. It would be great if I could run some script every like 2 minutes which checks if server is busy and restarts if it's iddle. I know that that might not work in the middle of the day when server is busiest but whatever - not a problem. Thanks!

Posted by sahabcse, 06-29-2011, 01:53 PM
I can write script for you.. Please let me know your offer

Posted by krizag, 06-29-2011, 04:54 PM
you need to write custom script for this.Did you have any experience in scripting?

Posted by luckwaski, 06-29-2011, 05:50 PM
Nop - unfortunatelly I don't. How hard would that be?

Posted by m4rc3, 06-29-2011, 06:00 PM
it shouldn't be too hard to script something like that but why do you want to restart apache when it's idle ? Last edited by m4rc3; 06-29-2011 at 06:00 PM. Reason: typo

Posted by luckwaski, 06-29-2011, 06:05 PM
Why do I wan't to restart it while idle? Frankly - I want it to handle recently added domains. I don't wanna wait till next day (while it restart 2am) or to restart in the middle of some long php query. Any idea how to get (trustworth) list/number of ongoing processes in fastcgi?

Posted by m4rc3, 06-29-2011, 06:11 PM
but wouldn't a simple reload work for you? I mean it will reload the config thus loading your newly added domains without actually shutting down the server

Posted by luckwaski, 06-29-2011, 06:21 PM
Yes - it will reload config etc. - but also it will break ongoing connections (imagine php script that uses some external api with curl - sometimes it takes 30 seconds to finish it) and I can't afford that. And don't mention -graceful - it's total disaster - I've don tests and that's even worse that hard-reset

Posted by luckwaski, 06-30-2011, 08:28 AM
Give me your e-mail pls.

Posted by Stratogen, 06-30-2011, 08:59 AM
The problem is going to be what you class as idle - the HTTP server may be idle waiting for one of your CURL scripts, but you still wouldn't want to restart it. I would suggest automating the 2am restart of the HTTP server which would be a trivial entry in cron.

Posted by luckwaski, 06-30-2011, 09:05 AM
Yea I know - that's the problem. How can I say that php is not working at the moment? And I would like to restart httpd more often - so clients wont have to wait for their domains to resolve.

Posted by Stratogen, 06-30-2011, 09:16 AM
There is a thread at http://www.webhostingtalk.com/showthread.php?t=673467 that discusses monitoring the number of active connections to port 80 which would do the trick. If the script outputs nothing then you are clear to restart.

Posted by viGeek, 06-30-2011, 10:29 AM
Here is something simple that should help get you started, assuming you want to do it based on connections. Wanted to add, instead of grabbing the return $?. Perhaps would be better to verify the pid exists. i.e [ -f /var/run/httpd.pid ]

Posted by luckwaski, 06-30-2011, 10:53 AM
Thanks guys! I'll give it a try - and gonna let you know what worked for me.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Telnap.com is down? (Views: 582)
about mysql server (Views: 631)
Script to rename files (Views: 573)


Language:

Client Login

Email

Password

Remember Me

Search