First
[anni] / docs / installation_1 / nginx-cache-purge.sh.example
1 #!/bin/sh
2
3 # A simple shell script to delete a media from the Nginx cache.
4
5 SCRIPTNAME=${0##*/}
6
7 # NGINX cache directory
8 CACHE_DIRECTORY="/tmp/pleroma-media-cache"
9
10 ## Return the files where the items are cached.
11 ## $1 - the filename, can be a pattern .
12 ## $2 - the cache directory.
13 ## $3 - (optional) the number of parallel processes to run for grep.
14 get_cache_files() {
15     local max_parallel=${3-16}
16     find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -E -Rl "^KEY:.*$1" | sort -u
17 }
18
19 ## Removes an item from the given cache zone.
20 ## $1 - the filename, can be a pattern .
21 ## $2 - the cache directory.
22 purge_item() {
23   for f in $(get_cache_files $1 $2); do
24       echo "found file: $f"
25       [ -f $f ] || continue
26       echo "Deleting $f from $2."
27       rm $f
28   done
29 } # purge_item
30
31 purge() {
32   for url in "$@"
33   do
34     echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)"
35     purge_item $url $CACHE_DIRECTORY
36   done
37
38 }
39
40 purge $@