V2: systemd service-file best practices

I would like to run Caddy v2 as a service on debian 10 with systemd but did not found any service-file, yet

v1 on my setup looks like this:

$ cat /lib/systemd/system/caddy.service
[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

; User and group the process will run as.
User=caddy
Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=$HOME

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/etc/caddy/caddy -agree=true -conf=/etc/caddy/Caddyfile -email=mailing123@hnrk.io -quic
ExecReload=/bin/kill -USR1 $MAINPID

; Use graceful shutdown with a reasonable timeout
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=4096

[Install]
WantedBy=multi-user.target

Are there any best practices to keep in mind for a new v2 systemd service file?

Thanks!

v2 doesn’t implement USR1 for now, because of its API. Of course the ExecStart would be different for v2. Your service file will vary depending on if you use caddy run or caddy start. Probably best to use run.

2 Likes

Thanks! This is my v2 systemd service file now:

[Unit]
Description=Caddy v2
Documentation=https://github.com/caddyserver/caddy/wiki/v2:-Documentation
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

; User and group the process will run as.
User=caddy
Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=$HOME

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/etc/v2caddy/caddy run -config=/etc/v2caddy/Caddyfile

; Use graceful shutdown with a reasonable timeout
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=4096

[Install]
WantedBy=multi-user.target
2 Likes

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