Skip to content

Commit

Permalink
fixed SERIOUS bug in trim-cache service
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisMitchell committed Mar 26, 2019
1 parent 4ee2cef commit 4a51ba3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bin/trim-cache
@@ -1,14 +1,15 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

. /srv/lib/conf
load_conf trim-cache max_disk_usage min_disk_usage

cd /srv/cache
disk_usage=($(du --block-size=1K --summarize))
disk_usage=($(du /srv/cache --block-size=1K --summarize))
(( disk_usage < max_disk_usage )) && exit

find -mindepth 2 -printf '%C@ %k\n' | sort --numeric-sort | while read ctime blocks; do
find /srv/cache -mindepth 2 -printf '%C@ %k\n' | sort --numeric-sort | while read ctime blocks; do
(( (disk_usage -= blocks) > min_disk_usage )) && continue
find -mindepth 2 -not -newerct @$ctime -delete
find /srv/cache -mindepth 2 -not -newerct @$ctime -delete
exit
done
2 changes: 2 additions & 0 deletions lib/systemd/tio-trim-cache.service
Expand Up @@ -3,4 +3,6 @@ Description=Trim TIO's output cache
[Service]
Type=oneshot
User=apache
Group=apache
ExecStart=/srv/bin/trim-cache

0 comments on commit 4a51ba3

Please sign in to comment.