Automatically starting HHVM (or any other service, really) when it's not running?

So I have a small droplet that I run a few small WordPress sites on with Nginx, HHVM, MySQL, etc.

Once a week or so, seemingly randomly, I visit sites on the server and am greeted with a “502 Bad Gateway” error from Nginx. When I investigate further in SSH, I discover that HHVM is not running.

I simply run the “sudo service hhvm start” command and everything comes up and running again.

So I have a couple questions:

  1. Is there any reason why HHVM would suddenly stop running like I’ve described? I believe I have it included in my boot sequence and I regularly update all my packages.

  2. Is there a way to run an automated check, maybe once every five minutes or so to check if HHVM is running, and if not, starting it?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I wrote a bash script for a similar thing ( apache and mysql ). You could easily rewrite it for other services:

It even sends you an email letting you know the service that was restarted.

For an automated check, you could use a bash script. I’d force it to run “service hhvm status” and grep for running / not running.

If it came back with “not running” for example, you could restart it with “service hhvm restart”.

This may be of some use to you

I’m not very good with bash, but this would be the path I would try to use

Sorry I couldn’t be of more help.

OOM killer, you ran out of memory.