diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index ef5b233f..656c31a9 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -11,6 +11,9 @@ All relevant changes are documented in this file. - `shutdown` now takes a time, `now`, `+MIN`, or `HH:MM`, and a message. Finit warns logged-in users as the time approaches, refuses new logins from five minutes before, and `shutdown -c` cancels. Issue #149 +- The `restart_sec:` option of the line-based format is now spelled + `restart-sec:`, kebab-case like every other setting. The old spelling + is still accepted - Add `restart-max-sec`, a limit for the delay between restarts of a crashing service. When set, the delay doubles for each restart, from `restart-sec` up to the limit, and comes down again as the service keeps diff --git a/doc/config/migration.md b/doc/config/migration.md index e91cbb67..bf82ab1f 100644 --- a/doc/config/migration.md +++ b/doc/config/migration.md @@ -63,7 +63,7 @@ Service options | `manual:yes` | `manual-start = true` | | `remain:yes` | `remain-after-exit = true` | | `restart:always` / `restart:NUM` | `restart = "always"` / `restart-max = NUM` | -| `restart_sec:SEC` | `restart-sec = SEC` | +| `restart-sec:SEC` | `restart-sec = SEC` | | `restart-max-sec:SEC` | `restart-max-sec = SEC` | | `norestart` | `restart = "never"` | | `respawn` | `respawn = true` | @@ -82,7 +82,8 @@ Service options | `if:svc` / `if:` | `if = "svc"` / `if = "cond"`, no angle brackets | | `tty:/dev/x` | `tty = "/dev/x"` | | `nowarn` | leading `-` on `command` or `envfile` | -| `restarttmo:` | dropped, was already an alias for `restart_sec:` | +| `restart_sec:` | old spelling of `restart-sec:`, still accepted | +| `restarttmo:` | dropped, was already an alias for `restart-sec:` | Repeated stanzas ---------------- diff --git a/man/finit.conf.5 b/man/finit.conf.5 index b1fa7b57..cdff93aa 100644 --- a/man/finit.conf.5 +++ b/man/finit.conf.5 @@ -379,18 +379,20 @@ marked .Em crashed and must be restarted manually with .Xr initctl 8 . -.It Cm restart_sec:SEC +.It Cm restart-sec:SEC 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 +and the above (2 and 5) will be used. The old spelling, +.Cm restart_sec:SEC , +is still accepted .It Cm restart-max-sec:SEC replaces that back-off with a delay that doubles for each restart, from -.Cm restart_sec +.Cm restart-sec up to this limit, e.g. 10, 20, 40, and so on up to 300 seconds with -.Cm restart_sec:10 restart-max-sec:300 . +.Cm restart-sec:10 restart-max-sec:300 . Without -.Cm restart_sec +.Cm restart-sec the first restart is at once, then after 2, 4, 8 seconds. The delay comes down again as the service keeps running .It Cm restart:always diff --git a/src/conf.c b/src/conf.c index 76de4690..f695f66b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1668,7 +1668,7 @@ static void svc_translate(cfg_t *sec, int type, struct rlimit rlimit[], char *fi } if (sec_getint(sec, "restart-sec", NULL, &num)) - addtok(line, sizeof(line), "restart_sec:%ld", num); + addtok(line, sizeof(line), "restart-sec:%ld", num); if (sec_getint(sec, "restart-max-sec", NULL, &num)) addtok(line, sizeof(line), "restart-max-sec:%ld", num); diff --git a/src/service.c b/src/service.c index d3c742cc..b56aadaa 100644 --- a/src/service.c +++ b/src/service.c @@ -2396,9 +2396,9 @@ svc_t *service_register_desc(int type, char *cfg, const char *desc, else restart_max = atoi(arg); } - else if (MATCH_CMD(cmd, "restarttmo:", arg)) /* compat alias */ - restart_tmo = atoi(arg) * 1000; - else if (MATCH_CMD(cmd, "restart_sec:", arg)) + else if (MATCH_CMD(cmd, "restart-sec:", arg) || + MATCH_CMD(cmd, "restart_sec:", arg) || /* compat alias */ + MATCH_CMD(cmd, "restarttmo:", arg)) /* compat alias */ restart_tmo = atoi(arg) * 1000; else if (MATCH_CMD(cmd, "restart-max-sec:", arg)) { const char *errstr; diff --git a/test/restart-backoff.sh b/test/restart-backoff.sh index a8f34c71..a6cb1b2c 100755 --- a/test/restart-backoff.sh +++ b/test/restart-backoff.sh @@ -32,6 +32,16 @@ CONF run "initctl reload" } +# Same, with the line-based format, options in $1 +crash_line() +{ + run "rm -f $FINIT_CONF" + run "initctl reload" + run "rm -f $STARTS" + run "echo 'service $1 crash.sh -- Crashing' > $FINIT_CONF" + run "initctl reload" +} + test_teardown() { say "Running test teardown." @@ -67,3 +77,10 @@ assert_delay 4 5 4 5 say 'The restart counter stops where the delay peaks' assert "Restart counter is 2" "$(texec initctl status crash | awk '/Restarts/{ print $4 }')" = "(2/-1)" + +sep +say 'restart-sec in the line-based format, and its old spelling' +crash_line 'restart:always restart-sec:3' +assert_delay 1 2 3 4 +crash_line 'restart:always restart_sec:3' +assert_delay 1 2 3 4