Overview

Date: 2026-05-11

Time: 15:56

Overview

The watchdog module monitors game servers managed by ftl2-servercraft and automatically tears them down when they've been empty for a configurable grace period. It runs as an async loop that polls player count via game-specific scripts, tracks empty/unreachable state, and orchestrates a backup-then-destroy sequence when shutdown conditions are met. It communicates status through a shared ServerState object (for TUI display) and a log callback.

Usage Patterns

The single entry point is run_watchdog(), called with a server config, mutable state object, and logging function:


await run_watchdog(
    config=server_config,      # ServerConfig with IP, paths, timing
    state=server_state,        # ServerState mutated in-place for TUI
    log_callback=log_fn,       # Callable[[str], None] for activity log
)

The function runs until one of three exits: (1) grace period expires and server is torn down, (2) server becomes unreachable 3 times consecutively and is torn down, or (3) state.watchdog_active is set to False externally (user stop).

API and Configuration

Key configuration from ServerConfig:

FTL2 automation context is configured with:

Hardcoded: 600s warmup before first poll (server boot time).

Key Behaviors

Relationships