Best practices for auto restart of caddy.service

1. The problem I’m having:

Systemd unitfile for running caddy as a service is not specifying rules regarding the restart of the service. When the caddy server crashes or is killed, it is not auto restarted.

:question: What is the best practice to keep caddy all the time up and running using systemd service?
:question: Is there a recommended aproach to restart caddy server when the systemd service is alive but the caddy server is not responding?
:question: Are there any examples, how for example a watchdog can be used to solve this issue?

2. Error messages and/or full log output:

no error messages

3. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

sudo apt install caddy

a. System environment:

Debian GNU/Linux 11 (bullseye)
Linux gw 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux

b. Command:

no command

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateDevices=yes
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

www.mycompany.net {
	root * /var/www
	file_server

	log {
		format json
		output file /var/log/caddy/www.log
	}
}

See Keep Caddy Running — Caddy Documentation
and Auto restart caddy if it crashes under systemd by ncw · Pull Request #92 · caddyserver/dist · GitHub

1 Like

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