running: How to auto-restart caddy with systemd (#284)

It was decided in https://github.com/caddyserver/dist/pull/92 that the
best way to auto restart caddy is using a systemd override file and
this documents how to do that.
This commit is contained in:
Nick Craig-Wood 2022-12-10 21:41:24 +00:00 committed by GitHub
parent a2742d8d8d
commit 54af42121f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -136,6 +136,15 @@ ExecReload=
ExecReload=/usr/bin/caddy reload --config /etc/caddy/caddy.json
```
Or, for example, if you'd like caddy to restart itself after 5s if it ever crashes unexpectedly:
```systemd
[Service]
# Automatically restart caddy if it crashes except if the exit code was 1
RestartPreventExitStatus=1
Restart=on-failure
RestartSec=5s
```
Then, save the file and exit the text editor, and restart the service for it to take effect:
<pre><code class="cmd bash">sudo systemctl restart caddy</code></pre>