better dynamic reload script

This commit is contained in:
ElevenNotes
2024-10-14 00:41:02 +02:00
parent ca7ef43a84
commit 0b475fd85f
4 changed files with 27 additions and 18 deletions

View File

@@ -0,0 +1,25 @@
#!/bin/ash
elevenLogJSON info "reloading config"
NGINX_DYNAMIC_RELOAD_LOG=${APP_ROOT}/run/reload.log
nginx -t &> ${NGINX_DYNAMIC_RELOAD_LOG}
while read -r LINE; do
if echo "${LINE}" | grep -q "nginx: "; then
if echo "${LINE}" | grep -q "\[warn\]"; then
LINE=$(echo ${LINE} | sed 's/nginx: \[warn\] //')
elevenLogJSON warning "${LINE}"
fi
if echo "${LINE}" | grep -q "\[emerg\]"; then
LINE=$(echo ${LINE} | sed 's/nginx: \[emerg\] //')
elevenLogJSON error "${LINE}"
fi
fi
done < ${NGINX_DYNAMIC_RELOAD_LOG}
if cat ${NGINX_DYNAMIC_RELOAD_LOG} | grep -q "test is successful"; then
nginx -s reload
elevenLogJSON info "config reloaded"
else
elevenLogJSON error "config reload failed!"
fi

View File

@@ -10,7 +10,7 @@
if [ -z "${1}" ]; then
if [ ! -z ${NGINX_DYNAMIC_RELOAD} ]; then
elevenLogJSON info "enable dynamic reload"
/sbin/inotifyd /usr/local/bin/io.sh ${APP_ROOT}/etc:cdnym &
/sbin/inotifyd /usr/local/bin/dynamic_reload.sh ${APP_ROOT}/etc:cdnym &
fi
elevenLogJSON info "starting ${APP_NAME} (${APP_VERSION})"

View File

@@ -1,16 +0,0 @@
#!/bin/ash
RELOAD_LOG=${APP_ROOT}/run/reload.log
nginx -tq &> ${RELOAD_LOG}
elevenLogJSON info "change in config files detected"
if cat ${RELOAD_LOG} | grep -q "nginx.conf test failed"; then
elevenLogJSON info "error in configuration files found"
cat ${RELOAD_LOG}
else
if cat ${RELOAD_LOG} | grep -q "nginx.conf test is successful"; then
elevenLogJSON info "reload nginx with config changes"
nginx -s reload
else
elevenLogJSON info "error in configuration files found"
cat ${RELOAD_LOG}
fi
fi