vhost-stack/bin/vhost-varnish-disable.sh

65 lines
1.8 KiB
Bash
Raw Normal View History

2021-04-04 13:28:22 -07:00
#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
2021-04-04 14:15:16 -07:00
# load include file
source $(dirname $0)/vhost.sh
2021-04-04 13:28:22 -07:00
2021-09-16 16:21:35 -07:00
help()
{
thisfilename=$(basename -- "$0")
2021-10-05 11:33:24 -07:00
echo "Disables Varnish config for specified domain (VirtualHost)."
2021-09-16 16:21:35 -07:00
echo ""
2021-10-05 11:33:24 -07:00
echo "usage: $thisfilename -d <domain> [-h]"
2021-09-16 16:21:35 -07:00
echo ""
2021-10-05 11:33:24 -07:00
echo " -h Print this help."
echo " -d <domain> Domain name (VirtualHost) to disable Varnish for."
2021-09-16 16:21:35 -07:00
echo ""
2021-10-05 11:33:24 -07:00
echo " Varnish is proxied through Apache. This disables the"
echo " Apache proxy to Varnish and removes the varnish config."
2021-09-16 16:21:35 -07:00
exit
}
2021-04-04 13:28:22 -07:00
2021-10-05 11:33:24 -07:00
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
2021-04-04 13:28:22 -07:00
fi
# grab macro line from virtualhost config
2021-10-05 11:33:24 -07:00
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$domain.conf` ; then
2021-04-04 13:28:22 -07:00
macro_name=`echo "$macro_vhost_line" | awk '{print $2}'`
else
2021-10-05 11:33:24 -07:00
echo "$domain is not configured with mod_macro"
2021-04-04 13:28:22 -07:00
exit 1
fi
# make sure Varnish is already enabled
if [[ $macro_name =~ ^.*Varnish$ ]]; then
# set new macro_name
macro_name=`echo $macro_name | sed -e 's|Varnish$||'`
2021-10-05 11:33:24 -07:00
vhost_enable="$macro_name $domain"
2021-04-04 13:28:22 -07:00
else
2021-10-05 11:33:24 -07:00
echo "Varnish is not enabled for $domain"
2021-04-04 13:28:22 -07:00
exit 1
fi
# check if VHost macro is for a Subdomain or Alias
if [[ "$macro_name" == *"Subdomain"* ]] || [[ "$macro_name" == *"Alias"* ]]; then
macro_var=`echo "$macro_vhost_line" | awk '{print $5}'`
vhost_enable="$vhost_enable $macro_var"
fi
2021-09-16 16:21:35 -07:00
/usr/local/bin/vhost-enable.sh $vhost_enable
2021-04-04 13:28:22 -07:00
2021-10-05 11:33:24 -07:00
if [[ -f /etc/varnish/sites.d/$domain ]]; then
rm /etc/varnish/sites.d/$domain
2021-09-16 16:21:35 -07:00
/usr/local/bin/vhost-varnish-update-sites.sh $vhost_enable
# uncomment to flush varnish cache
# systemctl is-active --quiet varnish && systemctl reload --quiet varnish
fi