Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

On Windows, you can set what should happen if/when a service fails. Is there a standard way of achieving the same thing on Linux (CentOS in particular)?

A bigger part of my question is: how do you handle sockets that have been left open - for example in TIME_WAIT, FIN_WAIT1, etc states.

At the moment if the service I am developing crashes, I have to wait for the sockets to clear or change the listen port before I can then manually restart it.

Thanks for your help.

share|improve this question
up vote 15 down vote accepted

monit is a great way to monitor and restart services when they fail--and you'll probably end up using this for other essential services (such as Apache). There's a nice article on nixCraft detailing how to use this for services specifically, although monit itself has many more functions beyond this.

As for the socket aspect, @galraen answered this spot on.

share|improve this answer
It's a shame I have to decide which is the answer. I should have asked two seperate questions. @gelraen your answer just ended my weeks of searching for a solution. Thanks you so much! @Redmumba thanks, Monit does look good! – Pryo Mar 26 '11 at 14:01
Whichever one you decide to mark correct, definitely upvote @gelraen's answer. Its spot on correct, and very informative. – Andrew M. Mar 26 '11 at 16:15

You can call setsockopt(2) for listening socket with SO_REUSEADDR, so you will be able to bind(2) it again without waiting for expiring all connections. Another possibility: drop connections from kernel. FreeBSD have tcpdrop command for this, don't know about Linux.

share|improve this answer

If your linux distro uses Upstart instead of SysV init, then the respawn keyword does this.

share|improve this answer
Thanks, this looks like just the thing, but unfortunately I'm stuck with SysV init. – Pryo Mar 26 '11 at 14:07

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.