-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquid-reload
executable file
·29 lines (20 loc) · 1.24 KB
/
squid-reload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
CONFIG="/etc/squid/squid.second-instance.conf"
export PATH="$PATH:/usr/sbin" # ..needed under Cron
Wait_listen() { for n in `seq 1 30`; do ss -ntl "sport = :$1" | grep -q ^LISTEN && return 0; sleep 1; done; echo "Timeout: wait_listen $1" ; return 1; }
Wait_not_listen() { for n in `seq 1 30`; do ss -ntl "sport = :$1" | grep -q ^LISTEN || return 0; sleep 1; done; echo "Timeout: wait_not_listen $1"; return 1; }
echo "Try to start second Squid..."
if test -s "$CONFIG" && squid -f "$CONFIG" && Wait_listen "4130" && sleep 15; then
echo "Redirect firewall to second Squid..."
iptables-save | awk '/^-A PREROUTING .* 3129$/ { $1=$NF=""; print "iptables -t nat -I", $0, "4129"; exit }' | sh -
iptables-save | awk '/^-A PREROUTING .* 3130$/ { $1=$NF=""; print "iptables -t nat -I", $0, "4130"; exit }' | sh -
fi
echo "Reconfigure main Squid..."
squid -k reconfigure
Wait_not_listen 3130
Wait_listen 3130
test -s /var/run/squid/squid2.pid && echo "Kill second squid..." && sleep 15
pkill -F /var/run/squid/squid2.pid
iptables-save | awk '/^-A PREROUTING .* 4129$/ { $1=""; print "iptables -t nat -D", $0; exit }' | sh -
iptables-save | awk '/^-A PREROUTING .* 4130$/ { $1=""; print "iptables -t nat -D", $0; exit }' | sh -
## END ##