#!/bin/bash set -vx if [ -e "/run/squid.pid" ];then echo "Squid pid: Already running ?" rm /run/squid.pid pkill squid exit 1 fi # Check si Au demarrage le cache contient des repertoires pas utilisés depuis plus de $LIMIT FINDTIME=$(find /var/spool/squid/$HOSTNAME/* -maxdepth 0 -type d $LIMIT | wc -l) # Combien de rep global NOWREP=$(find /var/spool/squid/$HOSTNAME/* -maxdepth 0 -type d | wc -l) # Not exist or too old if [ ! -d "/var/spool/squid/$HOSTNAME" ] || [ $FINDTIME == $NOWREP ];then # On genere/regenere squid -z -n $HOSTNAME sleep 1 else # Remet à zero la date du rep de cache pour le prochain check 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" value). 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 &