From 9ddea3b153679b0449e57741d9256919e60fab14 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Sun, 9 Jun 2024 18:59:22 +0100 Subject: Allow for configuring watch directory in container --- monitor.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/monitor.sh b/monitor.sh index e3bc9d4..48c42a9 100755 --- a/monitor.sh +++ b/monitor.sh @@ -2,27 +2,37 @@ set -exo pipefail -if [ -z ${HOOK_SCRIPT+x} ]; then - echo "Missing HOOK_SCRIPT environment variable, set it to the script to run upon file changes"; +if [ -z ${INOTIFY_HOOK_SCRIPT+x} ]; then + echo "Missing INOTIFY_HOOK_SCRIPT environment variable, set it to the script to run upon file changes"; exit 1; else - if ! test -f $HOOK_SCRIPT; then - echo "The file pointed to by HOOK_SCRIPT does not exist, check your container mounts."; + if ! test -f $INOTIFY_HOOK_SCRIPT; then + echo "The file pointed to by INOTIFY_HOOK_SCRIPT does not exist, check your container mounts."; exit 1; fi; - if ! test -x $HOOK_SCRIPT; then - echo "HOOK_SCRIPT is not an executable file (missing +x bit), check file permissions of the hook script." + if ! test -x $INOTIFY_HOOK_SCRIPT; then + echo "INOTIFY_HOOK_SCRIPT is not an executable file (missing +x bit), check file permissions of the hook script." exit 1; fi; fi; if [ -n "$WATCH_EVENTS" ]; then - ADDITIONAL_ARGS="-e $WATCH_EVENTS" + ADDITIONAL_ARGS="-e $INOTIFY_WATCH_EVENTS" else ADDITIONAL_ARGS="" fi -while inotifywait $ADDITIONAL_ARGS -r /opt/monitor; do - $HOOK_SCRIPT +if [ -n "$INOTIFY_WATCH_DIRECTORY" ]; then + WATCH_DIR="$INOTIFY_WATCH_DIRECTORY" +else + WATCH_DIR="/opt/monitor" +fi + +while inotifywait $ADDITIONAL_ARGS -r $WATCH_DIR; do + if [ -z ${INOTIFY_HOOK_DELAY+x} ]; then + echo "Waiting $INOTIFY_HOOK_DELAY until executing hook..." + sleep $INOTIFY_HOOK_DELAY + fi + $INOTIFY_HOOK_SCRIPT done; -- cgit v1.2.3