Skip to main content

Module lifecycle

Module lifecycle 

Source
Expand description

Daemon lifecycle management: PID file, Unix domain socket, grace period, signal handling, and cleanup.

This module contains all the logic for the daemon’s lifecycle:

  • PID file at StorageLayout::daemon_pid_file() prevents duplicate instances and allows clients to detect a running daemon.
  • Unix domain socket at StorageLayout::daemon_socket() accepts connections from MCP server proxies.
  • Grace period (5 minutes) triggers automatic shutdown when no clients are connected.
  • Signal handling catches SIGTERM/SIGINT for clean shutdown.

Constants§

GRACE_PERIOD
Duration of the grace period before the daemon shuts down after the last client disconnects.

Functions§

check_existing_daemon
Check whether an existing PID file points to a running process.
cleanup
Best-effort removal of the PID file and socket.
run_daemon
Run the daemon’s accept loop and grace-period shutdown logic.
write_pid_file
Write the current process ID to the PID file.