fredbcode-images-squid/run.sh
2021-04-23 11:15:19 +02:00

31 lines
841 B
Bash

#!/bin/sh
set -vx
# remove previous pid (if exist) after crash
rm /var/run/squid.pid
LIMIT="-cmin +5"
FINDTIME=$(find /var/spool/squid/$HOSTNAME/* -maxdepth 0 -type d $LIMIT)
chown -R squid /var/log/squid
# Si le cache n'existe pas OU rep trop ANCIEN
if [ ! -d "/var/spool/squid/$HOSTNAME" ] || [ ! -z $FINDTIME ];then
squid -z -n $HOSTNAME
sleep 1
else
touch "/var/spool/squid/$HOSTNAME"
fi
while test -e /var/run/squid.pid
do
echo "cache is generated/checked"
sleep 1
done
# Find and remove old useless caches directories (not used after limit). Sleep is here to wait for all containers to start.
mkdir /tmp/empty
sleep 20 && find /var/spool/squid/* -maxdepth 0 -type d $LIMIT -exec rsync -a -v --delete /tmp/empty/ {}/ \; && rm -d /var/spool/squid/* 2>/dev/null &
squid -N -n $HOSTNAME