Reload your vcl in Varnish without restart

Using varnishadm you can reload your vcl after editing it, without restarting varnish.
That means your cache is intact:

# varnishadm
varnish> vcl.load default /usr/local/varnish/etc/varnish/default.vcl
VCL compiled.
varnish> vcl.use default


What I found really practical was that this way I also could detect and fix errors in my vcl config, without varnish going down.

varnish> vcl.load default /usr/local/varnish/etc/varnish/default.vcl
Message from VCC-compiler:
Expected ')' got '{'
(program line 73), at
('input' Line 105 Pos 51)
        if ( !( req.url ~  "(login_form|manage)") {

Running VCC-compiler failed, exit 1
VCL compilation failed

2 comments on “Reload your vcl in Varnish without restart

  1. Wilson Sun March 1, 2016 4:56 am

    The method mentioned here reloads a vcl file into varnish. But there may be not this vcl file.

    When varnish works with other system, vcl configure is dynamically generated by the front system and set with vcl.inline.
    There is not a vcl file any more. In this case, we have to use vcl.inline.

    the following is my varnish_vcl_reload shell script using vcl.inline. Any suggestions
    are welcome. —
    # reload active vcl
    # Sometimes, vcl_init needs to be re-run by reloading the active vcl.
    # For example, a geoip database is loaded in vcl_init. When the database is updated,
    # vcl_init needs to be re-run.
    # This script saves the currently active vcl to a shell variable, and reloads it to varnish
    # Wislon Sun

    usage=”$(basename “$0″) [-n ident] [-t timeout] [-S secretfile] -T [address]:port

    -h show this help text
    -n,t,S,T refer to varnishadm”

    while getopts ‘:n:t:S:T:d:h’ option; do
    case $option in
    n) ident=$OPTARG
    t) timeout=$OPTARG
    S) secretfile=$OPTARG
    T) addressport=$OPTARG
    h) echo “$usage”
    🙂 printf “missing argument for -%s\n” “$OPTARG” >&2
    echo “$usage” >&2
    exit 1
    \?) echo “illegal option: -$OPTARG” >&2
    echo “$usage” >&2
    exit 1

    # Done parsing, set up command

    if [ ! -z “$ident” ]; then

    if [ ! -z “$timeout” ]; then
    VARNISHADM=”$VARNISHADM -t $timeout”

    if [ ! -z “$secretfile” ]; then
    VARNISHADM=”$VARNISHADM -S $secretfile”

    if [ ! -z “$addressport” ]; then
    VARNISHADM=”$VARNISHADM -T $addressport”

    # Check if we are able to connect at all
    if ! $VARNISHADM vcl.list >> /dev/null 2>&1; then
    echo “Unable to run \”$VARNISHADM vcl.list\””
    exit 1

    # find current config
    current_config=$( $VARNISHADM vcl.list | awk ‘ /^active/ { print $3 } ‘ )

    # save current config to a variable
    vclcontent= $VARNISHADM $current_config | sed ‘s/[“\]/\\\\&/g’ | sed ‘:a;N;$!ba;s/\n/\\\\n/g’

    timestamp=date +%Y%m%d_%H%M%S
    $VARNISHADM vcl.inline “vreload$timestamp” ‘”‘$vclcontent’”‘ >> /dev/null 2>&1
    vstring=varnishadm -n aeroflow vcl.list|grep “vreload$timestamp”
    if [ ! -z “$vstring” ]; then
    $VARNISHADM vcl.use “vreload$timestamp” >> /dev/null 2>&1
    $VARNISHADM vcl.discard $current_config >> /dev/null 2>&1
    echo “successfully reload current vcl config”
    exit 0
    echo “failed to save current vcl config”
    exit 1

    • Joar Jegleim March 1, 2016 12:41 pm

      Thank you for your varnish_vcl_reload shell script using vcl.inline, I will try it out ! 🙂

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.