Date: 2026-05-11
Time: 15:56
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.
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).
Key configuration from ServerConfig:
grace_period — seconds to wait after server empties before teardownpoll_interval — seconds between player count checksslack_channel — Slack channel for teardown notificationsinventorypath / statepath — FTL2 inventory and state file pathsscript — identifies which game script to load via scripts.get_script()FTL2 automation context is configured with:
LINODETOKEN and SLACKTOKEN (via Vault)failfast=True, autoinstall_deps=TrueHardcoded: 600s warmup before first poll (server boot time).
error.except Exception: pass).state object is updated in-place throughout — status, playercount, emptysince, watchdogactive, ipaddress, last_error. The TUI reads these fields.state.watchdog_active is set False externally, the loop exits and status reverts to "provisioned" or "stopped" based on actual provisioning state.ftl2.automation — async context manager providing the FTL2 runtime (ftl object) for running modules.config.ServerConfig — server definition (IP lookup, paths, timing, script selection).scripts — game-specific script interface; getscript() returns an object with getplayercount(), backupworld(), saveandstop(), destroy()community.general.linode_v4 — Linode API module (used by destroy scripts)community.general.slack — Slack notification module (called directly via ftl.local)secret_bindings