From 811864123197099cc13375a914b6cf0fdaef6b22 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 10 Apr 2023 15:04:12 +0200 Subject: [PATCH] Do not run tasks if required mounts are not present. A configuration item `imports.mounts` is added to `etc/config.yaml`. This should be a list of paths which must be non-empty. If any of the paths in that list is empty, runner.sh will abort. Closes #200. --- bin/check_mounts_present.py | 27 +++++++++++++++++++++++++++ bin/runner.sh | 6 ++++++ etc/config.yaml | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100755 bin/check_mounts_present.py diff --git a/bin/check_mounts_present.py b/bin/check_mounts_present.py new file mode 100755 index 0000000..78e758e --- /dev/null +++ b/bin/check_mounts_present.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 + +""" +Check if any of the directories provided in the imports.mounts configuration +section are empty. + +Returns 0 if all arguments are non-empty, 1 otherwise. It stops at the first +empty directory. +""" + +import os +import configuration + +cfg = configuration.read() + +if cfg and "imports" in cfg and "mounts" in cfg["imports"]: + + mounts = cfg["imports"]["mounts"] + for item in mounts: + with os.scandir(item) as contents: + if not any(contents): + exit(1) + +else: + print("No mounts in configuration") + +exit(0) diff --git a/bin/runner.sh b/bin/runner.sh index 300e591..d9e0f0c 100755 --- a/bin/runner.sh +++ b/bin/runner.sh @@ -107,6 +107,12 @@ echo "$$" > "$LOCKFILE" || { } print_info "Start run" +print_log "Check if data is accessible" +$BINDIR/check_mounts_present.py || { + print_warning "Import mounts not accessible. Inhibiting all tasks!" + exit 253 +} + print_log "Purge deleted files" run $BINDIR/purge_deleted_files.py diff --git a/etc/config.yaml b/etc/config.yaml index a4864f6..75cec49 100644 --- a/etc/config.yaml +++ b/etc/config.yaml @@ -32,6 +32,13 @@ imports: # least this many seconds ago. file_min_age: 60 + # These paths refer to remote mounts which must be present in order + # for imports to work. If any of these paths are empty, import actions + # (including data deletion) will be inhibited. This is to cope with + # things like transient network failures. + mounts: + - /srv/mnt/Data + queues: asaqc: request: