chore: checkpoint runtime stack changes

This commit is contained in:
Nick Sweeting 2026-05-28 07:53:09 -07:00
parent a55179fcd8
commit 523a10b94c
No known key found for this signature in database
3 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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()

View File

@ -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",
}