* fix: keep nginx IPv6 listen only when IPv6 is available (#4596)
Commit 2c48b1896 (1.45.2) made the internal nginx proxy listen on the IPv6
wildcard ('listen [::]:7575;'), which aborts nginx startup on hosts/VMs with
IPv6 disabled:
nginx: [emerg] socket() [::]:7575 failed (97: Address family not supported by protocol)
A plain revert would reintroduce #2697 and break IPv6-only/dual-stack
environments where this listener is required. Instead, only emit the IPv6
listen directive when the host actually has IPv6 configured.
Reuse the envsubst step run.sh already performs: compute NGINX_LISTEN_IPV6
from /proc/net/if_inet6 and substitute it into the template. proc files always
report size 0, so presence is detected by grepping the file (not 'test -s').
* fix: honor HOMARR_DISABLE_IPV6 override in nginx config generation
Review feedback on #6539: give users an explicit opt-out from the IPv6
listener even when the host reports IPv6. The issue reporter (#4596)
requested such an env var, and the pattern matches the existing
ENABLE_DNS_CACHING IPv6 toggle. Auto-detection behavior is unchanged when
the var is unset. Validated in containers: override wins, dual-stack
preserved by default, IPv4-only fallback on IPv6-less hosts.
86 lines
2.5 KiB
Bash
86 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Create sub directories in volume
|
|
mkdir -p /appdata/db
|
|
mkdir -p /appdata/redis
|
|
mkdir -p /appdata/trusted-certificates
|
|
|
|
# Run migrations
|
|
if [ "$DB_MIGRATIONS_DISABLED" = "true" ]; then
|
|
echo "DB migrations are disabled, skipping"
|
|
else
|
|
echo "Running DB migrations"
|
|
DISABLE_REDIS_LOGS=true node ./db/migrations/$DB_DIALECT/migrate.cjs ./db/migrations/$DB_DIALECT
|
|
if [ $? -ne 0 ]; then
|
|
echo "ERROR: DB migrations failed, aborting startup"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Auth secret is generated every time the container starts as it is required, but not used because we don't need JWTs or Mail hashing
|
|
export AUTH_SECRET=$(openssl rand -base64 32)
|
|
|
|
# Start nginx proxy
|
|
# 1. Replace the HOSTNAME in the nginx template file
|
|
# 2. Create the nginx configuration file from the template
|
|
# 3. Start the nginx server
|
|
# Only listen on IPv6 when the host actually has IPv6 configured (#4596).
|
|
# Otherwise nginx aborts with "socket() [::]:7575 failed (97: Address family
|
|
# not supported by protocol)". Check HOMARR_DISABLE_IPV6 first so users can
|
|
# force IPv4-only even when the host supports IPv6, then probe for IPv6
|
|
# addresses via grep (not -s: proc files always report size 0).
|
|
export HOSTNAME
|
|
export NGINX_LISTEN_IPV6=''
|
|
if [ "${HOMARR_DISABLE_IPV6:-false}" != "true" ] && grep -q . /proc/net/if_inet6 2>/dev/null; then
|
|
NGINX_LISTEN_IPV6='listen [::]:7575;'
|
|
fi
|
|
envsubst '${HOSTNAME} ${NGINX_LISTEN_IPV6}' < /etc/nginx/templates/nginx.conf > /etc/nginx/nginx.conf
|
|
# Start services in the background and store their PIDs
|
|
nginx -g 'daemon off;' &
|
|
NGINX_PID=$!
|
|
|
|
if [ "$REDIS_IS_EXTERNAL" = "true" ]; then
|
|
echo "Using external Redis server at redis://$REDIS_HOST:$REDIS_PORT"
|
|
REDIS_PID=""
|
|
else
|
|
echo "Starting internal Redis server"
|
|
redis-server /app/redis.conf &
|
|
REDIS_PID=$!
|
|
fi
|
|
|
|
SHUTTING_DOWN=false
|
|
|
|
terminate() {
|
|
SHUTTING_DOWN=true
|
|
echo "Shutting down..."
|
|
kill -TERM $NEXTJS_PID 2>/dev/null
|
|
wait $NEXTJS_PID 2>/dev/null
|
|
kill -TERM $NGINX_PID 2>/dev/null
|
|
wait $NGINX_PID 2>/dev/null
|
|
if [ -n "$REDIS_PID" ]; then
|
|
kill -TERM $REDIS_PID 2>/dev/null
|
|
wait $REDIS_PID 2>/dev/null
|
|
fi
|
|
echo "Shutdown complete."
|
|
exit 0
|
|
}
|
|
|
|
trap terminate TERM INT
|
|
|
|
node apps/nextjs/server.js &
|
|
NEXTJS_PID=$!
|
|
|
|
while true; do
|
|
wait $NEXTJS_PID
|
|
EXIT_CODE=$?
|
|
|
|
if [ "$SHUTTING_DOWN" = true ]; then
|
|
break
|
|
fi
|
|
|
|
echo "Next.js exited with code $EXIT_CODE, restarting in 1s..."
|
|
sleep 1
|
|
node apps/nextjs/server.js &
|
|
NEXTJS_PID=$!
|
|
done
|