Skip to content

Instantly share code, notes, and snippets.

@tomazzaman
Last active September 22, 2016 08:23
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tomazzaman/13da35056017d7b8cf00 to your computer and use it in GitHub Desktop.
Save tomazzaman/13da35056017d7b8cf00 to your computer and use it in GitHub Desktop.
Restart HHVM with Monit
# This file should be in /etc/monit/conf.d
check process hhvm with pidfile /var/run/hhvm/pid
group hhvm
# Start program calls our custom script from above
start program = "/usr/local/sbin/start_hhvm.sh"
stop program = "/usr/sbin/service hhvm stop"
if failed unixsocket /var/run/hhvm/hhvm.sock then restart
if mem > 400.0 MB for 1 cycles then restart
if 5 restarts with 5 cycles then timeout
#!/bin/bash
# This file should be saved in /usr/local/sbin
# It must exist because sometime a crashed process
# leaves a socket behind, rendering it unstartable
# So what we do is test whether the socket file
# leftover is there and delete it. Also, make sure
# this file is executable: $ chmod +x start_hhvm.sh
SOCKET=/var/run/hhvm/hhvm.sock
if [ -e $SOCKET ];
then
rm -f $SOCKET
fi
/usr/sbin/service hhvm start
exit 0;
@yustein
Copy link

yustein commented Apr 17, 2015

thanks 😄

@yustein
Copy link

yustein commented Apr 19, 2015

I had to change the

/usr/sbin/service hhvm start

to

/usr/sbin/service hhvm restart

otherwise the service would not restart according to my log files..

@yustein
Copy link

yustein commented Apr 19, 2015

Interesting, if I don't issue the

sudo monit monitor hhvm

it does not monitor it, if hhvm is not fast enough after a reboot to start before monit, and monit can't find the service pid could that be the reason?

@fa8ster
Copy link

fa8ster commented May 11, 2015

Do you know why HHVM is always just having the status "Initializing" if i do a monitor all?

rocess 'nginx'
status Running
monitoring status Monitored
pid 13469
parent pid 1
uptime 58m
children 8
memory kilobytes 2764
memory kilobytes total 67452
memory percent 0.0%
memory percent total 0.2%
cpu percent 0.0%
cpu percent total 0.0%
port response time 0.000s to 127.0.0.1:80 [DEFAULT via TCP]
data collected Mon, 11 May 2015 08:44:15

_Process 'hhvm'
status Connection failed
monitoring status Monitored
_
pid 0
parent pid 0
uptime 0m
children 0
memory kilobytes 0
memory kilobytes total 0
memory percent 0.0%
memory percent total 0.0%
cpu percent 0.0%
cpu percent total 0.0%
unix socket response time 0.000s to /var/run/hhvm/hhvm.sock [DEFAULT]
data collected Mon, 11 May 2015 08:44:16

System 'm42mpprod01.m42mpprod.a7.internal.cloudapp.net'
status Running
monitoring status Monitored
load average [1.17] [1.20] [1.14]
cpu 3.6%us 0.9%sy 2.1%wa
memory usage 833084 kB [2.8%]
swap usage 0 kB [0.0%]
data collected Mon, 11 May 2015 08:44:16

@fabricek
Copy link

We don't need this script cause monit check the process id in the pid file. So considered as fail if it's not the right pidfile.
From monit :
is the absolute path to the program's pid-file. A pid-file is a file, containing a Process's unique ID. If the pid-file does not exist or does not contain the PID number of a running process, Monit will call the entry's start method if defined.

@Seb-
Copy link

Seb- commented Aug 17, 2016

For the record, I've had success with using the "restart" /usr/sbin/service hhvm restart into the "start program" directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment