Caddy server reload after update CaddyFile

  • explain what you are trying to do,
    I want to reload CaddyServer after changing CaddyFile without downtime.
  • show what you have already tried,
    I saw that I can do that with this 2 options right now:
  1. pkill -USR1 caddy
  2. ps -C caddy
    PID TTY TIME CMD
    1392 pts/0 00:00:00 caddy
    kill -s USR1 1392

And I don’t to know if this two options if right for me and will not make any downtime. And also if there is other options I need to know about?

Both those options will trigger a graceful reload of Caddy.

You may be interested in -pidfile, a command-line flag for Caddy that will tell it to write its process ID to the file you specify. You can then read that file to generate a kill command, like kill -s USR1 $(cat /path/to/pidfile).

https://caddyserver.com/docs/cli#pidfile

So they both do that without downtime, right?

Correct, a graceful reload of Caddy has no downtime.

If the reload fails, Caddy will continue serving sites using the old configuration, with no interruption to service.

2 Likes

In case your distro comes with systemd you might as well use its path unit files. (Adjust the following paths!)

# /etc/systemd/system/caddy-reload.path
[Unit]
Description=Trigger a reload of Caddy on changes to its config file

[Path]
PathChanged=/etc/caddy/CaddyFile

[Install]
WantedBy=multi-user.target
# /etc/systemd/system/caddy-reload.service
[Unit]
Description=Reload Caddy

[Service]
Type=oneshot
; ExecStart=/usr/bin/sleep 0.1s
ExecStart=/bin/systemctl try-reload-or-restart caddy.service
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.