Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a VPS host that every once in a while (I'm talking 3-4 weeks, maybe) will briefly kill apache to test problems on the box. For some reason, their CPanel customers come back right away when they're done testing, but people like me who didn't want to pay 9.95/mo extra for CPanel are left to notice my site is down and go in and restart it myself.

Barring the obvious (changing VPS hosts), is there a script to run that will check on, say, 5 minute intervals to see if apache has been stopped, and if it has, to restart it?

I'm running CentOS.

share|improve this question
Edit: I should clarify that I'm not sure if "keep-alive" is really the right term I should be using here. – scraft3613 Nov 21 '09 at 17:18
Yeah, I don't think "keep-alive" is what you wanted there; I've edited the title to hopefully be more appropriate. – womble Nov 21 '09 at 17:27
up vote 3 down vote accepted

What the hell? This is the most utterly insane thing I have ever heard of. I think these clowns need to be named and shamed... killing off a customer's running software to "test problems on the box"? Words fail me.

Simple script (run it every minute via cron):


service httpd status >/dev/null || service httpd start >/dev/null

And yes, I'd be running (not walking) to a new VPS provider.

share|improve this answer
Thanks for fixing the title and for the script womble, and yes, I'll be talking to the accounts folks and making the change to a new company soon. – scraft3613 Nov 21 '09 at 20:07
so - we've established you don't like monit. what alternatives for it do you suggest except one-liners [ which are ok, but sometimes it's better to use something standardized that provides nice framework ]. and what horror stories about monit can you tell? it has done the trick for me. – pQd Nov 21 '09 at 20:13
Also, thought you might enjoy to see their fairly canned response to my tickets about their behavior: "There were temporary network issues which have been resolved by now. Apache service was stopped by us during investigation of the real reason of traffic peak. cPanel software automatically restart service when it`s down, so there is no need to worry." When I of course responded that I was not on CPanel (something they should have clearly seen on their end), they replied "we do not provide script/code debugging support." – scraft3613 Nov 21 '09 at 20:15
@pQd: Daemontools for simple "this should be running no matter what"; Nagios with service handlers for more complicated stuff. – womble Nov 21 '09 at 20:49
@pQd: My problems with monit are both philosophical (bad design), and practical -- it frequently loses track of a service (thinks it's down when it's not, as well as thinks it's up when it's not), decides it's going to stop monitoring something and not mention it to anyone, doesn't quickly detect that an attempt to start something failed, and it's annoying habit of only polling things once a minute (or more) makes for lengthy downtimes. It's documentation is poor, and it's model is unintuitive and violates the principle of least surprise. – womble Nov 21 '09 at 20:49

I like womble's suggestion of running apache under daemontools or runit. These tools will restart a failed or killed process immediately. Not only will it make sure your apache process runs no matter what, it will probably confuse the hell out of the techs at your clue-challenged provider

share|improve this answer

you can as well take a look at monit - quite flexible software watchdog that can monitor / restart many other services & notify you whenever any action was taken.

share|improve this answer
If you value your sanity, you will avoid monit like the plague. It is an ill-concieved and poorly-implemented piece of software, that does nothing that other systems don't do a hell of a lot better. – womble Nov 21 '09 at 18:14

With such a host, I would use external monitoring, too. and AlertFox are both good and have useful free plans.

share|improve this answer

launchd. Use it to both load and maintain services.

share|improve this answer
From the question: "I'm running CentOS". The wikipedia(?!?) page you linked to gives no indication that launchd is available for any platform other than OS X. – womble Nov 22 '09 at 0:33
"open source" should be enough … – Nerdling Nov 22 '09 at 6:04

Your Answer


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.