Caddy.Server.External (Caddy v2.3.1)
View SourceExternal Caddy Server management.
Manages a Caddy instance that is started and controlled externally (e.g., by systemd, launchd, or another process manager).
This GenServer:
- Monitors Caddy health via the Admin API
- Executes system commands for lifecycle operations
- Pushes configuration when Caddy becomes available
- Emits telemetry events for observability
Configuration
config :caddy, mode: :external
config :caddy, admin_url: "http://localhost:2019"
config :caddy, health_interval: 30_000
config :caddy, commands: [
start: "systemctl start caddy",
stop: "systemctl stop caddy",
restart: "systemctl restart caddy",
status: "systemctl is-active caddy"
]State
The server maintains:
caddy_status- Current known status (:running,:stopped,:unknown)config_pushed- Whether initial config has been pushedlast_health_check- Timestamp of last successful health check
Summary
Functions
Check the current status of the external Caddy instance.
Returns a specification to start this module under a supervisor.
Execute a lifecycle command.
Get Caddyfile content via Admin API.
Trigger an immediate health check.
Push configuration to the running Caddy instance.
Restart the external Caddy instance using the configured restart command.
Start the external Caddy instance using the configured start command.
Start the external server GenServer.
Stop the external Caddy instance using the configured stop command.
Types
@type state() :: %{ caddy_status: :running | :stopped | :unknown, config_pushed: boolean(), last_health_check: DateTime.t() | nil, health_interval: pos_integer() }
Functions
@spec check_status() :: :running | :stopped | :unknown
Check the current status of the external Caddy instance.
Returns a specification to start this module under a supervisor.
See Supervisor.
Execute a lifecycle command.
Available commands: :start, :stop, :restart, :status
@spec get_caddyfile() :: binary()
Get Caddyfile content via Admin API.
@spec health_check() :: :ok
Trigger an immediate health check.
@spec push_config() :: :ok | {:error, term()}
Push configuration to the running Caddy instance.
Restart the external Caddy instance using the configured restart command.
Start the external Caddy instance using the configured start command.
Start the external server GenServer.
Stop the external Caddy instance using the configured stop command.