From 9852eaff52b3be68ab36e83050ff68d17be8a604 Mon Sep 17 00:00:00 2001 From: bergware Date: Sun, 16 Feb 2025 23:20:37 +0100 Subject: [PATCH] rc.nginx: force a restart of nginx when interface binding fails This prevents 'access refused', which may happen when nginx gets initially started with no IP assignment. --- etc/rc.d/rc.nginx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/etc/rc.d/rc.nginx b/etc/rc.d/rc.nginx index 6ce029b6c..4b8eb4f3d 100755 --- a/etc/rc.d/rc.nginx +++ b/etc/rc.d/rc.nginx @@ -31,6 +31,7 @@ TSCERTPATH="$SSL/certs/ts_bundle.pem" MYSERVERS="/boot/config/plugins/dynamix.my.servers/myservers.cfg" DEFAULTS="/etc/default/nginx" SYSTEM="/sys/class/net" +SYSLOG="/var/log/syslog" # Load defaults # Defines NGINX_CUSTOMFA for custom Content-Security-Policy frame-ancestors url @@ -774,7 +775,13 @@ nginx_reload(){ if nginx_check; then log "Reloading $DAEMON configuration..." kill -HUP $(cat $PID) - sleep 3 + sleep 1 + if tail -8 $SYSLOG | grep -qm1 'Address already in use'; then + # unconditional restart when binding fails + sleep 2 + log "Restarting $DAEMON..." + nginx_renew + fi else log "Invalid configuration, $DAEMON not reloaded" return 1