diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 8b1e637..c3055e7 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -20,7 +20,9 @@ services: depends_on: - genie - streamlit - command: /renew-certs.sh + volumes: + - /path/to/host/certificates:/etc/letsencrypt/live/app.batterymodel.com:ro + command: /bin/bash -c "/renew-certs.sh && nginx -g 'daemon off;'" streamlit: image: ghcr.io/battmoteam/battmogui_streamlit:latest diff --git a/nginx/renew-certs.sh b/nginx/renew-certs.sh index 3a8304e..3fe01a4 100644 --- a/nginx/renew-certs.sh +++ b/nginx/renew-certs.sh @@ -1,34 +1,6 @@ #!/bin/bash set -e -# Function to start Nginx in the background -start_nginx() { - nginx -g 'daemon off;' & - NGINX_PID=$! -} +certbot certonly --webroot -w /usr/share/nginx/html -d app.batterymodel.com --email lorena.hendrix@sintef.no --agree-tos --non-interactive -# Function to stop the Nginx process -stop_nginx() { - if [ -n "$NGINX_PID" ]; then - kill "$NGINX_PID" - fi -} -# Trap to ensure Nginx is stopped on script exit -trap stop_nginx EXIT - -# Start Nginx to serve the challenge files -start_nginx - -# Obtain or renew certificates -if [ ! -d "/etc/letsencrypt/live/app.batterymodel.com" ]; then - certbot certonly --webroot -w /usr/share/nginx/html -d app.batterymodel.com --email lorena.hendrix@sintef.no --agree-tos --non-interactive -else - certbot renew --webroot -w /usr/share/nginx/html -fi - -# Stop the background Nginx process -stop_nginx - -# Start Nginx in the foreground -exec nginx -g 'daemon off;' \ No newline at end of file