-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusr-local-bin-loris-cache-clean
52 lines (44 loc) · 1.72 KB
/
usr-local-bin-loris-cache-clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# avoids race conditions by stopping the server before attempting to
# clean files and folders in the caches
# also, in case the occupied size is too high to safely execute
# loris-cache-clean in time, goes for the forest-burning loris-cache-purge
# which deletes everything without taking LRU policies into consideration
# run as root
set -e
if [ "$#" -lt 2 ]; then
echo "Usage: loris-cache-clean SOFT_MAX_SIZE_KILOBYTES HARD_MAX_SIZE_KILOBYTES"
echo "Sample: loris-cache-clean 10000000 20000000"
echo " will clean the cache with LRU policies if used disk space is more than 10GB"
echo " will purge the cache deleting everything if used disk space is more than 20GB"
exit 1
fi
current_usage_cache_root () {
df -k {{ pillar.iiif.loris.storage }} --output=used | sed 1d
}
log_message () {
logger "$1" --tag "loris-cache-clean"
}
log_message "Started loris-cache-clean (arguments $1 $2)"
soft_limit="$1"
hard_limit="$2"
usage=$(current_usage_cache_root)
log_message "Cache at $usage kb"
if [ "$usage" -lt "$soft_limit" ]; then
log_message "Nothing to do"
exit 0
fi
if [ "$usage" -lt "$hard_limit" ]; then
# systemctl stop nginx
# log_message "Starting loris-cache-clean-soft"
# timeout 240 /usr/local/bin/loris-cache-clean-soft "$soft_limit" || log_message "TIMEOUT OF loris-cache-clean-soft"
# log_message "Completed loris-cache-clean-soft"
# systemctl start nginx
log_message "Skipping loris-cache-clean-soft (disabled)"
else
systemctl stop nginx
log_message "Starting loris-cache-clean-hard"
/usr/local/bin/loris-cache-clean-hard || log_message "FAILED loris-cache-clean-hard"
log_message "Completed loris-cache-clean-hard"
systemctl start nginx
fi