From 523a10b94c1fc9ca4d6448c8bca173b63441ce27 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 28 May 2026 07:53:09 -0700 Subject: [PATCH] chore: checkpoint runtime stack changes --- archivebox/cli/archivebox_server.py | 6 ++++-- archivebox/cli/archivebox_update.py | 12 ++++++++++-- archivebox/workers/supervisord_util.py | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/archivebox/cli/archivebox_server.py b/archivebox/cli/archivebox_server.py index 027afa22..537f389d 100644 --- a/archivebox/cli/archivebox_server.py +++ b/archivebox/cli/archivebox_server.py @@ -78,7 +78,7 @@ def server( current_command, standby_until_runtime_stack_needed, ) - from archivebox.core.shutdown_util import foreground_shutdown_signals + from archivebox.core.shutdown_util import foreground_parent_watchdog, foreground_shutdown_signals if run_in_debug: print("[green][+] Starting ArchiveBox webserver in DEBUG mode...[/green]") @@ -96,7 +96,7 @@ def server( command = current_command(Process.TypeChoices.SERVER, data_dir=config.DATA_DIR, url=bind_url) try: - with foreground_shutdown_signals(): + with foreground_shutdown_signals(), foreground_parent_watchdog(): while True: standby_until_runtime_stack_needed(command, data_dir=config.DATA_DIR) sys.stdout.write(f"[*] ArchiveBox server parent pid={os.getpid()} is now running the orchestrator and server...\n") @@ -117,6 +117,8 @@ def server( keep_running=lambda: command_owns_runtime_stack(command, data_dir=config.DATA_DIR), should_stop_supervisord=lambda: command_owns_runtime_stack(command, data_dir=config.DATA_DIR), ) + if result == "interrupted": + break if not command_owns_runtime_stack(command, data_dir=config.DATA_DIR): print("[yellow][*] Another ArchiveBox command took over the runtime stack; standing by.[/yellow]") continue diff --git a/archivebox/cli/archivebox_update.py b/archivebox/cli/archivebox_update.py index 710a2263..061615da 100644 --- a/archivebox/cli/archivebox_update.py +++ b/archivebox/cli/archivebox_update.py @@ -255,6 +255,7 @@ def update( ), ) touched_snapshot_ids: set[str] = set() + exit_code = 0 try: wait_for_turn() @@ -395,6 +396,7 @@ def update( time.sleep(60) resume = None except (KeyboardInterrupt, asyncio.CancelledError) as err: + exit_code = 130 exact_resume = getattr(err, "archivebox_resume", None) resume_cmd = ["archivebox", "update"] if migrate_only: @@ -431,9 +433,15 @@ def update( print("\n[red][X] archivebox update interrupted.[/red]") print("[yellow]Hint: resume this idempotent update with:[/yellow]") print(f" [green]{shlex.join(resume_cmd)}[/green]") - raise SystemExit(130) + raise SystemExit(exit_code) + except SystemExit as err: + if isinstance(err.code, int): + exit_code = err.code + elif err.code: + exit_code = 1 + raise finally: - command.mark_exited() + command.mark_exited(exit_code=exit_code) if stop_daemon_stack: stop_own_supervisord_process() diff --git a/archivebox/workers/supervisord_util.py b/archivebox/workers/supervisord_util.py index b2cecb65..8b9429e7 100644 --- a/archivebox/workers/supervisord_util.py +++ b/archivebox/workers/supervisord_util.py @@ -168,6 +168,7 @@ RUNNER_ONCE_WORKER = lambda args, name="worker_runner_once": { "name": name, "command": _shell_join([sys.executable, "-m", "archivebox", "run", *args]), "autorestart": "false", + "stopwaitsecs": "1", "stdout_logfile": f"logs/{name}.log", }