diff --git a/doc/config.md b/doc/config.md index ccd9c310..dea907c2 100644 --- a/doc/config.md +++ b/doc/config.md @@ -450,6 +450,8 @@ configurable with the following options: a crashing service, default: 2 seconds for the first five retries, then back-off to 5 seconds. The maximum of this configured value and the above (2 and 5) will be used + * `restart:always` -- no upper limit on the number of times Finit + tries to restart a crashing service. Same as `restart:-1` * `norestart` -- dont restart on failures, same as `restart:0` * `respawn` -- bypasses the `restart` mechanism completely, allows endless restarts. Useful in many use-cases, but not what `service` diff --git a/man/finit.conf.5 b/man/finit.conf.5 index 6d3c95a7..7ed8509c 100644 --- a/man/finit.conf.5 +++ b/man/finit.conf.5 @@ -304,6 +304,10 @@ number of seconds before Finit tries to restart a crashing service, default: 2 seconds for the first five retries, then back-off to 5 seconds. The maximum of this configured value and the above (2 and 5) will be used +.It Cm restart:always +no upper limit on the number of times Finit tries to restart a crashing +service. Same as +.Cm restart:-1 .It Cm norestart dont restart on failures, same as .Cm restart:0 diff --git a/src/service.c b/src/service.c index 6567793b..8dd8a88a 100644 --- a/src/service.c +++ b/src/service.c @@ -1274,6 +1274,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file) forking = 1; else if (!strncasecmp(cmd, "manual:yes", 10)) manual = 1; + else if (!strncasecmp(cmd, "restart:always", 14)) + restart_max = -1; else if (!strncasecmp(cmd, "restart:", 8)) restart_max = atoi(&cmd[8]); else if (!strncasecmp(cmd, "restarttmo:", 11)) /* compat alias */ @@ -1759,7 +1761,7 @@ static void service_retry(svc_t *svc) } /* Peak instability index */ - if (*restart_cnt >= svc->restart_max) { + if (svc->restart_max != -1 && *restart_cnt >= svc->restart_max) { logit(LOG_CONSOLE | LOG_WARNING, "Service %s keeps crashing, not restarting.", svc_ident(svc, NULL, 0)); svc_crashing(svc); diff --git a/src/svc.h b/src/svc.h index 4c0ceeca..5d7aa369 100644 --- a/src/svc.h +++ b/src/svc.h @@ -139,7 +139,7 @@ typedef struct svc { /* Counters */ char once; /* run/task, (at least) once per runlevel */ unsigned int restart_tot; /* Total restarts ever, summarized, including `initctl restart` */ - unsigned char restart_max; /* Maximum number of restarts allowed */ + int restart_max; /* Maximum number of restarts allowed */ int restart_tmo; /* Time required for the service to start. */ unsigned char oncrash_action; /* Action to perform in crashed state. */ char respawn; /* ttys, or services with `respawn`, never increment restart_cnt */