varnishadm(1) supports `vcl.load' and `vcl.use' for the obvious use
cases of changing configuration at runtime without restarting the daemon.

Upstream has no more advanced tooling for "reload the config" as in
"reread VCL from disk and activate" so other downstreams have been
shipping scripts to do that.

Here's my version that follows the same common idea of loading the
configuration under a name that has time information in it to avoid
naming collisions.

It's dead simple and allows me to just `rcctl reload varnish' after
changing my VCL.

Manual page included, `mandoc -Tlint' is happy.

Feedback? OK?

Index: Makefile
===================================================================
RCS file: /cvs/ports/www/varnish/Makefile,v
retrieving revision 1.46
diff -u -p -r1.46 Makefile
--- Makefile    19 May 2019 13:14:56 -0000      1.46
+++ Makefile    19 May 2019 15:50:05 -0000
@@ -3,6 +3,7 @@
 COMMENT =              high-performance HTTP accelerator
 
 DISTNAME =             varnish-6.2.0
+REVISION =             0
 
 CATEGORIES =           www
 
@@ -52,6 +53,8 @@ CONFIGURE_ARGS +=     --enable-debugging-sym
 .endif
 
 post-install:
+       ${SUBST_PROGRAM} ${FILESDIR}/varnishreload ${PREFIX}/bin/varnishreload
+       ${SUBST_MAN} ${FILESDIR}/varnishreload.1 
${PREFIX}/man/man1/varnishreload.1
        ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/varnish
        ${INSTALL_DATA} ${WRKDIST}${SYSCONFDIR}/{example,builtin}.vcl \
            ${PREFIX}/share/examples/varnish
Index: files/varnishreload
===================================================================
RCS file: files/varnishreload
diff -N files/varnishreload
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ files/varnishreload 19 May 2019 15:50:05 -0000
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# $OpenBSD $
+#
+# Reload active VCL.
+set -Cefu
+
+if getopts '' _ || [ $# -ge 2 ]; then
+       printf 'usage:\t%s [file]\n' "${0##*/}" 1>&2
+       exit 1
+fi
+
+FILE=${1:-${SYSCONFDIR}/varnish/default.vcl}
+NAME=${FILE##*/}
+NAME=${NAME%%.*}_$(date +%Y%m%d%H%M%S)
+
+${TRUEPREFIX}/bin/varnishadm -- vcl.load "$NAME" "$FILE"
+${TRUEPREFIX}/bin/varnishadm -- vcl.use "$NAME"
Index: files/varnishreload.1
===================================================================
RCS file: files/varnishreload.1
diff -N files/varnishreload.1
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ files/varnishreload.1       19 May 2019 15:50:05 -0000
@@ -0,0 +1,30 @@
+.\" $OpenBSD $
+.Dd $Mdocdate: May 19 2019 $
+.Dt VARNISHRELOAD 1
+.Os
+.Sh NAME
+.Nm varnishreload
+.Nd reload active VCL
+.Sh SYNOPSIS
+.Nm
+.Op Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility loads a new Varnish configuration and activates it iff valid.
+If no file is given, the installation default is used.
+.Pp
+The new VCL name consists of the file name and time of reload
+in order to maintain a meaningful, ordered list of configuations.
+.Sh FILES
+.Bl -tag -width Ds
+.It Pa ${SYSCONFDIR}/varnish/default.vcl
+The default VCL file.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr varnishadm 1 ,
+.Xr varnishd 1
+.Sh AUTHORS
+.An Klemens Nanni Aq Mt k...@openbsd.org
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/www/varnish/pkg/PLIST,v
retrieving revision 1.14
diff -u -p -r1.14 PLIST
--- pkg/PLIST   3 May 2019 11:06:26 -0000       1.14
+++ pkg/PLIST   19 May 2019 15:50:05 -0000
@@ -6,6 +6,7 @@
 @bin bin/varnishhist
 @bin bin/varnishlog
 @bin bin/varnishncsa
+bin/varnishreload
 @bin bin/varnishstat
 @bin bin/varnishtest
 @bin bin/varnishtop
@@ -115,6 +116,7 @@ lib/varnish/vmods/libvmod_vtc.so
 @man man/man1/varnishhist.1
 @man man/man1/varnishlog.1
 @man man/man1/varnishncsa.1
+@man man/man1/varnishreload.1
 @man man/man1/varnishstat.1
 @man man/man1/varnishtest.1
 @man man/man1/varnishtop.1
Index: pkg/varnishd.rc
===================================================================
RCS file: /cvs/ports/www/varnish/pkg/varnishd.rc,v
retrieving revision 1.5
diff -u -p -r1.5 varnishd.rc
--- pkg/varnishd.rc     5 Feb 2018 14:03:26 -0000       1.5
+++ pkg/varnishd.rc     19 May 2019 15:50:05 -0000
@@ -8,6 +8,9 @@ daemon_flags="-j unix,user=_varnish,ccgr
 . /etc/rc.d/rc.subr
 
 pexp="varnishd: Varnish-Mgt -i $(hostname)"
-rc_reload=NO
+
+rc_reload() {
+       ${PREFIX}/bin/varnishreload
+}
 
 rc_cmd $1

Reply via email to