summaryrefslogtreecommitdiff
path: root/installation
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2020-05-20 06:56:04 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2020-05-20 06:56:04 +0300
commitb5b9d161cddd1b6650cde00cf0f3cbf56ab7a4a3 (patch)
tree6a45bf6b6c2cbeaed06c62899bdb80cfaf0426c8 /installation
parent5f0a3ac74d51333a778e6be26876fe26b0ff625b (diff)
update purge script
Diffstat (limited to 'installation')
-rwxr-xr-xinstallation/nginx-cache-purge.example39
-rwxr-xr-xinstallation/nginx-cache-purge.sh.example40
2 files changed, 40 insertions, 39 deletions
diff --git a/installation/nginx-cache-purge.example b/installation/nginx-cache-purge.example
deleted file mode 100755
index 12dfa733c..000000000
--- a/installation/nginx-cache-purge.example
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-
-# A simple Bash script to delete an media from the Nginx cache.
-
-SCRIPTNAME=${0##*/}
-
-# NGINX cache directory
-CACHE_DIRECTORY="/tmp/pleroma-media-cache"
-
-function get_cache_files() {
- local max_parallel=${3-16}
- find $2 -maxdepth 1 -type d | xargs -P $max_parallel -n 1 grep -ERl "^KEY:.*$1" | sort -u
-}
-
-function purge_item() {
- local cache_files
- cache_files=$(get_cache_files "$1" "$2")
-
- if [ -n "$cache_files" ]; then
- for i in $cache_files; do
- [ -f $i ] || continue
- echo "Deleting $i from $2."
- rm $i
- done
- else
- echo "$1 is not cached."
- fi
-}
-
-function purge() {
- for url in "$@"
- do
- echo "$SCRIPTNAME delete $url from cache ($CACHE_DIRECTORY)"
- purge_item $url $CACHE_DIRECTORY
- done
-
-}
-
-purge $1
diff --git a/installation/nginx-cache-purge.sh.example b/installation/nginx-cache-purge.sh.example
new file mode 100755
index 000000000..aaa195324
--- /dev/null
+++ b/installation/nginx-cache-purge.sh.example
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# A simple shell script to delete a media from the Nginx cache.
+
+SCRIPTNAME=${0##*/}
+
+# NGINX cache directory
+CACHE_DIRECTORY="/tmp/pleroma-media-cache"
+
+## Return the files where the items are cached.
+## $1 - the filename, can be a pattern .
+## $2 - the cache directory.
+## $3 - (optional) the number of parallel processes to run for grep.
+get_cache_files() {
+ local max_parallel=${3-16}
+ find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -ERl "^KEY:.*$1" | sort -u
+}
+
+## Removes an item from the given cache zone.
+## $1 - the filename, can be a pattern .
+## $2 - the cache directory.
+purge_item() {
+ for f in $(get_cache_files $1 $2); do
+ echo "found file: $f"
+ [ -f $f ] || continue
+ echo "Deleting $f from $2."
+ rm $f
+ done
+} # purge_item
+
+purge() {
+ for url in "$@"
+ do
+ echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)"
+ purge_item $url $CACHE_DIRECTORY
+ done
+
+}
+
+purge $1