Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Created April 22, 2020 16:46
Show Gist options
  • Save eksiscloud/0b9167c29af8696f773cc7ee1894bb8e to your computer and use it in GitHub Desktop.
Save eksiscloud/0b9167c29af8696f773cc7ee1894bb8e to your computer and use it in GitHub Desktop.
Monit: Varnish
# Varnish
check program varnishpanic with path "/bin/varnishadm panic.show"
if status != 1 then alert
check process varnish with pidfile /var/run/varnish.pid
#start program = "/etc/init.d/varnish start" with timeout 30 seconds
#stop program = "/etc/init.d/varnish stop"
start program = "/usr/bin/systemctl start varnish" with timeout 30 seconds
stop program = "/usr/bin/systemctl stop varnish"
if failed host 127.0.0.1 port 81 protocol http
and request "/monit-zxcvb"
then restart
if 3 restarts within 5 cycles then timeout
@eksiscloud
Copy link
Author

eksiscloud commented Apr 22, 2020

Heads up with port 81. You may use another port.

/monit-zxcvb mut be unique and not in public use. Make an empty file in the web-dir of the alphabetically very first virtual host you have in use.

touch /var/www/html/monit-zxcvb

Varnish must have varnish.pid or varnishd.pid
ls /var/run

If not, then:

systemctl edit --full varnish

Find the line beginning: ExecStart=/usr/sbin/varnishd

Add this: -P /var/run/varnish.pid

nano /etc/varnish/monit.vcl

Add this:

sub vcl_recv {
if (req.url == "/monit-zxcvb") {
return(synth(200, "OK"));
}
}

nano /etc/varnish/default.vcl

add this after vcl 4.1: and before backend default {

Monit include "/etc/varnish/monit.vcl";

systemctl restart varnish

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