diff --git a/deploy/update.sh b/deploy/update.sh index 48bcfa7..2fd7f93 100755 --- a/deploy/update.sh +++ b/deploy/update.sh @@ -84,19 +84,33 @@ fi VHOST_STAMP="$PREFIX/.vhost-applied" vhost_now=$(sha256sum "$APP/deploy/nginx-vhost.conf" | cut -d' ' -f1) -site_host=""; app_port="8080" -# Written by install.sh. Absent on a deployment that predates it, in which case -# the commands below are a template rather than a copy-paste. +site_host=""; app_port="" +# Written by install.sh, and absent on every deployment that predates it -- +# which is the case that most needs the one-time check below, so the port is +# recovered from the environment file and the vhost found by what it proxies to. +# Guessing "your-host" instead would have skipped the check on exactly the hosts +# it was added for. if [[ -f "$PREFIX/.deploy-env" ]]; then . "$PREFIX/.deploy-env" site_host="$SITE_HOST"; app_port="$APP_PORT" fi -installed_vhost="/etc/nginx/conf.d/${site_host:-your-host}.conf" +if [[ -z "$app_port" && -f "$PREFIX/lembas.env" ]]; then + app_port=$(sed -n 's/^LEMBAS_PORT=//p' "$PREFIX/lembas.env" | tail -1) +fi +app_port="${app_port:-8080}" + +installed_vhost="" +if [[ -n "$site_host" && -f "/etc/nginx/conf.d/$site_host.conf" ]]; then + installed_vhost="/etc/nginx/conf.d/$site_host.conf" +else + installed_vhost=$(grep -ls "proxy_pass http://127.0.0.1:$app_port" \ + /etc/nginx/conf.d/*.conf 2>/dev/null | head -1) +fi vhost_stale="" if [[ -f "$VHOST_STAMP" ]]; then [[ "$(cat "$VHOST_STAMP")" != "$vhost_now" ]] && vhost_stale="the template has changed" -elif [[ -n "$site_host" && -f "$installed_vhost" ]]; then +elif [[ -n "$installed_vhost" ]]; then # First run with this check, so there is no stamp to compare against. Rather # than assume what is installed is current -- which is what the unit check # does, and would hide exactly the change this was added for -- look for the @@ -109,7 +123,7 @@ if [[ -n "$vhost_stale" ]]; then echo "== nginx vhost ==" >&2 echo " $vhost_stale." >&2 echo " Review and reinstall it:" >&2 - echo " diff $installed_vhost <(sed \\" >&2 + echo " diff ${installed_vhost:-/etc/nginx/conf.d/your-host.conf} <(sed \\" >&2 echo " -e 's|__SITE_HOST__|${site_host:-your-host}|g' -e 's|__APP_PORT__|$app_port|g' \\" >&2 echo " $APP/deploy/nginx-vhost.conf)" >&2 echo " Then: sudo nginx -t && sudo systemctl reload nginx" >&2