From 3a42041dac2f588445ab5a8b5511bc299c185243 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 14 Mar 2017 14:26:26 -0500 Subject: [PATCH] Automatically purge old cache content on launch (closes #8.) --- .sandstorm/changelog.md | 7 ++++++- .sandstorm/launcher.sh | 24 ++++++++++++++++++++++++ .sandstorm/sandstorm-files.list | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.sandstorm/changelog.md b/.sandstorm/changelog.md index 62c58c5..6042050 100644 --- a/.sandstorm/changelog.md +++ b/.sandstorm/changelog.md @@ -1,6 +1,11 @@ -# 2016-06-26a-sandstorm5 (2016-11-17) +# 2016-06-26a-sandstorm6 (2017-03-14) + + * Now cleans up cached content older than 30 days, as well as removing stale locks and other useless data + +# 2016-06-26a-sandstorm5 (2017-03-14) * Create default @user ACL rule + * Fix issue where recursive symlinks broke previous grains # V2016-06-26a-sandstorm4 (2016-10-14) diff --git a/.sandstorm/launcher.sh b/.sandstorm/launcher.sh index 02e6392..1dfe6d7 100644 --- a/.sandstorm/launcher.sh +++ b/.sandstorm/launcher.sh @@ -49,5 +49,29 @@ grep -Ev '^($|#)' /opt/app/dokuwiki/data.orig/deleted.files | xargs -n 1 rm -vrf cp /opt/app/acl.auth.php /var/lib/dokuwiki/conf +function cleanup() +{ + local data_path="$1" # full path to data directory of wiki + local retention_days="$2" # number of days after which old files are to be removed + + # purge files older than ${retention_days} days from attic and media_attic (old revisions) + find "${data_path}"/{media_,}attic/ -type f -mtime +${retention_days} -delete + + # remove stale lock files (files which are 1-2 days old) + find "${data_path}"/locks/ -name '*.lock' -type f -mtime +1 -delete + + # remove empty directories + find "${data_path}"/{attic,cache,index,locks,media,media_attic,media_meta,meta,pages,tmp}/ \ + -mindepth 1 -type d -empty -delete + + # remove files older than ${retention_days} days from the cache + if [ -e "${data_path}"/cache/?/ ] + then + find "${data_path}"/cache/?/ -type f -mtime +${retention_days} -delete + fi +} + +cleanup /var/lib/dokuwiki/data 30 + # Start nginx. /usr/sbin/nginx -c /opt/app/.sandstorm/service-config/nginx.conf -g "daemon off;" diff --git a/.sandstorm/sandstorm-files.list b/.sandstorm/sandstorm-files.list index 5ed573b..c660023 100644 --- a/.sandstorm/sandstorm-files.list +++ b/.sandstorm/sandstorm-files.list @@ -5284,6 +5284,7 @@ sandstorm-http-bridge sandstorm-http-bridge-config sandstorm-manifest usr/bin/file +usr/bin/find usr/bin/id usr/bin/rsync usr/bin/touch