Change inotifywait function to properly detect file changes.

This commit is contained in:
redxef 2023-08-19 02:43:59 +02:00
parent 7333c7bcf5
commit 50393ac177
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
2 changed files with 11 additions and 5 deletions

View file

@ -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

View file

@ -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
}