I am trying to learn the best practices for checking that Apache and Postgres are running on my server. If either of them have stopped, I want to auto-restart these services. I'm using Ubuntu 12.04 LTS.

My strategy, was to write a cron job that checked that both of these services were alive every 5 minutes, and if they are not, to restart them (and to email me that there was a problem).

I'm unsure if there is a better way to do this. I currently use Fabric to administer the server remotely; and was also wondering if trying to write this all in Python could be an appropriate approach.

2 Answers 2


Monitoring tools like Zenoss, Nagios, etc, would be better for sure. But if you have like 1 server, they could be overkill.

For Apache, check that you can get a page with wget. For Postgres - well, you can run a query with psql.

Not sure why you are worried about restarting them. I have PostgreSQL and Apache servers which have been running for 5+ years without ever needing to be restarted (except to install updates). These are professional product, they don't just die.


Monit does exactly what you want to do, in a more standardized manner. I suggest you use it instead of rolling your own solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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