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

October 31, 2014 3.3k views

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?

3 Answers

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.

OOM killer, you ran out of memory.

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.

Have another answer? Share your knowledge.