等待 Nginx 新进程完成灰度入口切换
This commit is contained in:
+10
-1
@@ -70,6 +70,8 @@ proxy_changed=0
|
||||
rollback() {
|
||||
result=$?
|
||||
trap - ERR
|
||||
# ERR is inherited by command substitutions; only the parent may roll back.
|
||||
if ((BASH_SUBSHELL)); then exit "$result"; fi
|
||||
set +e
|
||||
if ((proxy_changed)); then
|
||||
if [[ -f "$release/previous-site.conf" ]]; then cp -p "$release/previous-site.conf" "$site"; else rm -f -- "$site"; fi
|
||||
@@ -102,7 +104,14 @@ install -m 644 "$release/site.conf" "$site"
|
||||
nginx -t
|
||||
nginx -s reload
|
||||
for path in / /api/export_chat /api/get_history; do
|
||||
code=$(curl --silent --show-error --resolve "$CHAT_DOMAIN:443:127.0.0.1" -o /dev/null -w '%{http_code}' "https://$CHAT_DOMAIN$path")
|
||||
code=''
|
||||
# A successful reload signal precedes the new workers accepting connections.
|
||||
for attempt in {1..10}; do
|
||||
if code=$(curl --silent --connect-timeout 3 --max-time 8 --resolve "$CHAT_DOMAIN:443:127.0.0.1" -o /dev/null -w '%{http_code}' "https://$CHAT_DOMAIN$path"); then
|
||||
[[ "$code" != 401 ]] || break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
[[ "$code" == 401 ]] || { echo 'Gray access protection verification failed.' >&2; false; }
|
||||
done
|
||||
printf '%s\n' "$release" > "$root/.current-release.new"
|
||||
|
||||
Reference in New Issue
Block a user