Created
June 13, 2018 19:00
-
-
Save mricon/28dd36fa093f9cb0748f63756f0f0a8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Don't bother with anything smaller than 1MB in size | |
MINSIZE="1M" | |
# Clean up any cache files older than 1 week, regardless of size | |
MAXAGE="7" | |
# In a multisite case, avoid running all cleaners at once | |
if [ "$2" != '--now' ]; then | |
sleep $(((RANDOM % 60))) | |
fi | |
CGITRC=$1 | |
if [ -z "$CGITRC" ]; then | |
CGITRC="/etc/cgitrc" | |
fi | |
CACHE_ROOT=$(grep '^cache-root=' $CGITRC | cut -d= -f2 2>/dev/null) | |
SNAPSHOT_TTL=$(grep '^cache-snapshot-ttl=' $CGITRC | cut -d= -f2 2>/dev/null) | |
STATIC_TTL=$(grep '^cache-static-ttl=' $CGITRC | cut -d= -f2 2>/dev/null) | |
if [ -z "$CACHE_ROOT" ]; then | |
CACHE_ROOT="/var/cache/cgit" | |
fi | |
if [ -z "$SNAPSHOT_TTL" ]; then | |
SNAPSHOT_TTL="10" | |
fi | |
for CACHEFILE in $(find $CACHE_ROOT -type f -size +$MINSIZE -mmin +$SNAPSHOT_TTL); do | |
if head -n1 $CACHEFILE | grep -q '/snapshot/'; then | |
rm -f $CACHEFILE | |
fi | |
done | |
if [ ! -z "$STATIC_TTL" ]; then | |
for CACHEFILE in $(find $CACHE_ROOT -type f -size +$MINSIZE -mmin +$STATIC_TTL); do | |
if head -n1 $CACHEFILE | grep -q 'id='; then | |
rm -f $CACHEFILE | |
fi | |
done | |
fi | |
find $CACHE_ROOT -type f -mtime +$MAXAGE -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment