E7: stop the tool runner alone and wait its drain bound
The service manager's stop signalled the tool runner's whole group, so its bundles died with their calls. The composer carries the runner's drain-bound setting on its process; the unit stops the runner alone and waits the bound and 15 s before it kills what is left, so the new runner starts only after the old one exits or that bound passes. Builds: design 47 H2 §813 (12); H-A-353; H-A-358
This commit is contained in:
@@ -293,6 +293,10 @@ func withNode(r *declaration.Process, node string) *declaration.Process {
|
||||
return &p
|
||||
}
|
||||
|
||||
// drainStopMargin is the seconds a draining process's stop timeout lies above its drain bound: the time it takes to stop
|
||||
// its children after its drain (H-A-358).
|
||||
const drainStopMargin = 15
|
||||
|
||||
// unitFor is the unit the mesh writes for a daemon.
|
||||
//
|
||||
// **Generated whole and never edited in place**, the same rule as every other managed file: an
|
||||
@@ -333,7 +337,15 @@ func unitFor(r *declaration.Process) string {
|
||||
}
|
||||
// Restarted when it exits, because something that stops is not something that stays up.
|
||||
// Delayed, so a process that fails at once does not spin the machine.
|
||||
b.WriteString("Restart=always\nRestartSec=5\n\n")
|
||||
b.WriteString("Restart=always\nRestartSec=5\n")
|
||||
// **A process that drains is stopped alone** (design 47 H2 §813 (12), H-A-353, H-A-358): the stop signal reaches it
|
||||
// and not its children, so the calls in flight finish within its drain bound and it stops its children itself; the
|
||||
// service manager waits the bound and the time they take before it kills what is left, so the new process starts only
|
||||
// after the old one exits or that bound passes.
|
||||
if r.DrainBound > 0 {
|
||||
fmt.Fprintf(&b, "KillMode=mixed\nTimeoutStopSec=%ds\n", r.DrainBound+drainStopMargin)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
|
||||
b.WriteString("[Install]\nWantedBy=multi-user.target\n")
|
||||
return b.String()
|
||||
|
||||
@@ -43,6 +43,16 @@ func TestTheUnitRunsWhatTheDaemonSaid(t *testing.T) {
|
||||
if strings.Contains(unit, "Type=oneshot") {
|
||||
t.Fatalf("a process that should stay up is declared a step:\n%s", unit)
|
||||
}
|
||||
// Design 47 H2 §813 (12), H-A-353, H-A-358: a process that drains is stopped alone, its stop waiting its drain bound and
|
||||
// 15 s for its children; one that does not keeps the service manager's defaults.
|
||||
if strings.Contains(unit, "KillMode=") || strings.Contains(unit, "TimeoutStopSec=") {
|
||||
t.Fatalf("a process with no drain bound has its stop written:\n%s", unit)
|
||||
}
|
||||
draining := aProcess()
|
||||
draining.DrainBound = 30
|
||||
if got := unitFor(draining); !strings.Contains(got, "Restart=always\nRestartSec=5\nKillMode=mixed\nTimeoutStopSec=45s\n\n[Install]") {
|
||||
t.Fatalf("a process with a drain bound of 30 s is not stopped alone within 45 s:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
// **Deterministic, because the unit is half the daemon's identity.** Environment held in a map
|
||||
|
||||
Reference in New Issue
Block a user