caddy stop command gracefully stops a running Caddy instance using the admin API.
Usage
Description
Stops the background Caddy process as gracefully as possible. It requires that the admin API is enabled and accessible, since it uses the API’s/stop endpoint.
The address of this request can be customized using the --address flag, or parsed from the given --config, or defaults to the standard admin API address.
Flags
Configuration file to use to parse the admin address, if
--address is not used.Caddy will load this config to determine where the admin API is listening.Name of config adapter to apply (when
--config is used).Only needed if the config file is not in JSON format.The address to use to reach the admin API endpoint, if not the default.Overrides the address parsed from
--config. Format: host:port or unix/path/to/socketExamples
Stop with default admin address
localhost:2019).
Stop with custom admin address
Stop by reading config file
Stop with custom admin address in config
If your Caddyfile has:Stop using Unix socket
Exit Codes
0- Success (Caddy stopped gracefully)1- Failed (could not stop Caddy)
How It Works
Thecaddy stop command:
- Determines the admin API address from:
- The
--addressflag (highest priority) - The
--configfile (parses admin config) - Default address
localhost:2019
- The
- Sends a POST request to
/stopon the admin API - Waits for the response
- Returns success or failure
Graceful Shutdown
When Caddy receives the stop command, it:- Stops accepting new connections
- Waits for active connections to complete (with a timeout)
- Cleans up resources
- Exits
The graceful shutdown timeout can be configured in the Caddy config. By default, Caddy will wait for active connections to finish.
Troubleshooting
Admin API not accessible
If you get an error like:- Caddy is not running, or
- The admin API is disabled, or
- The admin API is listening on a different address
Admin API disabled
If you disabled the admin API in your config:caddy stop. Instead, stop Caddy by:
- Sending a signal:
kill <pid> - Using the PID file:
kill $(cat /var/run/caddy.pid) - Using systemctl (if using systemd):
systemctl stop caddy
Wrong admin address
If your admin API is on a custom address, either:- Use
--addressflag:caddy stop --address localhost:2020 - Use
--configflag:caddy stop --config /path/to/config
Alternative Methods
Using signals
Using systemd
Related Commands
caddy start- Start Caddy in the backgroundcaddy run- Start Caddy in the foregroundcaddy reload- Reload the configuration without stopping