[PATCH] Variable for vcl_dir in startup scripts

Delacroix, Gauthier Gauthier.Delacroix at coreye.fr
Tue Jun 23 18:15:28 CEST 2015


This commit (https://github.com/varnish/Varnish-Cache/commit/09c93b40c1820faf564ec7e39bfaccad6ca88343) added a syntax check when starting the varnish service, but it didn't take into account the fact that the config could setup a vcl_dir where relative includes are stored.

My proposal is to add a startup variable for the vcl_dir, so that the syntax check works with a different vcl_dir.

It seems to work fine with old config files with undefined VARNISH_VCL_DIR and absolute path in VARNISH_VCL_CONF so it's not really a breaking change, even if working with an old config file would make a dirty start command.

Gauthier

---
 redhat/varnish.initrc    |  6 +++---
 redhat/varnish.params    |  5 ++++-
 redhat/varnish.service   |  7 +++++--
 redhat/varnish.sysconfig | 10 +++++++---
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/redhat/varnish.initrc b/redhat/varnish.initrc
index 117e334..d1c6691 100755
--- a/redhat/varnish.initrc
+++ b/redhat/varnish.initrc
@@ -125,10 +125,10 @@ rh_status_q() {
 }
 
 configtest() {
-    if [ -f "$VARNISH_VCL_CONF" ]; then
-        $exec -f "$VARNISH_VCL_CONF" -C -n /tmp > /dev/null && echo "Syntax ok"
+    if [ -f "${VARNISH_VCL_DIR}/${VARNISH_VCL_CONF}" ]; then
+        $exec -f "${VARNISH_VCL_DIR}/${VARNISH_VCL_CONF}" -p vcl_dir="${VARNISH_VCL_DIR}" -C -n /tmp > /dev/null && echo "Syntax ok"
     else
-	echo "VARNISH_VCL_CONF is  unset or does not point to a file"
+	echo "VARNISH_VCL_CONF is  unset or does not point to a file in VARNISH_VCL_DIR"
     fi
 }
 
diff --git a/redhat/varnish.params b/redhat/varnish.params
index 27a14dd..5f2a357 100644
--- a/redhat/varnish.params
+++ b/redhat/varnish.params
@@ -4,8 +4,11 @@
 # Set this to 1 to make systemd reload try to switch vcl without restart.
 RELOAD_VCL=1
 
+# Main configuration directory.
+VARNISH_VCL_DIR=/etc/varnish
+
 # Main configuration file. You probably want to change it.
-VARNISH_VCL_CONF=/etc/varnish/default.vcl
+VARNISH_VCL_CONF=default.vcl
 
 # Default address and port to bind to. Blank address means all IPv4
 # and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
diff --git a/redhat/varnish.service b/redhat/varnish.service
index a4f3355..3d070ed 100644
--- a/redhat/varnish.service
+++ b/redhat/varnish.service
@@ -27,10 +27,12 @@ EnvironmentFile=/etc/varnish/varnish.params
 Type=forking
 PIDFile=/var/run/varnish.pid
 PrivateTmp=true
-ExecStartPre=/usr/sbin/varnishd -C -f $VARNISH_VCL_CONF
+ExecStartPre=/usr/sbin/varnishd -C \
+	-f ${VARNISH_VCL_DIR}/${VARNISH_VCL_CONF} \
+	-p vcl_dir=${VARNISH_VCL_DIR}
 ExecStart=/usr/sbin/varnishd \
 	-P /var/run/varnish.pid \
-	-f $VARNISH_VCL_CONF \
+	-f ${VARNISH_VCL_DIR}/${VARNISH_VCL_CONF} \
 	-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
 	-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
 	-t $VARNISH_TTL \
@@ -38,6 +40,7 @@ ExecStart=/usr/sbin/varnishd \
 	-g $VARNISH_GROUP \
 	-S $VARNISH_SECRET_FILE \
 	-s $VARNISH_STORAGE \
+	-p vcl_dir=${VARNISH_VCL_DIR}
 	$DAEMON_OPTS
 
 ExecReload=/usr/sbin/varnish_reload_vcl
diff --git a/redhat/varnish.sysconfig b/redhat/varnish.sysconfig
index 6aa2354..1ad7f1a 100644
--- a/redhat/varnish.sysconfig
+++ b/redhat/varnish.sysconfig
@@ -56,8 +56,11 @@ RELOAD_VCL=1
 #
 # See varnishd(1) for more information.
 #
+# # Main configuration directory.
+VARNISH_VCL_DIR=/etc/varnish
+#
 # # Main configuration file. You probably want to change it :)
-VARNISH_VCL_CONF=/etc/varnish/default.vcl
+VARNISH_VCL_CONF=default.vcl
 #
 # # Default address and port to bind to
 # # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
@@ -94,7 +97,7 @@ VARNISH_TTL=120
 # # DAEMON_OPTS is used by the init script.  If you add or remove options, make
 # # sure you update this section, too.
 DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
-             -f ${VARNISH_VCL_CONF} \
+             -f ${VARNISH_VCL_DIR}/${VARNISH_VCL_CONF} \
              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
              -t ${VARNISH_TTL} \
              -p thread_pool_min=${VARNISH_MIN_THREADS} \
@@ -102,7 +105,8 @@ DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
              -p thread_pool_timeout=${VARNISH_THREAD_TIMEOUT} \
              -u varnish -g varnish \
              -S ${VARNISH_SECRET_FILE} \
-             -s ${VARNISH_STORAGE}"
+             -s ${VARNISH_STORAGE}" \
+             -p vcl_dir=${VARNISH_VCL_DIR}
 #
 
 
-- 
1.8.3.1





More information about the varnish-dev mailing list