Improve startup command inotifywait.

This commit is contained in:
redxef 2024-01-26 00:27:04 +01:00
parent a1f8d62549
commit e8e2761cff
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -38,12 +38,12 @@ run_nginx() {
run_inotifywait() {
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)"
sed -En '/ssl_certificate/ s/^\s*ssl_certificate(_key)? (.*);.*$/\2/p' {} \; | sort -u)"
wait_directories="$(echo "$wait_files" | xargs -n 1 dirname | sort -u)"
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 <(sort <<< "$matched_files") <(echo "$wait_files"))" ]]; then
if [[ -n "$(comm -12 <(sort -u <<< "$matched_files") <(echo "$wait_files"))" ]]; then
nginx -s reload
fi
done