Skip to content

Commit 1784b3d

Browse files
committed
Merge pull request loris-imageserver#157 from loris-imageserver/revise_cache_script
adds info about quota version or cache maintenance script
2 parents 6816941 + 44c2ed9 commit 1784b3d

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

bin/loris-cache_clean.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
#!/bin/bash
22

33
#
4-
# cache_clean.sh
4+
# loris-cache_clean.sh
5+
#
56
# Cron script for maintaining the loris cache size.
67
#
78
# CAUTION - This script deletes files. Be careful where you point it!
89
#
9-
LOG="/var/log/loris/cache_clean.log"
1010

11-
# Check that the cache directories...
11+
LOG="/var/log/loris2/cache_clean.log"
12+
13+
# Check that the image cache directory...
1214
IMG_CACHE_DIR="/var/cache/loris/img"
13-
IMG_LINKS_DIR="/var/cache/loris/links"
1415

15-
# ...is below a certain size...
16+
# ...is below a certain size and...
1617
REDUCE_TO=1048576 #1 gb
1718
# REDUCE_TO=1073741824 # 1 TB
1819
# REDUCE_TO=2147483648 # 2 TB
1920

20-
# ...and when it is larger, start deleting files accessed more than a certain
21+
# ...and when it is larger, start deleting files accessed more than a certain
2122
# number of days ago until the cache is smaller than the configured size.
2223

23-
# Note the name of the variable __REDUCE_TO__: this should not be the total
24-
# amount of space you can afford for the cache, but instead the total space
25-
# you can afford MINUS the amount you expect the cache to grow in between
24+
# Note the name of the variable __REDUCE_TO__: this should not be the total
25+
# amount of space you can afford for the cache, but instead the total space
26+
# you can afford MINUS the amount you expect the cache to grow in between
2627
# executions of this script.
2728

2829
current_usage () {
29-
du -sk $IMG_CACHE_DIR | cut -f 1
30+
du -sk $IMG_CACHE_DIR | cut -f 1 # Fine for a few GB...
31+
# quota -Q -u loris | grep sdb1 | awk '{ print $2 }' # ...much faster!!
32+
# Note that you'll like need to change the name of the filesystem above if
33+
# using the `quota` version.
3034
}
3135

3236
delete_total=0
@@ -43,9 +47,6 @@ while [ $usage -gt $REDUCE_TO ] && [ $max_age -ge -1 ]; do
4347
let delete_total+=1
4448
done
4549

46-
# broken symlinks
47-
find -L $IMG_LINKS_DIR -type l -delete
48-
4950
# empty directories
5051
find $IMG_CACHE_DIR -mindepth 1 -type d -empty -delete
5152

@@ -60,7 +61,3 @@ if [ $run == 0 ]; then
6061
else
6162
echo "Cache at $usage kb (no deletes required)." >> $LOG
6263
fi
63-
64-
65-
66-

doc/cache_maintenance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ There are two a Bash scripts at `bin/loris-cache_clean.sh` and `bin/loris-http_c
77

88
__`setup.py` will not move or deploy the script for you.__ You can do this with, e.g. `sudo crontab -e -u loris` (replace `loris` with a user that has permission to delete files from the cache).
99

10-
`du` can take a very long time to run if you've configured your cache to be very large. In this case, consider setting an arbitrarily high disk usage quota for the cache owner ('arbitrarily high' so that you don't get errors if you go over a bit between executions of the cron script), and replace the `current_usage()` function in the cron script with:
10+
`du` can take a very long time to run if you've configured your cache to be very large. In this case, consider setting an arbitrarily high disk usage quota for the cache owner ('arbitrarily high' so that you don't get errors if you go over a bit between executions of the cron script), and replace the `current_usage()` function in the cron script with something like (you'll probably have to adjust the name of the file system):
1111

1212
```bash
1313
current_usage () {
14-
quota -Q -u loris |grep sdc1 | awk '{ print $2 }'
14+
quota -Q -u loris | grep sdb1 | awk '{ print $2 }'
1515
}
1616
```
1717

0 commit comments

Comments
 (0)