From 54af42121fc54a6334d85b57297725d13ce70a26 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 10 Dec 2022 21:41:24 +0000 Subject: [PATCH] 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. --- src/docs/markdown/running.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/docs/markdown/running.md b/src/docs/markdown/running.md index b809752..33f5377 100644 --- a/src/docs/markdown/running.md +++ b/src/docs/markdown/running.md @@ -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:
sudo systemctl restart caddy