[PATCH] Allow varnish_reload_vcl to discard old VCL after reload

Delacroix, Gauthier Gauthier.Delacroix at coreye.fr
Wed Nov 19 10:10:09 CET 2014


This patch allows varnish_reload_vcl to discard old (available) VCL
configurations after reload. DISCARD_OLD_VCL environment variable must be set
to 1. It is set to 0 by default to avoid unexpected behavior change.
---
 redhat/varnish.params     |  5 +++++
 redhat/varnish.sysconfig  |  5 +++++
 redhat/varnish_reload_vcl | 15 ++++++++++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/redhat/varnish.params b/redhat/varnish.params
index 636e975..09516c1 100644
--- a/redhat/varnish.params
+++ b/redhat/varnish.params
@@ -4,6 +4,11 @@
 # Set this to 1 to make systemd reload try to switch vcl without restart.
 RELOAD_VCL=1

+# Set this to 1 to make init script reload try to discard old
+# VCL configurations after reload.
+# To make this work, you need to set RELOAD_VCL variable to 1.
+DISCARD_ON_RELOAD=0
+
 # Main configuration file. You probably want to change it.
 VARNISH_VCL_CONF=/etc/varnish/default.vcl

diff --git a/redhat/varnish.sysconfig b/redhat/varnish.sysconfig
index 6aa2354..c532695 100644
--- a/redhat/varnish.sysconfig
+++ b/redhat/varnish.sysconfig
@@ -24,6 +24,11 @@ NPROCS="unlimited"
 # use Alternative 3, Advanced configuration, below
 RELOAD_VCL=1

+# Set this to 1 to make init script reload try to discard old
+# VCL configurations after reload.
+# To make this work, you need to set RELOAD_VCL variable to 1.
+DISCARD_ON_RELOAD=0
+
 # This file contains 4 alternatives, please use only one.

 ## Alternative 1, Minimal configuration, no VCL
diff --git a/redhat/varnish_reload_vcl b/redhat/varnish_reload_vcl
index be3c21a..c686541 100755
--- a/redhat/varnish_reload_vcl
+++ b/redhat/varnish_reload_vcl
@@ -10,7 +10,7 @@
 # The following environment variables have to be set:
 # RELOAD_VCL, VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_PORT
 # The following are optional:
-# VARNISH_SECRET_FILE, VARNISH_ADMIN_LISTEN_ADDRESS
+# VARNISH_SECRET_FILE, VARNISH_ADMIN_LISTEN_ADDRESS, DISCARD_ON_RELOAD
 #
 # Requires GNU bash and GNU date
 #
@@ -26,6 +26,7 @@ print_debug() {
        echo "
 Parsed configuration:
 RELOAD_VCL=\"$RELOAD_VCL\"
+DISCARD_ON_RELOAD=\"$DISCARD_ON_RELOAD\"
 VARNISH_VCL_CONF=\"$VARNISH_VCL_CONF\"
 VARNISH_ADMIN_LISTEN_ADDRESS=\"$VARNISH_ADMIN_LISTEN_ADDRESS\"
 VARNISH_ADMIN_LISTEN_PORT=\"$VARNISH_ADMIN_LISTEN_PORT\"
@@ -108,6 +109,18 @@ else
        echo "$VARNISHADM vcl.use failed"
        exit 1
 fi
+
+if [ "$DISCARD_ON_RELOAD" = "1" ]; then
+       $VARNISHADM vcl.list | grep "^available" | awk '{ print $3 }' | while read old_config; do
+               if $VARNISHADM vcl.discard $old_config > /dev/null; then
+                       echo "VCL '$old_config' discarded"
+                       $debug && echo "$VARNISHADM vcl.discard succeded"
+               else
+                       echo "$VARNISHADM vcl.discard failed"
+                       exit 1
+               fi
+       done
+fi
 $VARNISHADM vcl.list
 echo Done
 exit 0
--
1.8.3.1



More information about the varnish-dev mailing list