Caddy.Server (Caddy v2.3.1)
View SourceCaddy Server - Mode-based server selection.
This module delegates to the appropriate server implementation based on the configured mode:
:external(default) - UsesCaddy.Server.Externalto communicate with an externally managed Caddy:embedded- UsesCaddy.Server.Embeddedto manage a local Caddy process
Embedded Mode
In embedded mode, the Caddy binary is spawned and managed directly by this application. The server handles process lifecycle, output logging, and cleanup.
External Mode
In external mode, Caddy is managed by an external system (e.g., systemd). This server communicates via the Admin API and can execute system commands for lifecycle operations.
Configuration
# External mode (default)
config :caddy, mode: :external
config :caddy, admin_url: "http://localhost:2019"
config :caddy, commands: [
start: "systemctl start caddy",
stop: "systemctl stop caddy",
restart: "systemctl restart caddy",
status: "systemctl is-active caddy"
]
# Embedded mode
config :caddy, mode: :embedded
config :caddy, caddy_bin: "/usr/bin/caddy"
Summary
Functions
Check the status of the Caddy server.
Returns a child specification for the supervisor.
Execute a lifecycle command (external mode only).
Get Caddyfile content of the current running server.
Returns the current server implementation module.
Start the appropriate server based on the configured mode.
Functions
@spec check_status() :: :running | :stopped | :unknown
Check the status of the Caddy server.
Returns:
:running- Caddy is running and responding:stopped- Caddy is not running:unknown- Status cannot be determined
Returns a child specification for the supervisor.
This delegates to the appropriate implementation based on mode.
Execute a lifecycle command (external mode only).
Available commands: :start, :stop, :restart, :status
Returns {:error, :embedded_mode} if called in embedded mode.
@spec get_caddyfile() :: binary()
Get Caddyfile content of the current running server.
In embedded mode, reads from the local etc directory. In external mode, fetches via Admin API.
@spec impl_module() :: module()
Returns the current server implementation module.
Start the appropriate server based on the configured mode.