From cab6c197d4a1756a84afa113f8c5377db73f1fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B2=E8=B1=B9=20=CE=A6=CF=89=CE=A6?= Date: Thu, 26 Mar 2026 05:44:59 +0800 Subject: [PATCH] feat: add auto-restart policy with failure threshold for systemd service Enable Restart=on-failure with a 5-second delay. Implement a safety limit: stop restarting if the service fails more than 5 times within 1 minute. Prevent infinite crash loops and resource exhaustion. --- src/chronotron.service | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/chronotron.service b/src/chronotron.service index fa19b7b..e1a1908 100644 --- a/src/chronotron.service +++ b/src/chronotron.service @@ -2,6 +2,11 @@ Description=Display chrony statistics on 4x20 LCD After=network.target +//If in 1 min fail more then 5 times, stop restart service. +StartLimitIntervalSec=60s +StartLimitBurst=5 + + [Service] Type=simple User=root @@ -10,6 +15,9 @@ WorkingDirectory=/opt/chronotron ExecStart=/opt/chronotron/chronotron.py StandardOutput=syslog StandardError=syslog +//If service fail, auto restart after 5 sec +Restart=on-failure +RestartSec=5s [Install] WantedBy=multi-user.target