From 47ddd834c7c0e633665a5718626d3d481e8e4b82 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Tue, 26 May 2020 09:02:37 -0400 Subject: [PATCH] Starts nginx inside the bash script --- Dockerfile | 5 +---- docker/substitute-env-variables.sh | 13 ++++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 85f88fd..645a8ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,12 +26,9 @@ RUN chmod +x ./entrypoint.sh # The entrypoint.sh script will run after the container finishes starting. # Substitutes environment variables in nginx configuration and index.html, -# then reloads nginx. +# then starts/reloads nginx. ENTRYPOINT ["./entrypoint.sh", \ "/etc/nginx/html/index.html,/etc/nginx/conf.d/default.conf", \ "PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0", \ "/etc/nginx/html", \ "true"] - -### STAGE 3: Profit! ### -CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/substitute-env-variables.sh b/docker/substitute-env-variables.sh index 36e49a3..909b083 100755 --- a/docker/substitute-env-variables.sh +++ b/docker/substitute-env-variables.sh @@ -89,9 +89,16 @@ done if [ $num_args -ge 4 ] && [ "$4" == "true" ]; then # Check to see if nginx command is available if hash nginx 2> /dev/null; then - echo "Reloading nginx..." - exec nginx -s reload - echo "nginx reloaded." + # Check to see if nginx is already running + if [ -e /var/run/nginx.pid ]; then + echo "nginx is currently running. Reloading nginx..." + exec nginx -s reload + echo "nginx reloaded." + else + echo "nginx is not yet running. Starting nginx..." + exec nginx -g 'daemon off;' + echo "nginx started." + fi else echo "nginx command not found on this system." fi