diff --git a/Dockerfile b/Dockerfile index 057bd8a..51077e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -91,6 +91,8 @@ ENV \ PROJECT_INACTIVITY_TIMEOUT=0 \ # Disable DANGLING_TIMEOUT by default PROJECT_DANGLING_TIMEOUT=0 \ + # Enable PROJECT_AUTOSTART by default + PROJECT_AUTOSTART=1 \ # Disable access log by default ACCESS_LOG=0 \ # Disable debug output by default diff --git a/README.md b/README.md index f4730ae..b6c13f4 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ docker run -d --name=nodejs \ ## Advanced proxy configuration These advanced settings can be used in CI sandbox environments and help keep the resource usage down by stopping -Docksal project containers after a period of inactivity. Projects are automatically restarting upon a new HTTP request. +Docksal project containers after a period of inactivity. Projects are automatically restarted upon a new HTTP request (unless `PROJECT_AUTOSTART` is set to `0`, see below.). `PROJECT_INACTIVITY_TIMEOUT` @@ -107,6 +107,9 @@ environment specific equivalent, e.g. `docksal-ci.env`). Note: permanent projects will still be put into hibernation according to `PROJECT_INACTIVITY_TIMEOUT`. +`PROJECT_AUTOSTART` + +Setting this variable to `0` will disable autostart projects by visiting project url. This option is active by default (set to `1`). ## Default and custom certs for HTTPS diff --git a/bin/proxyctl b/bin/proxyctl index 4726e5c..171a160 100755 --- a/bin/proxyctl +++ b/bin/proxyctl @@ -103,6 +103,9 @@ start () # Set logging prefix for the function and trigger a log entry export LOG_PREFIX='[start]' && log + # Disable projects autostart in case PROJECT_AUTOSTART set to 0 + [[ "$PROJECT_AUTOSTART" == 0 ]] && log "WARNING: Projects autostart is disabled." && return 0 + local type=${1} local id=${2} diff --git a/conf/nginx/lua/proxyctl.lua b/conf/nginx/lua/proxyctl.lua index 686d1b2..44a4884 100644 --- a/conf/nginx/lua/proxyctl.lua +++ b/conf/nginx/lua/proxyctl.lua @@ -1,12 +1,12 @@ -- Debug pring helper -function dpr(message) +local function dpr(message) if (tonumber(os.getenv("DEBUG_LOG")) > 0) then ngx.log(ngx.STDERR, "DEBUG: " .. message) end end -- Helper function to read a file from disk -function read_file(path) +local function read_file(path) local open = io.open local file = open(path, "rb") -- r read mode and b binary mode if not file then return nil end @@ -16,7 +16,7 @@ function read_file(path) end -- Returns loading.html for HTTP_OK and not-found.html otherwise -function response(status) +local function response(status) -- Load response body from disk -- This used to be done with ngx.location.capture, which does not support HTTP/2 and fails with https requests: -- See https://github.com/openresty/lua-nginx-module/issues/1285#issuecomment-376418678 @@ -62,7 +62,7 @@ if (lock_timestamp == 0) then -- Lanch project start script -- os.execute returs multiple values starting with Lua 5.2 - local status, exit, exit_code = os.execute("sudo /usr/local/bin/proxyctl start $(sudo /usr/local/bin/proxyctl lookup \"" .. ngx.var.host .. "\")") + local status, exit, exit_code = os.execute("sudo -E /usr/local/bin/proxyctl start $(sudo /usr/local/bin/proxyctl lookup \"" .. ngx.var.host .. "\")") if (exit_code == 0) then -- If all went well, reload the page diff --git a/conf/nginx/nginx.conf.tmpl b/conf/nginx/nginx.conf.tmpl index 357b5ba..2694c82 100644 --- a/conf/nginx/nginx.conf.tmpl +++ b/conf/nginx/nginx.conf.tmpl @@ -4,6 +4,9 @@ pid /var/run/nginx.pid; daemon off; env DEBUG_LOG; +env PROJECT_INACTIVITY_TIMEOUT; +env PROJECT_DANGLING_TIMEOUT; +env PROJECT_AUTOSTART; # Send logs to stderr error_log /dev/stderr warn;