service: start restart always at two seconds between restarts

A crashing service with restart always waited five seconds before
every restart.  It should wait two seconds for the first five, like a
service with the default restart-max:

    service foo {
        restart = "always"
        command = "foo"
    }

The back-off starts after half of restart-max attempts.  For restart
always restart-max is -1, so half of it was zero and the back-off
began with the first restart.  Use the default restart-max instead.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-19 20:39:40 +01:00
1 parent 631baab756
commit 4e1b0d4fbe
5 files changed
+67 -5

No files matched your search

+4 -3
View File
@@ -3267,7 +3267,7 @@ static void service_cleanup_script(svc_t *svc)
static void service_retry(svc_t *svc)
{
char *restart_cnt = (char *)&svc->restart_cnt;
int timeout;
int timeout, half;
service_timeout_cancel(svc);
@@ -3326,8 +3326,9 @@ static void service_retry(svc_t *svc)
dbg("%s crashed, trying to start it again, attempt %d", svc_ident(svc, NULL, 0), *restart_cnt);
if ((*restart_cnt) == 1)
svc->restart_saved = svc->restart_tmo;
/* Wait 2s for the first 5 respawns, then back off to 5s */
timeout = ((*restart_cnt) <= (svc->restart_max / 2)) ? 2000 : 5000;
/* Wait 2s for the first half of the attempts, then back off to 5s */
half = (svc->restart_max == -1 ? SVC_RESPAWN_MAX : svc->restart_max) / 2;
timeout = *restart_cnt <= half ? 2000 : 5000;
/* If a longer timeout was specified in the conf, use that instead. */
svc->restart_tmo = max(svc->restart_tmo, timeout);
if (WIFEXITED(svc->status))