57 lines
1.5 KiB
Bash
57 lines
1.5 KiB
Bash
#!/bin/bash
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
# variables
|
|
date=$(date +%d-%m-%Y_%w)
|
|
# Remove buggy cache and restart
|
|
|
|
cachedirconf=$(grep cache_dir /etc/squid/squid.conf | grep -v "#" | cut -d " " -f5)
|
|
cachedir=$(ls /var/spool/squid/$HOSTNAME | wc -l)
|
|
|
|
if [ $cachedirconf -gt $cachedir ] && [ -d "/var/spool/squid/$HOSTNAME" ]; then
|
|
# corrupted caches
|
|
echo "CACHE IS CORRUPED: try to autorepair"
|
|
rsync -a -v --delete /tmp/empty/ /var/spool/squid/$HOSTNAME
|
|
rm -Rf /var/spool/squid/$HOSTNAME
|
|
# restart for regenerating cache after
|
|
squid -k kill
|
|
fi
|
|
|
|
if [ -z "$supgethosts" ] && [ -z "$supicaphost" ]; then
|
|
echo "SUP: NO SUP"
|
|
exit 0
|
|
fi
|
|
|
|
if [ -n "$supgethosts" ]; then
|
|
for i in ${supgethosts[@]}
|
|
do
|
|
echo "CHECK: $i"
|
|
curl -s -o /dev/null --connect-timeout 5 -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/96.0" $i
|
|
if [ $? = 0 ];then
|
|
echo "SUP: ACCESS ok $i"
|
|
if [ -z "$supicaphost" ]; then
|
|
exit 0
|
|
else
|
|
break
|
|
fi
|
|
else
|
|
echo "SUP: ERROR $i"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -n "$supicaphost" ]; then
|
|
c-icap-client -i $supicaphost -p $supicapport -s request > /tmp/test-icap-e2g-orion 2>&1
|
|
grep "200 OK" /tmp/test-icap-e2g-orion >/dev/null
|
|
if [ $? = 0 ];then
|
|
echo "SUP ICAP: ACCESS ICAP ok $supicaphost"
|
|
exit 0
|
|
else
|
|
echo "SUP ICAP: ERROR $supicaphost"
|
|
fi
|
|
fi
|
|
|
|
# Sup error because no OK before
|
|
echo "SUP ERROR"
|
|
squid -k shutdown
|
|
exit 1
|