38 lines
935 B
Bash

#!/bin/sh
set -vx
# remove previous pid (if exist) after crash
rm /var/run/$HOSTNAME.pid
if [ "$NOAUTO" == "yes" ];then
squid -z -n $HOSTNAME
squid -N -n $HOSTNAME
fi
LIMIT="-cmin +1440"
FINDTIME=$(find /var/cache/squid/$HOSTNAME/* -maxdepth 0 -type d $LIMIT)
chown -R squid /var/log/squid
# Not exist or too old
if [ ! -d "/var/cache/squid/$HOSTNAME" ] || [ ! -z $FINDTIME ];then
squid -z -n $HOSTNAME
sleep 1
else
touch "/var/cache/squid/$HOSTNAME"
fi
while test -e /var/run/$HOSTNAME.pid
do
echo "cache is generated/checked"
sleep 1
done
# Find and remove old useless caches directories (not used after limi valuet). sleep is only used to wait other containers are well started.
mkdir /tmp/empty
sleep 20 && find /var/cache/squid/* -maxdepth 0 -type d $LIMIT -exec rsync -a -v --delete /tmp/empty/ {}/ \; && rm -d /var/cache/squid/* 2>/dev/null &
squid -N -n $HOSTNAME