No downtime Caddyfile reloads without watch?

I am running caddy in a docker container.

# ./caddy version
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

When I experiment with Caddyfiles, I run caddy validate first and only then reload the Caddyfile.

My understanding is that there are atleast 3 ways (incl. API) to have caddy reload the Caddyfile without needing to restart it:

  1. Send the caddy instance a USR1: but when I do a kill -USR1 1 inside the docker container where caddy’s PID is 1, I don’t see it reloading the Caddyfile (/root/.config/caddy/autosave.json remains the same).
# ps
PID   USER     TIME  COMMAND
  1   root     0:00  ./caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
  1. ./caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile results in an error:
reload: sending configuration to instance: performing request: Post "http://localhost:2019/load": dial tcp 127.0.0.1:2019: connect: connection refused

This is the stock /root/.config/caddy/autosave.json before reload

{"admin":{"disabled":true},"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"logs":{"logger_names":{"example.com":"log0"},"skip_hosts":["www.example.com"]},"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"static_response","headers":{"Location":["https://example.com{http.request.uri}"]},"status_code":302}],"match":[{"host":["www.example.com"]}]}]}],"match":[{"host":["www.example.com"]}],"terminal":true},{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"service_container:666"}]}]}]}],"match":[{"host":["example.com"]}],"terminal":true}]}}},"tls":{"automation":{"policies":[{"issuers":[{"challenges":{"dns":{"resolvers":["1.1.1.1"]}},"email":"admin@example.com","module":"acme"},{"challenges":{"dns":{"resolvers":["1.1.1.1"]}},"email":"admin@example.com","module":"zerossl"}],"subjects":["www.example.com","example.com"]}]}}},"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"include":["http.log.access.log0"],"level":"INFO"}}}}

This is the /root/.config/caddy/autosave.json I would expect to see after reload

{"admin":{"disabled":true},"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"logs":{"logger_names":{"example.com":"log0"},"skip_hosts":["www.example.com"]},"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"static_response","headers":{"Location":["https://example.com{http.request.uri}"]},"status_code":302}],"match":[{"host":["www.example.com"]}]}]}],"match":[{"host":["www.example.com"]}],"terminal":true},{"handle":[{"handler":"subroute","routes":[{"group":"group1","handle":[{"handler":"rewrite","uri":"/legacy"}]},{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"service_container:666"}]}]}]}],"match":[{"host":["example.com"]}],"terminal":true}]}}},"tls":{"automation":{"policies":[{"issuers":[{"challenges":{"dns":{"resolvers":["1.1.1.1"]}},"email":"admin@example.com","module":"acme"},{"challenges":{"dns":{"resolvers":["1.1.1.1"]}},"email":"admin@example.com","module":"zerossl"}],"subjects":["www.example.com","example.com"]}]}}},"logging":{"logs":{"default":{"exclude":["http.log.access.log0"]},"log0":{"include":["http.log.access.log0"],"level":"INFO"}}}}

Don’t know about your first point (signal), but your second point is obvious:
you disabled the admin api endpoint in your current config

"admin":{"disabled":true}

the admin api endpoint is the mechanism how the reload operation worlks (the new config would be sent to the api endpoint per http), see https://caddyserver.com/docs/json/admin/disabled/

4 Likes

@jok is right on the money. That’s why we emit a warning when you disable the admin endpoint.

Caddy doesn’t respond to USR signals. (Use caddy reload instead.)

3 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.