Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add filewatcher to reverse-proxy container to restart when SSL cert is updated (#635)

Leendert de Borst65c1a6044741
diff --git a/apps/server/Dockerfile b/apps/server/Dockerfile
index e8e8b0364..d8bbe9826 100644
--- a/apps/server/Dockerfile
+++ b/apps/server/Dockerfile
@@ -7,8 +7,8 @@ LABEL org.opencontainers.image.licenses="AGPL-3.0"
LABEL org.opencontainers.image.title="AliasVault Reverse Proxy"
LABEL org.opencontainers.image.description="Nginx reverse proxy for AliasVault. Part of multi-container setup and can be deployed via install.sh (see docs.aliasvault.net)"
-# Install OpenSSL
-RUN apk add --no-cache openssl
+# Install OpenSSL and inotify-tools for certificate watching
+RUN apk add --no-cache openssl inotify-tools
# Copy configuration and entrypoint script
COPY apps/server/nginx.conf /etc/nginx/nginx.conf
diff --git a/apps/server/entrypoint.sh b/apps/server/entrypoint.sh
index 41ad6cd17..919db936e 100644
--- a/apps/server/entrypoint.sh
+++ b/apps/server/entrypoint.sh
@@ -29,5 +29,35 @@ else
EOF
fi
-# Start nginx
-nginx -g "daemon off;"
\ No newline at end of file
+# Start nginx and check if it started successfully
+nginx
+if [ $? -ne 0 ]; then
+ echo "Failed to start nginx, exiting..."
+ exit 1
+fi
+
+# Start certificate watcher if Let's Encrypt is enabled
+if [ "${LETSENCRYPT_ENABLED}" = "true" ]; then
+ echo "Starting certificate watcher for automatic nginx reload..."
+
+ # Watch for changes and reload nginx
+ while true; do
+ # Watch the entire Let's Encrypt live directory for any certificate changes
+ inotifywait -e modify,create,delete,move -r /etc/nginx/ssl-letsencrypt 2>/dev/null
+
+ # Wait a moment for all certificate files to be written
+ sleep 2
+
+ echo "Certificate change detected, reloading nginx..."
+ nginx -s reload 2>&1
+ done &
+fi
+
+# Keep the container running and monitor nginx
+while true; do
+ if ! pgrep nginx > /dev/null; then
+ echo "Nginx is not running, exiting..."
+ exit 1
+ fi
+ sleep 10
+done