fix(cliproxy): finish concurrent update recovery

This commit is contained in:
Tam Nhu Tran committed 2026-08-10 22:13:29 -04:00
1 parent 192b27fbb2
commit fc56ecaac4
14 files changed
+428 -87

No files matched your search

+18 -2
View File
@@ -44,6 +44,14 @@ compose_up() {
-f "$compose_file" up -d --build
}
compose_recreate() {
cd "$compose_dir"
docker compose --project-name "$compose_project" --project-directory "$compose_dir" \
-f "$compose_file" up -d --force-recreate --no-build || \
docker compose --project-name "$compose_project" --project-directory "$compose_dir" \
-f "$compose_file" up -d --force-recreate --build
}
if ! docker inspect "$container_name" >/dev/null 2>&1; then
log "Container $container_name is missing; recreating from $compose_file"
compose_up
@@ -79,6 +87,14 @@ if docker exec "$container_name" \
fi
log 'Supervisor recovery failed; restarting the container'
docker restart "$container_name" >/dev/null
if docker restart "$container_name" >/dev/null; then
if wait_for_health; then
log "Container $container_name recovered and passed both health probes"
exit 0
fi
fi
log "Container $container_name is still unhealthy; recreating it from $compose_file"
compose_recreate
wait_for_health
log "Container $container_name recovered and passed both health probes"
log "Container $container_name was recreated and passed both health probes"
+44 -1
View File
@@ -55,6 +55,10 @@ stage_binary="$stage_dir/cli-proxy-api-plus"
stage_version="$stage_dir/.version"
backup_binary="$stage_root/previous-binary"
backup_version="$stage_root/previous-version"
install_lock_target='/root/.ccs/cliproxy/bin/.install-lifecycle-plus'
install_lock_dir="$install_lock_target.lock"
install_lock_stale_seconds=600
install_lock_owned=0
maintenance_started=0
supervisorctl_cmd() {
@@ -65,6 +69,40 @@ cleanup() {
rm -rf -- "$stage_root"
}
remove_stale_install_lock() {
lock_mtime="$(
stat -c %Y "$install_lock_dir" 2>/dev/null || stat -f %m "$install_lock_dir" 2>/dev/null
)" || return 0
current_time="$(date +%s)"
lock_age=$((current_time - lock_mtime))
if [ "$lock_age" -gt "$install_lock_stale_seconds" ]; then
rmdir "$install_lock_dir" 2>/dev/null || true
fi
}
acquire_install_lock() {
mkdir -p "$install_lock_target"
attempts=0
while ! mkdir "$install_lock_dir" 2>/dev/null; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 240 ]; then
printf '[X] Timed out waiting for CLIProxy install lifecycle lock\n' >&2
return 1
fi
remove_stale_install_lock
sleep 0.25
done
install_lock_owned=1
touch "$install_lock_dir"
}
release_install_lock() {
if [ "$install_lock_owned" -eq 1 ]; then
rmdir "$install_lock_dir" 2>/dev/null || true
install_lock_owned=0
fi
}
wait_for_proxy() {
attempts=0
while [ "$attempts" -lt 30 ]; do
@@ -107,6 +145,7 @@ on_exit() {
printf '[X] CLIProxy rollback failed; recovery files preserved at %s\n' "$stage_root" >&2
fi
fi
release_install_lock
if [ "$rollback_failed" -eq 0 ]; then
cleanup
else
@@ -115,7 +154,10 @@ on_exit() {
exit "$rc"
}
trap on_exit EXIT INT TERM HUP
trap on_exit EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
trap 'exit 129' HUP
mkdir -p "$stage_ccs_dir"
CCS_DIR="$stage_ccs_dir" ccs cliproxy --latest --backend plus
@@ -123,6 +165,7 @@ test -x "$stage_binary"
test -s "$stage_version"
"$stage_binary" --version >/dev/null
acquire_install_lock
cp -p "$live_binary" "$backup_binary"
cp -p "$live_version" "$backup_version"