Last active
April 26, 2018 08:47
-
-
Save antonbabenko/d2796672546a28f38b23 to your computer and use it in GitHub Desktop.
Watch default.vcl changes and reload on the fly (must-have for working with Varnish locally)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##### | |
# Watch changes in default.vcl and reload a varnish config: | |
# sudo su - | |
# fswatch -o /usr/local/etc/varnish/default.vcl | xargs -n1 /Users/Bob/bin/reloadvcl | |
#### | |
FILE="/usr/local/etc/varnish/default.vcl" | |
VARNISH_DIR="/usr/local/var/varnish" | |
VARNISHD="/usr/local/sbin/varnishd" | |
VARNISHADM="/usr/local/bin/varnishadm" | |
NOW=`date +%s` | |
DISPLAY_DATE=`date +%c` | |
# Try to compile config | |
$VARNISHD -C -f $FILE > /tmp/vcl_output 2>&1 | |
if [ ! $? -eq 0 ]; then | |
cat /tmp/vcl_output | |
exit 1 | |
fi | |
$VARNISHADM -n $VARNISH_DIR vcl.load conf$NOW $FILE > /tmp/vcl_output2 | |
cat /tmp/vcl_output2 | |
$VARNISHADM -n $VARNISH_DIR vcl.use conf$NOW > /tmp/vcl_output3 | |
cat /tmp/vcl_output3 | |
echo "[ ${DISPLAY_DATE} ] conf${NOW} - Varnish config has been reloaded." | |
#echo "Current configs:" | |
#echo "vcl.list" | $VARNISHADM -n $VARNISH_DIR > /tmp/vcl_output4 | |
#cat /tmp/vcl_output4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment