From 50393ac177e3be29baa4c515b66cba3b236cd621 Mon Sep 17 00:00:00 2001 From: redxef Date: Sat, 19 Aug 2023 02:43:59 +0200 Subject: [PATCH] Change inotifywait function to properly detect file changes. --- Dockerfile | 2 +- start-nginx.sh | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f84bb9..83fe8dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM nginx:alpine-perl -RUN apk add --upgrade --no-cache gettext inotify-tools +RUN apk add --upgrade --no-cache bash gettext inotify-tools RUN mv /etc/nginx /etc/nginx.tmpl RUN touch /etc/envsubst.conf diff --git a/start-nginx.sh b/start-nginx.sh index c513207..166d305 100755 --- a/start-nginx.sh +++ b/start-nginx.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash pids="" @@ -36,10 +36,16 @@ run_nginx() { } run_inotifywait() { - while find "$dstdir" -type f -exec \ - sed -En '/ssl_certificate/ s/^\s*ssl_certificate(_key)? (.*);.*$/\2/p' {} \; | sort | uniq | tee /dev/stderr | \ - inotifywait --fromfile=- -e close_write -e modify; do + while :; do + wait_files="$(find "$dstdir" -type f -exec \ + sed -En '/ssl_certificate/ s/^\s*ssl_certificate(_key)? (.*);.*$/\2/p' {} \; | sort | uniq)" + wait_directories="$(echo "$wait_files" | xargs -0 dirname | sort | uniq)" + echo "monitoring the following files:" + echo "$wait_files" + matched_files="$(echo "$wait_directories" | inotifywait --fromfile=- -e close_write -e modify -e create)" + if [[ -n "$(comm -12 <(echo "$matched_files") <(echo "$wait_files"))" ]]; then nginx -s reload + fi done }