From 63216c5b2b15791d25e65758d1936ec8f25b6fcd Mon Sep 17 00:00:00 2001 From: Greg Schohn Date: Fri, 4 Oct 2024 17:42:04 -0400 Subject: [PATCH] DocumentMigration entrypoint - Stop looping if we're eating up more disk space. Signed-off-by: Greg Schohn --- .../docker/entrypoint.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/DocumentsFromSnapshotMigration/docker/entrypoint.sh b/DocumentsFromSnapshotMigration/docker/entrypoint.sh index 32473136d..3181e803f 100755 --- a/DocumentsFromSnapshotMigration/docker/entrypoint.sh +++ b/DocumentsFromSnapshotMigration/docker/entrypoint.sh @@ -43,6 +43,20 @@ if [[ $RFS_COMMAND != *"--target-password"* ]]; then fi fi +# Monitor how much aggregate free space is left, if we drop below a certain amount, +# don't allow another process to run again +space_drop_fraction=4 +initial_free_space=$(df --output=avail | awk 'NR>1 {sum+=$1} END {print sum}') +still_enough_space_left() { + current_free=$(df --output=avail | awk 'NR>1 {sum+=$1} END {print sum}') + if (((initial_free_space - current_free) >= (initial_free_space / $space_drop_fraction))); then + return 1; + else + return 0; + fi +} + + [ -z "$RFS_COMMAND" ] && \ { echo "Warning: RFS_COMMAND is empty! Exiting."; exit 1; } || \ -until ! { echo "Running command $RFS_COMMAND"; eval "$RFS_COMMAND"; }; do :; done \ No newline at end of file +until ! { echo "Running command $RFS_COMMAND"; eval "$RFS_COMMAND" && still_enough_space_left; }; do :; done