summaryrefslogtreecommitdiff
path: root/extra/varnish/varnish-vcl-reload
blob: 7e84a258bf3e90bb1ea470d4fcc12a2d9880d550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

cfg=${1:-/etc/varnish/default.vcl}
if [ ! -e "$cfg" ]; then
  printf 'ERROR: VCL file %s does not exist\n' "$cfg" >&2
  exit 1
fi

activecfg=$(varnishadm 'vcl.list' | awk '/active/ { print $3 }')
if [ -z "$activecfg" ]; then
  printf 'ERROR: No active VCL found!\n' >&2
  exit 1
fi

newcfg=$(date +'vcl-%s')
printf 'INFO: using new config %s\n' "$cfg"

varnishadm "vcl.load $newcfg $cfg" &&
varnishadm "vcl.use $newcfg" &&
varnishadm "vcl.discard $activecfg"