@mark1russell7/service 0.8.19 → 0.8.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/backoff.d.ts +44 -2
- package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
- package/build/builder.js +499 -0
- package/build/builder.js.map +1 -0
- package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
- package/build/channel.d.ts +1 -1
- package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
- package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
- package/build/client/core.js.map +1 -0
- package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
- package/build/client/dial.js +52 -0
- package/build/client/dial.js.map +1 -0
- package/build/client/machine.js +29 -0
- package/build/client/machine.js.map +1 -0
- package/build/client/meets.d.ts +35 -0
- package/build/client/meets.js +78 -0
- package/build/client/meets.js.map +1 -0
- package/build/clock.d.ts +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +470 -0
- package/build/conformance.js.map +1 -0
- package/build/contract.d.ts +28 -0
- package/build/contract.js +184 -0
- package/build/contract.js.map +1 -0
- package/build/description.d.ts +161 -0
- package/build/description.js +11 -0
- package/build/description.js.map +1 -0
- package/build/drains.js +35 -0
- package/build/drains.js.map +1 -0
- package/build/events.d.ts +25 -0
- package/build/fakes.d.ts +43 -0
- package/build/fakes.js +93 -0
- package/build/fakes.js.map +1 -0
- package/build/grpc/client.d.ts +153 -0
- package/build/grpc/client.js +474 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/connection.d.ts +97 -0
- package/build/grpc/connection.js +59 -0
- package/build/grpc/connection.js.map +1 -0
- package/build/grpc/machine.d.ts +12 -0
- package/build/grpc/machine.js +149 -0
- package/build/grpc/machine.js.map +1 -0
- package/build/grpc/meets.d.ts +14 -0
- package/build/grpc/meets.js +105 -0
- package/build/grpc/meets.js.map +1 -0
- package/build/grpc/starting.d.ts +33 -0
- package/build/grpc/starting.js +89 -0
- package/build/grpc/starting.js.map +1 -0
- package/build/grpc.d.ts +9 -303
- package/build/grpc.js +7 -854
- package/build/health.d.ts +93 -0
- package/build/health.js +223 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +1 -1
- package/build/host/discovery.d.ts +61 -0
- package/build/host/discovery.js +113 -0
- package/build/host/discovery.js.map +1 -0
- package/build/host/env.d.ts +14 -0
- package/build/host/env.js +57 -0
- package/build/host/env.js.map +1 -0
- package/build/host/fakes.d.ts +82 -0
- package/build/host/fakes.js +239 -0
- package/build/host/fakes.js.map +1 -0
- package/build/host/group.d.ts +142 -0
- package/build/host/group.js +517 -0
- package/build/host/group.js.map +1 -0
- package/build/host/install.d.ts +96 -0
- package/build/host/install.js +330 -0
- package/build/host/install.js.map +1 -0
- package/build/host/lock.d.ts +78 -0
- package/build/host/lock.js +190 -0
- package/build/host/lock.js.map +1 -0
- package/build/host/logs.d.ts +26 -0
- package/build/host/logs.js +48 -0
- package/build/host/logs.js.map +1 -0
- package/build/host/node.d.ts +14 -0
- package/build/host/node.js +309 -0
- package/build/host/node.js.map +1 -0
- package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
- package/build/host/ports.js +17 -0
- package/build/host/ports.js.map +1 -0
- package/build/host/probes.d.ts +51 -0
- package/build/host/probes.js +139 -0
- package/build/host/probes.js.map +1 -0
- package/build/host/processes.d.ts +32 -0
- package/build/host/processes.js +63 -0
- package/build/host/processes.js.map +1 -0
- package/build/host/render.d.ts +84 -0
- package/build/host/render.js +235 -0
- package/build/host/render.js.map +1 -0
- package/build/host/watch.d.ts +90 -0
- package/build/host/watch.js +165 -0
- package/build/host/watch.js.map +1 -0
- package/build/host.d.ts +13 -671
- package/build/host.js +12 -2126
- package/build/http/answers.js +29 -0
- package/build/http/answers.js.map +1 -0
- package/build/http/fake-server.js +61 -0
- package/build/http/fake-server.js.map +1 -0
- package/build/http/outcome.d.ts +115 -0
- package/build/http/outcome.js +325 -0
- package/build/http/outcome.js.map +1 -0
- package/build/http/probes.d.ts +83 -0
- package/build/http/probes.js +232 -0
- package/build/http/probes.js.map +1 -0
- package/build/http/transport.d.ts +165 -0
- package/build/http/transport.js +517 -0
- package/build/http/transport.js.map +1 -0
- package/build/http-client/client.d.ts +121 -0
- package/build/http-client/client.js +330 -0
- package/build/http-client/client.js.map +1 -0
- package/build/http-client/connection.d.ts +78 -0
- package/build/http-client/connection.js +54 -0
- package/build/http-client/connection.js.map +1 -0
- package/build/http-client/machine.d.ts +14 -0
- package/build/http-client/machine.js +109 -0
- package/build/http-client/machine.js.map +1 -0
- package/build/http-client/meets.d.ts +11 -0
- package/build/http-client/meets.js +74 -0
- package/build/http-client/meets.js.map +1 -0
- package/build/http-client/session.d.ts +87 -0
- package/build/http-client/session.js +99 -0
- package/build/http-client/session.js.map +1 -0
- package/build/http-client/starting.d.ts +25 -0
- package/build/http-client/starting.js +65 -0
- package/build/http-client/starting.js.map +1 -0
- package/build/http-client.d.ts +9 -330
- package/build/http-client.js +8 -707
- package/build/http.d.ts +5 -353
- package/build/http.js +3 -1086
- package/build/identity.d.ts +16 -0
- package/build/identity.js +44 -0
- package/build/identity.js.map +1 -0
- package/build/index.d.ts +35 -412
- package/build/index.js +24 -3277
- package/build/knobs.d.ts +1 -0
- package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
- package/build/knobs.js.map +1 -0
- package/build/latch.d.ts +29 -0
- package/build/latch.js +122 -0
- package/build/latch.js.map +1 -0
- package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
- package/build/law.js +149 -0
- package/build/law.js.map +1 -0
- package/build/lifecycle.d.ts +144 -0
- package/build/lifecycle.js +411 -0
- package/build/lifecycle.js.map +1 -0
- package/build/limiter/machine.d.ts +40 -0
- package/build/limiter/machine.js +279 -0
- package/build/limiter/machine.js.map +1 -0
- package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
- package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
- package/build/limiter/policy.js.map +1 -0
- package/build/{limiter-BNKnwzeY.d.ts → limiter/quota.d.ts} +32 -74
- package/build/{limiter-DrM0PQV9.js → limiter/quota.js} +3 -418
- package/build/limiter/quota.js.map +1 -0
- package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
- package/build/limiter/store.js +145 -0
- package/build/limiter/store.js.map +1 -0
- package/build/limiter.d.ts +4 -3
- package/build/limiter.js +4 -2
- package/build/lint.d.ts +152 -0
- package/build/lint.js +576 -0
- package/build/lint.js.map +1 -0
- package/build/logger.d.ts +71 -0
- package/build/logger.js +183 -0
- package/build/logger.js.map +1 -0
- package/build/machines.d.ts +41 -0
- package/build/machines.js +451 -0
- package/build/machines.js.map +1 -0
- package/build/metrics.d.ts +53 -0
- package/build/metrics.js +111 -0
- package/build/metrics.js.map +1 -0
- package/build/mongodb/client.d.ts +131 -0
- package/build/mongodb/client.js +388 -0
- package/build/mongodb/client.js.map +1 -0
- package/build/mongodb/connection.d.ts +112 -0
- package/build/mongodb/connection.js +12 -0
- package/build/mongodb/connection.js.map +1 -0
- package/build/mongodb/machine.d.ts +14 -0
- package/build/mongodb/machine.js +122 -0
- package/build/mongodb/machine.js.map +1 -0
- package/build/mongodb/meets.d.ts +15 -0
- package/build/mongodb/meets.js +103 -0
- package/build/mongodb/meets.js.map +1 -0
- package/build/mongodb/starting.d.ts +29 -0
- package/build/mongodb/starting.js +77 -0
- package/build/mongodb/starting.js.map +1 -0
- package/build/mongodb.d.ts +8 -296
- package/build/mongodb.js +7 -682
- package/build/operation.d.ts +27 -0
- package/build/{operation-DF73RZOI.js → operation.js} +2 -2
- package/build/operation.js.map +1 -0
- package/build/otel.d.ts +2 -2
- package/build/pg/client.d.ts +96 -0
- package/build/pg/client.js +277 -0
- package/build/pg/client.js.map +1 -0
- package/build/pg/connection.d.ts +75 -0
- package/build/pg/connection.js +11 -0
- package/build/pg/connection.js.map +1 -0
- package/build/pg/machine.d.ts +13 -0
- package/build/pg/machine.js +111 -0
- package/build/pg/machine.js.map +1 -0
- package/build/pg/meets.d.ts +14 -0
- package/build/pg/meets.js +83 -0
- package/build/pg/meets.js.map +1 -0
- package/build/pg/starting.d.ts +26 -0
- package/build/pg/starting.js +62 -0
- package/build/pg/starting.js.map +1 -0
- package/build/pg.d.ts +8 -219
- package/build/pg.js +7 -525
- package/build/poller.d.ts +9 -0
- package/build/poller.js +152 -0
- package/build/poller.js.map +1 -0
- package/build/process.d.ts +114 -0
- package/build/process.js +170 -0
- package/build/process.js.map +1 -0
- package/build/profiles.d.ts +68 -0
- package/build/profiles.js +120 -0
- package/build/profiles.js.map +1 -0
- package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
- package/build/queue.js +279 -0
- package/build/queue.js.map +1 -0
- package/build/rabbitmq/client.d.ts +144 -0
- package/build/rabbitmq/client.js +426 -0
- package/build/rabbitmq/client.js.map +1 -0
- package/build/rabbitmq/connection.d.ts +91 -0
- package/build/rabbitmq/connection.js +15 -0
- package/build/rabbitmq/connection.js.map +1 -0
- package/build/rabbitmq/machine.d.ts +13 -0
- package/build/rabbitmq/machine.js +159 -0
- package/build/rabbitmq/machine.js.map +1 -0
- package/build/rabbitmq/meets.d.ts +12 -0
- package/build/rabbitmq/meets.js +96 -0
- package/build/rabbitmq/meets.js.map +1 -0
- package/build/rabbitmq/starting.d.ts +27 -0
- package/build/rabbitmq/starting.js +67 -0
- package/build/rabbitmq/starting.js.map +1 -0
- package/build/rabbitmq.d.ts +8 -283
- package/build/rabbitmq.js +7 -742
- package/build/redis/client.d.ts +86 -0
- package/build/redis/client.js +285 -0
- package/build/redis/client.js.map +1 -0
- package/build/redis/connection.d.ts +57 -0
- package/build/redis/connection.js +11 -0
- package/build/redis/connection.js.map +1 -0
- package/build/redis/limiter.d.ts +43 -0
- package/build/redis/limiter.js +164 -0
- package/build/redis/limiter.js.map +1 -0
- package/build/redis/machine.d.ts +12 -0
- package/build/redis/machine.js +144 -0
- package/build/redis/machine.js.map +1 -0
- package/build/redis/meets.d.ts +11 -0
- package/build/redis/meets.js +75 -0
- package/build/redis/meets.js.map +1 -0
- package/build/redis/operations.d.ts +5 -0
- package/build/redis/operations.js +114 -0
- package/build/redis/operations.js.map +1 -0
- package/build/redis.d.ts +10 -207
- package/build/redis.js +9 -771
- package/build/requests.d.ts +66 -0
- package/build/requests.js +279 -0
- package/build/requests.js.map +1 -0
- package/build/retrier.d.ts +62 -0
- package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
- package/build/retrier.js.map +1 -0
- package/build/routes.d.ts +35 -0
- package/build/routes.js +77 -0
- package/build/routes.js.map +1 -0
- package/build/rules.d.ts +19 -2
- package/build/stops.d.ts +51 -0
- package/build/stops.js +86 -0
- package/build/stops.js.map +1 -0
- package/build/testing.d.ts +8 -270
- package/build/testing.js +4 -1027
- package/build/testing.js.map +1 -1
- package/build/timing.d.ts +63 -0
- package/build/{timing-DZl36uXs.js → timing.js} +2 -2
- package/build/timing.js.map +1 -0
- package/build/units.d.ts +17 -0
- package/build/units.js +236 -0
- package/build/units.js.map +1 -0
- package/build/watchdog.d.ts +34 -0
- package/build/watchdog.js +53 -0
- package/build/watchdog.js.map +1 -0
- package/build/websocket/client.d.ts +136 -0
- package/build/websocket/client.js +422 -0
- package/build/websocket/client.js.map +1 -0
- package/build/websocket/connection.d.ts +83 -0
- package/build/websocket/connection.js +57 -0
- package/build/websocket/connection.js.map +1 -0
- package/build/websocket/machine.d.ts +12 -0
- package/build/websocket/machine.js +155 -0
- package/build/websocket/machine.js.map +1 -0
- package/build/websocket/meets.d.ts +14 -0
- package/build/websocket/meets.js +92 -0
- package/build/websocket/meets.js.map +1 -0
- package/build/websocket/starting.d.ts +25 -0
- package/build/websocket/starting.js +69 -0
- package/build/websocket/starting.js.map +1 -0
- package/build/websocket.d.ts +9 -264
- package/build/websocket.js +8 -774
- package/build/worker.d.ts +92 -0
- package/build/worker.js +153 -0
- package/build/worker.js.map +1 -0
- package/package.json +4 -3
- package/build/backoff-QTRGfkEK.d.ts +0 -45
- package/build/clock-DpVgpY4h.d.ts +0 -2
- package/build/grpc.js.map +0 -1
- package/build/host.js.map +0 -1
- package/build/http-client.js.map +0 -1
- package/build/http.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/knobs-BJcz6m01.js.map +0 -1
- package/build/lifecycle-D0J-zwZF.d.ts +0 -374
- package/build/limiter-DrM0PQV9.js.map +0 -1
- package/build/logger-B6drv9w0.d.ts +0 -488
- package/build/machine-BhVeHr_m.js.map +0 -1
- package/build/mongodb.js.map +0 -1
- package/build/operation-DF73RZOI.js.map +0 -1
- package/build/pg.js.map +0 -1
- package/build/policy-UYALkqVq.js.map +0 -1
- package/build/process-7R9M29wN.js +0 -437
- package/build/process-7R9M29wN.js.map +0 -1
- package/build/rabbitmq.js.map +0 -1
- package/build/redis.js.map +0 -1
- package/build/requests-DD2ALv0_.js +0 -583
- package/build/requests-DD2ALv0_.js.map +0 -1
- package/build/retrier-Dnjhvxol.js.map +0 -1
- package/build/timing-DZl36uXs.js.map +0 -1
- package/build/websocket.js.map +0 -1
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { backoffProblems } from "../backoff.js";
|
|
2
|
+
import { isMessageShape } from "../process.js";
|
|
3
|
+
import { retrier } from "../retrier.js";
|
|
4
|
+
import { removeDiscovery, writeDiscovery } from "./discovery.js";
|
|
5
|
+
import { parseEnvFile } from "./env.js";
|
|
6
|
+
import { acquireInstanceLock } from "./lock.js";
|
|
7
|
+
import { rotatingLog } from "./logs.js";
|
|
8
|
+
import { joinPath } from "./ports.js";
|
|
9
|
+
import { probeOnce, probeProblems } from "./probes.js";
|
|
10
|
+
import { stopTree } from "./processes.js";
|
|
11
|
+
import { isTime } from "./render.js";
|
|
12
|
+
import { convertible, isQuantity, valueIn } from "@mark1russell7/quantity";
|
|
13
|
+
// src/host/group.ts
|
|
14
|
+
/**
|
|
15
|
+
* This restart is the default. The first wait is 1 s, and each wait after it is two times longer, to 1 min.
|
|
16
|
+
* The jitter subtracts up to half of each wait. The count of tries goes back to 0 after 1 min ready.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_RESTART = {
|
|
19
|
+
backoff: {
|
|
20
|
+
base: 1e3,
|
|
21
|
+
factor: 2,
|
|
22
|
+
cap: 6e4,
|
|
23
|
+
jitter: {
|
|
24
|
+
kind: "subtract",
|
|
25
|
+
fraction: .5
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
resetAfter: {
|
|
29
|
+
value: 60,
|
|
30
|
+
unit: "s"
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const DEFAULT_GRACE = {
|
|
34
|
+
value: 10,
|
|
35
|
+
unit: "s"
|
|
36
|
+
};
|
|
37
|
+
const DEFAULT_LOG_SIZE = {
|
|
38
|
+
value: 10,
|
|
39
|
+
unit: "MB"
|
|
40
|
+
};
|
|
41
|
+
const DEFAULT_LOG_KEEP = 3;
|
|
42
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
43
|
+
const ms = (time) => valueIn(time, "ms");
|
|
44
|
+
/**
|
|
45
|
+
* This function gives the start sequence of a group, as layers of names. Each program of a layer needs only programs of the
|
|
46
|
+
* layers before it. A program in a cycle, or after an unknown program, is in no layer. `groupProblems` names it.
|
|
47
|
+
*/
|
|
48
|
+
const startOrder = (spec) => {
|
|
49
|
+
const names = new Set(spec.programs.map((program) => program.name));
|
|
50
|
+
const placed = /* @__PURE__ */ new Set();
|
|
51
|
+
const layers = [];
|
|
52
|
+
for (;;) {
|
|
53
|
+
const layer = spec.programs.filter((program) => !placed.has(program.name)).filter((program) => (program.after ?? []).every((name) => names.has(name) && placed.has(name))).map((program) => program.name);
|
|
54
|
+
if (layer.length === 0) return layers;
|
|
55
|
+
for (const name of layer) placed.add(name);
|
|
56
|
+
layers.push([...new Set(layer)]);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const isTimeAtLeast = (value, floor, strict) => isTime(value) && (strict ? ms(value) > floor : ms(value) >= floor);
|
|
60
|
+
/** This function gives the problems of a group spec: each value that the supervisor cannot use. */
|
|
61
|
+
const groupProblems = (spec) => {
|
|
62
|
+
const problems = [];
|
|
63
|
+
if (!NAME.test(spec.name)) problems.push(`the group name ${JSON.stringify(spec.name)} is not letters, digits, ".", "_" and "-"`);
|
|
64
|
+
if (spec.stateDir === "") problems.push("the stateDir is empty");
|
|
65
|
+
if (spec.programs.length === 0) problems.push("the group has no programs");
|
|
66
|
+
const seen = /* @__PURE__ */ new Set();
|
|
67
|
+
const names = new Set(spec.programs.map((program) => program.name));
|
|
68
|
+
for (const program of spec.programs) {
|
|
69
|
+
const name = program.name;
|
|
70
|
+
const of = `the program ${JSON.stringify(name)}`;
|
|
71
|
+
if (!NAME.test(name)) problems.push(`${of}: the name is not letters, digits, ".", "_" and "-"`);
|
|
72
|
+
if (seen.has(name)) problems.push(`${of} comes two times`);
|
|
73
|
+
seen.add(name);
|
|
74
|
+
if (program.program === "") problems.push(`${of}: the program is empty`);
|
|
75
|
+
for (const need of program.after ?? []) if (need === name) problems.push(`${of} is after itself`);
|
|
76
|
+
else if (!names.has(need)) problems.push(`${of} is after ${JSON.stringify(need)}, which is not in the group`);
|
|
77
|
+
if (program.ready !== void 0) {
|
|
78
|
+
problems.push(...probeProblems(program.ready.probe).map((problem) => `${of}: ${problem}`));
|
|
79
|
+
for (const field of [
|
|
80
|
+
"interval",
|
|
81
|
+
"timeout",
|
|
82
|
+
"within"
|
|
83
|
+
]) if (!isTimeAtLeast(program.ready[field], 0, true)) problems.push(`${of}: the ${field} of the probe is not a time above zero`);
|
|
84
|
+
}
|
|
85
|
+
if (program.alive !== void 0) {
|
|
86
|
+
problems.push(...probeProblems(program.alive.probe).map((problem) => `${of}: the liveness probe: ${problem}`));
|
|
87
|
+
for (const field of ["interval", "timeout"]) if (!isTimeAtLeast(program.alive[field], 0, true)) problems.push(`${of}: the ${field} of the liveness probe is not a time above zero`);
|
|
88
|
+
if (!(Number.isInteger(program.alive.failures) && program.alive.failures >= 1)) problems.push(`${of}: the failures of the liveness probe is not a whole number of 1 or more`);
|
|
89
|
+
}
|
|
90
|
+
if (program.restart !== void 0 && program.restart !== null) {
|
|
91
|
+
problems.push(...backoffProblems(program.restart.backoff).map((problem) => `${of}: ${problem}`));
|
|
92
|
+
if (!isTimeAtLeast(program.restart.resetAfter, 0, false)) problems.push(`${of}: the resetAfter is not a time of zero or more`);
|
|
93
|
+
}
|
|
94
|
+
if (program.log !== void 0 && program.log !== null) {
|
|
95
|
+
const size = program.log.maxSize;
|
|
96
|
+
if (!(isQuantity(size) && convertible(size.unit, "B") && valueIn(size, "B") > 0)) problems.push(`${of}: the maxSize of the log is not a size above zero`);
|
|
97
|
+
if (!(Number.isInteger(program.log.keep) && program.log.keep >= 0)) problems.push(`${of}: the keep of the log is not a whole number of zero or more`);
|
|
98
|
+
if (program.log.path === "") problems.push(`${of}: the path of the log is empty`);
|
|
99
|
+
}
|
|
100
|
+
if (program.stop !== void 0) {
|
|
101
|
+
if (!isTimeAtLeast(program.stop.grace, 0, false)) problems.push(`${of}: the grace of the stop is not a time of zero or more`);
|
|
102
|
+
if (program.stop.message !== void 0 && !isMessageShape(program.stop.message)) problems.push(`${of}: the stop message is not a value of JSON`);
|
|
103
|
+
const signal = program.stop.signal;
|
|
104
|
+
if (signal !== void 0 && signal !== "SIGINT" && signal !== "SIGTERM") problems.push(`${of}: the stop signal ${JSON.stringify(signal)} is not SIGINT or SIGTERM`);
|
|
105
|
+
}
|
|
106
|
+
const port = program.listen?.port;
|
|
107
|
+
if (port !== void 0 && port !== null && !(Number.isInteger(port) && port >= 1 && port <= 65535)) problems.push(`${of}: the port ${port} is not a port from 1 to 65535`);
|
|
108
|
+
}
|
|
109
|
+
const placed = new Set(startOrder(spec).flat());
|
|
110
|
+
const left = spec.programs.filter((program) => !placed.has(program.name) && (program.after ?? []).every((need) => names.has(need) && need !== program.name));
|
|
111
|
+
if (left.length > 0) problems.push(`the programs ${left.map((program) => JSON.stringify(program.name)).join(", ")} are in a cycle of "after", or after a program in one`);
|
|
112
|
+
return problems;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* This function makes the supervisor of a group. It refuses a spec with problems. Each effect goes
|
|
116
|
+
* through the ports, thus a test gives `fakeHost()` and starts no process.
|
|
117
|
+
* - A program starts when each program of its `after` is ready. It takes its lock first, thus a second instance does not start.
|
|
118
|
+
* - A program with a probe is ready when its probe passes. A program that is not ready in `within` stops, and starts again.
|
|
119
|
+
* - A program that stops starts again after the backoff of its `retrier`, when its programs are ready.
|
|
120
|
+
* - Its output goes to its rotating log. Its environment is the host, then its env file, then its `env`.
|
|
121
|
+
* - The stop goes in the reverse sequence: the staged stop first, and after the grace, the stop of the process tree by its ID.
|
|
122
|
+
*/
|
|
123
|
+
const superviseGroup = (spec, ports, options = {}) => {
|
|
124
|
+
const problems = groupProblems(spec);
|
|
125
|
+
if (problems.length > 0) throw new Error(`the group ${spec.name} has problems: ${problems.join("; ")}`);
|
|
126
|
+
const abort = new AbortController();
|
|
127
|
+
const layers = startOrder(spec);
|
|
128
|
+
let started = false;
|
|
129
|
+
let stopping = false;
|
|
130
|
+
let stopped = null;
|
|
131
|
+
const say = (level, message, fields) => {
|
|
132
|
+
try {
|
|
133
|
+
ports.logger?.log(level, message, {
|
|
134
|
+
group: spec.name,
|
|
135
|
+
...fields
|
|
136
|
+
});
|
|
137
|
+
} catch {}
|
|
138
|
+
};
|
|
139
|
+
const units = /* @__PURE__ */ new Map();
|
|
140
|
+
for (const program of spec.programs) {
|
|
141
|
+
const restart = program.restart === void 0 ? DEFAULT_RESTART : program.restart;
|
|
142
|
+
const logSpec = program.log === void 0 ? {
|
|
143
|
+
path: joinPath(ports.platform, spec.stateDir, "logs", `${program.name}.log`),
|
|
144
|
+
maxSize: DEFAULT_LOG_SIZE,
|
|
145
|
+
keep: DEFAULT_LOG_KEEP
|
|
146
|
+
} : program.log;
|
|
147
|
+
units.set(program.name, {
|
|
148
|
+
spec: program,
|
|
149
|
+
lockPath: joinPath(ports.platform, spec.stateDir, `${program.name}.lock`),
|
|
150
|
+
discoveryPath: joinPath(ports.platform, spec.stateDir, `${program.name}.json`),
|
|
151
|
+
log: logSpec === null ? null : rotatingLog(logSpec, ports.files),
|
|
152
|
+
retry: restart === null ? null : retrier({
|
|
153
|
+
...restart.backoff,
|
|
154
|
+
clock: ports.clock,
|
|
155
|
+
signal: abort.signal,
|
|
156
|
+
...options.random === void 0 ? {} : { random: options.random }
|
|
157
|
+
}),
|
|
158
|
+
phase: "waiting",
|
|
159
|
+
child: null,
|
|
160
|
+
lock: null,
|
|
161
|
+
timers: [],
|
|
162
|
+
watch: null,
|
|
163
|
+
restarts: 0,
|
|
164
|
+
detail: null,
|
|
165
|
+
reason: null,
|
|
166
|
+
waiters: []
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const unitOf = (name) => units.get(name);
|
|
170
|
+
const clearTimers = (unit) => {
|
|
171
|
+
for (const cancel of unit.timers.splice(0)) cancel();
|
|
172
|
+
unit.watch?.();
|
|
173
|
+
unit.watch = null;
|
|
174
|
+
};
|
|
175
|
+
const environment = async (unit) => {
|
|
176
|
+
const env = {};
|
|
177
|
+
for (const [key, value] of Object.entries(ports.env)) if (value !== void 0) env[key] = value;
|
|
178
|
+
const file = unit.spec.envFile;
|
|
179
|
+
if (file !== void 0) try {
|
|
180
|
+
const text = await ports.files.read(file);
|
|
181
|
+
if (text === null) say("warn", `the env file ${file} of ${unit.spec.name} does not exist`, {
|
|
182
|
+
program: unit.spec.name,
|
|
183
|
+
file
|
|
184
|
+
});
|
|
185
|
+
else {
|
|
186
|
+
const parsed = parseEnvFile(text);
|
|
187
|
+
Object.assign(env, parsed.env);
|
|
188
|
+
for (const problem of parsed.problems) say("warn", `the env file ${file} of ${unit.spec.name}: ${problem}`, {
|
|
189
|
+
program: unit.spec.name,
|
|
190
|
+
file
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
say("warn", `the read of the env file ${file} of ${unit.spec.name} failed`, {
|
|
195
|
+
program: unit.spec.name,
|
|
196
|
+
file,
|
|
197
|
+
error
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return Object.assign(env, unit.spec.env ?? {});
|
|
201
|
+
};
|
|
202
|
+
const consider = (unit) => {
|
|
203
|
+
if (!started || stopping || unit.phase !== "waiting") return;
|
|
204
|
+
if (!(unit.spec.after ?? []).every((name) => unitOf(name).phase === "ready")) return;
|
|
205
|
+
launch(unit);
|
|
206
|
+
};
|
|
207
|
+
const considerAll = () => {
|
|
208
|
+
for (const layer of layers) for (const name of layer) consider(unitOf(name));
|
|
209
|
+
};
|
|
210
|
+
/** This function starts the program again after the backoff, or ends it when it has no restart. */
|
|
211
|
+
const later = (unit, phase) => {
|
|
212
|
+
const delay = unit.retry?.schedule(() => {
|
|
213
|
+
if (stopping) return;
|
|
214
|
+
unit.phase = "waiting";
|
|
215
|
+
unit.restarts += 1;
|
|
216
|
+
consider(unit);
|
|
217
|
+
});
|
|
218
|
+
if (delay === void 0 || delay === null) {
|
|
219
|
+
unit.phase = phase === "held" ? "held" : "exited";
|
|
220
|
+
unit.lock?.release();
|
|
221
|
+
unit.lock = null;
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
unit.phase = phase;
|
|
225
|
+
say("info", `${unit.spec.name} starts again in ${delay} ms`, {
|
|
226
|
+
program: unit.spec.name,
|
|
227
|
+
delay: {
|
|
228
|
+
value: delay,
|
|
229
|
+
unit: "ms"
|
|
230
|
+
},
|
|
231
|
+
attempt: unit.retry?.attempts
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
const markReady = (unit, child) => {
|
|
235
|
+
if (unit.child !== child || stopping) return;
|
|
236
|
+
unit.phase = "ready";
|
|
237
|
+
unit.detail = null;
|
|
238
|
+
say("info", `${unit.spec.name} is ready`, {
|
|
239
|
+
program: unit.spec.name,
|
|
240
|
+
pid: child.pid
|
|
241
|
+
});
|
|
242
|
+
const restart = unit.spec.restart === void 0 ? DEFAULT_RESTART : unit.spec.restart;
|
|
243
|
+
if (unit.retry !== null && restart !== null) unit.timers.push(ports.clock.after(ms(restart.resetAfter), () => {
|
|
244
|
+
if (unit.child === child && unit.phase === "ready") unit.retry?.reset();
|
|
245
|
+
}));
|
|
246
|
+
if (unit.spec.alive !== void 0) watch(unit, child, unit.spec.alive);
|
|
247
|
+
considerAll();
|
|
248
|
+
};
|
|
249
|
+
/** This function uses the liveness probe of a ready program each interval, and stops the program after `failures` failures in sequence. */
|
|
250
|
+
const watch = (unit, child, alive) => {
|
|
251
|
+
let failures = 0;
|
|
252
|
+
const current = () => unit.child === child && unit.phase === "ready" && !stopping;
|
|
253
|
+
const next = () => {
|
|
254
|
+
unit.watch = ports.clock.after(ms(alive.interval), () => {
|
|
255
|
+
unit.watch = null;
|
|
256
|
+
check();
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
const check = async () => {
|
|
260
|
+
if (!current()) return;
|
|
261
|
+
const result = await probeOnce(alive.probe, ms(alive.timeout), ports);
|
|
262
|
+
if (!current()) return;
|
|
263
|
+
if (result.ok) {
|
|
264
|
+
if (failures > 0) say("info", `${unit.spec.name} is alive again`, {
|
|
265
|
+
program: unit.spec.name,
|
|
266
|
+
pid: child.pid,
|
|
267
|
+
failures
|
|
268
|
+
});
|
|
269
|
+
failures = 0;
|
|
270
|
+
unit.detail = null;
|
|
271
|
+
next();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
failures += 1;
|
|
275
|
+
unit.detail = `the liveness probe failed ${failures} of ${alive.failures} times in sequence (${result.why})`;
|
|
276
|
+
if (failures < alive.failures) {
|
|
277
|
+
say("warn", `${unit.spec.name}: ${unit.detail}`, {
|
|
278
|
+
program: unit.spec.name,
|
|
279
|
+
pid: child.pid,
|
|
280
|
+
why: result.why
|
|
281
|
+
});
|
|
282
|
+
next();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
unit.reason = `its liveness probe failed ${failures} times in sequence (${result.why})`;
|
|
286
|
+
unit.detail = unit.reason;
|
|
287
|
+
say("warn", `${unit.spec.name} is not alive, thus it stops`, {
|
|
288
|
+
program: unit.spec.name,
|
|
289
|
+
pid: child.pid,
|
|
290
|
+
why: result.why
|
|
291
|
+
});
|
|
292
|
+
stagedStop(unit, child);
|
|
293
|
+
};
|
|
294
|
+
next();
|
|
295
|
+
};
|
|
296
|
+
const probe = (unit, child, ready) => {
|
|
297
|
+
const deadline = ports.clock.now() + ms(ready.within);
|
|
298
|
+
const attempt = async () => {
|
|
299
|
+
if (unit.child !== child || stopping) return;
|
|
300
|
+
const result = await probeOnce(ready.probe, ms(ready.timeout), ports);
|
|
301
|
+
if (unit.child !== child || stopping) return;
|
|
302
|
+
if (result.ok) {
|
|
303
|
+
markReady(unit, child);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
unit.detail = result.why;
|
|
307
|
+
if (ports.clock.now() >= deadline) {
|
|
308
|
+
unit.reason = `it was not ready in ${ms(ready.within)} ms (${result.why})`;
|
|
309
|
+
unit.detail = unit.reason;
|
|
310
|
+
say("warn", `${unit.spec.name} is not ready in its time, thus it stops`, {
|
|
311
|
+
program: unit.spec.name,
|
|
312
|
+
pid: child.pid,
|
|
313
|
+
why: result.why
|
|
314
|
+
});
|
|
315
|
+
stagedStop(unit, child);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
unit.timers.push(ports.clock.after(ms(ready.interval), () => void attempt()));
|
|
319
|
+
};
|
|
320
|
+
attempt();
|
|
321
|
+
};
|
|
322
|
+
const exited = (unit, child, code, signal) => {
|
|
323
|
+
if (unit.child !== child) return;
|
|
324
|
+
clearTimers(unit);
|
|
325
|
+
unit.child = null;
|
|
326
|
+
for (const waiter of unit.waiters.splice(0)) waiter();
|
|
327
|
+
if (child.pid !== null) removeDiscovery(unit.discoveryPath, ports, child.pid);
|
|
328
|
+
unit.lock?.update(null).catch(() => {});
|
|
329
|
+
if (stopping || unit.phase === "stopping") {
|
|
330
|
+
unit.phase = "stopped";
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const end = child.pid === null ? `${unit.spec.program} did not start` : `it exited with ${code === null ? `the signal ${signal ?? "unknown"}` : `the code ${code}`}`;
|
|
334
|
+
unit.detail = unit.reason === null ? end : `${unit.reason}, then ${end}`;
|
|
335
|
+
unit.reason = null;
|
|
336
|
+
say("warn", `${unit.spec.name} stopped: ${unit.detail}`, {
|
|
337
|
+
program: unit.spec.name,
|
|
338
|
+
pid: child.pid,
|
|
339
|
+
code,
|
|
340
|
+
signal
|
|
341
|
+
});
|
|
342
|
+
later(unit, "backoff");
|
|
343
|
+
};
|
|
344
|
+
const launch = async (unit) => {
|
|
345
|
+
unit.phase = "starting";
|
|
346
|
+
unit.detail = null;
|
|
347
|
+
const name = unit.spec.name;
|
|
348
|
+
if (unit.lock === null) {
|
|
349
|
+
const taken = await acquireInstanceLock(unit.lockPath, ports);
|
|
350
|
+
if (stopping) {
|
|
351
|
+
if (taken.kind === "acquired") await taken.lock.release();
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (taken.kind !== "acquired") {
|
|
355
|
+
unit.detail = taken.kind === "held" ? `the process ${taken.owner.child?.pid ?? taken.owner.pid} holds the lock ${unit.lockPath}` : taken.problem;
|
|
356
|
+
say("warn", `${name} does not start: ${unit.detail}`, {
|
|
357
|
+
program: name,
|
|
358
|
+
lock: unit.lockPath
|
|
359
|
+
});
|
|
360
|
+
later(unit, "held");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
unit.lock = taken.lock;
|
|
364
|
+
}
|
|
365
|
+
const lock = unit.lock;
|
|
366
|
+
const env = await environment(unit);
|
|
367
|
+
if (stopping) {
|
|
368
|
+
await lock.release();
|
|
369
|
+
unit.lock = null;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const child = ports.processes.spawn({
|
|
373
|
+
program: unit.spec.program,
|
|
374
|
+
args: unit.spec.args ?? [],
|
|
375
|
+
cwd: unit.spec.cwd,
|
|
376
|
+
env,
|
|
377
|
+
ipc: unit.spec.ipc ?? false
|
|
378
|
+
});
|
|
379
|
+
const startedAt = ports.wall();
|
|
380
|
+
unit.child = child;
|
|
381
|
+
child.onOutput((_stream, chunk) => unit.log?.write(chunk));
|
|
382
|
+
child.onExit((code, signal) => exited(unit, child, code, signal));
|
|
383
|
+
const pid = child.pid;
|
|
384
|
+
if (pid === null) return;
|
|
385
|
+
say("info", `${name} started`, {
|
|
386
|
+
program: name,
|
|
387
|
+
pid
|
|
388
|
+
});
|
|
389
|
+
const mark = {
|
|
390
|
+
pid,
|
|
391
|
+
startedAt
|
|
392
|
+
};
|
|
393
|
+
try {
|
|
394
|
+
await lock.update(mark);
|
|
395
|
+
await writeDiscovery(unit.discoveryPath, {
|
|
396
|
+
pid,
|
|
397
|
+
startedAt: new Date(startedAt).toISOString(),
|
|
398
|
+
port: unit.spec.listen?.port ?? null,
|
|
399
|
+
url: unit.spec.listen?.url ?? null,
|
|
400
|
+
extra: {
|
|
401
|
+
group: spec.name,
|
|
402
|
+
program: name
|
|
403
|
+
}
|
|
404
|
+
}, ports);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
say("warn", `the files of ${name} were not written`, {
|
|
407
|
+
program: name,
|
|
408
|
+
error
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (unit.child !== child) await removeDiscovery(unit.discoveryPath, ports, pid);
|
|
412
|
+
if (unit.child !== child || stopping) return;
|
|
413
|
+
if (unit.spec.ready === void 0) markReady(unit, child);
|
|
414
|
+
else probe(unit, child, unit.spec.ready);
|
|
415
|
+
};
|
|
416
|
+
/** This function waits for the end of a child, for at most `wait` milliseconds. It tells if the child ended. */
|
|
417
|
+
const ended = (unit, child, wait) => new Promise((resolve) => {
|
|
418
|
+
if (unit.child !== child) {
|
|
419
|
+
resolve(true);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const cancel = ports.clock.after(wait, () => resolve(unit.child !== child));
|
|
423
|
+
unit.waiters.push(() => {
|
|
424
|
+
cancel();
|
|
425
|
+
resolve(true);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
/**
|
|
429
|
+
* This function stops a child in stages. The message goes on its IPC channel when it has one. Else
|
|
430
|
+
* Linux gets SIGTERM, and Windows gets `taskkill /T` without `/F`. After the grace, the process tree stops by its ID.
|
|
431
|
+
*/
|
|
432
|
+
const stagedStop = async (unit, child) => {
|
|
433
|
+
const pid = child.pid;
|
|
434
|
+
if (pid === null || unit.child !== child) return;
|
|
435
|
+
const grace = ms(unit.spec.stop?.grace ?? DEFAULT_GRACE);
|
|
436
|
+
const gone = ended(unit, child, grace);
|
|
437
|
+
let asked = null;
|
|
438
|
+
if (child.ipc && child.send(unit.spec.stop?.message ?? "shutdown")) asked = "the IPC message";
|
|
439
|
+
else if (ports.platform === "win32") {
|
|
440
|
+
if ((await ports.commands.run("taskkill", [
|
|
441
|
+
"/T",
|
|
442
|
+
"/PID",
|
|
443
|
+
String(pid)
|
|
444
|
+
]).catch(() => null))?.code === 0) asked = "taskkill";
|
|
445
|
+
} else {
|
|
446
|
+
const signal = unit.spec.stop?.signal ?? "SIGTERM";
|
|
447
|
+
if (ports.processes.signal(pid, signal)) asked = signal;
|
|
448
|
+
}
|
|
449
|
+
say("info", `${unit.spec.name} stops${asked === null ? "" : ` through ${asked}`}`, {
|
|
450
|
+
program: unit.spec.name,
|
|
451
|
+
pid,
|
|
452
|
+
grace: {
|
|
453
|
+
value: grace,
|
|
454
|
+
unit: "ms"
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
if (asked !== null && await gone) return;
|
|
458
|
+
const tree = await stopTree(pid, ports);
|
|
459
|
+
const why = asked === null ? "the staged stop did not go" : "it did not stop in its grace";
|
|
460
|
+
say(tree.kind === "failed" ? "error" : "warn", `${unit.spec.name}: ${why}, thus its process tree stops: ${tree.kind}`, {
|
|
461
|
+
program: unit.spec.name,
|
|
462
|
+
pid,
|
|
463
|
+
outcome: tree.kind
|
|
464
|
+
});
|
|
465
|
+
if (!await ended(unit, child, grace)) say("error", `${unit.spec.name} did not end after the stop of its process tree`, {
|
|
466
|
+
program: unit.spec.name,
|
|
467
|
+
pid
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
const stopUnit = async (unit) => {
|
|
471
|
+
clearTimers(unit);
|
|
472
|
+
const child = unit.child;
|
|
473
|
+
const pid = child?.pid ?? null;
|
|
474
|
+
if (child !== null && pid !== null) {
|
|
475
|
+
unit.phase = "stopping";
|
|
476
|
+
await stagedStop(unit, child);
|
|
477
|
+
await removeDiscovery(unit.discoveryPath, ports, pid);
|
|
478
|
+
}
|
|
479
|
+
unit.phase = "stopped";
|
|
480
|
+
await unit.lock?.release();
|
|
481
|
+
unit.lock = null;
|
|
482
|
+
};
|
|
483
|
+
return {
|
|
484
|
+
start() {
|
|
485
|
+
if (started || stopping) return;
|
|
486
|
+
started = true;
|
|
487
|
+
say("info", `the group ${spec.name} starts`, { layers });
|
|
488
|
+
considerAll();
|
|
489
|
+
},
|
|
490
|
+
stop() {
|
|
491
|
+
if (stopped !== null) return stopped;
|
|
492
|
+
stopping = true;
|
|
493
|
+
abort.abort();
|
|
494
|
+
stopped = (async () => {
|
|
495
|
+
for (const layer of [...layers].reverse()) await Promise.all(layer.map((name) => stopUnit(unitOf(name))));
|
|
496
|
+
await Promise.all([...units.values()].map((unit) => unit.log?.flush()));
|
|
497
|
+
say("info", `the group ${spec.name} stopped`, {});
|
|
498
|
+
})();
|
|
499
|
+
return stopped;
|
|
500
|
+
},
|
|
501
|
+
states() {
|
|
502
|
+
return spec.programs.map((program) => {
|
|
503
|
+
const unit = unitOf(program.name);
|
|
504
|
+
return {
|
|
505
|
+
name: program.name,
|
|
506
|
+
phase: unit.phase,
|
|
507
|
+
pid: unit.child?.pid ?? null,
|
|
508
|
+
restarts: unit.restarts,
|
|
509
|
+
detail: unit.detail
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
export { DEFAULT_RESTART, groupProblems, startOrder, superviseGroup };
|
|
516
|
+
|
|
517
|
+
//# sourceMappingURL=group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.js","names":[],"sources":["../../src/host/group.ts"],"sourcesContent":["import type { Quantity } from \"@mark1russell7/quantity\";\nimport { convertible, isQuantity, valueIn } from \"@mark1russell7/quantity\";\nimport type { Backoff } from \"../backoff.ts\";\nimport { backoffProblems } from \"../backoff.ts\";\nimport type { Cancel } from \"../clock.ts\";\nimport type { LogFields, LogLevel } from \"../logger.ts\";\nimport type { MessageShape } from \"../process.ts\";\nimport { isMessageShape } from \"../process.ts\";\nimport type { Retrier } from \"../retrier.ts\";\nimport { retrier } from \"../retrier.ts\";\nimport { removeDiscovery, writeDiscovery } from \"./discovery.ts\";\nimport { parseEnvFile } from \"./env.ts\";\nimport type { InstanceLock } from \"./lock.ts\";\nimport { acquireInstanceLock } from \"./lock.ts\";\nimport type { LogSpec, RotatingLog } from \"./logs.ts\";\nimport { rotatingLog } from \"./logs.ts\";\nimport type { ChildHandle, HostPorts } from \"./ports.ts\";\nimport { joinPath } from \"./ports.ts\";\nimport type { ReadyProbe } from \"./probes.ts\";\nimport { probeOnce, probeProblems } from \"./probes.ts\";\nimport { stopTree } from \"./processes.ts\";\nimport { isTime } from \"./render.ts\";\n\n/** A ready spec tells how the supervisor finds that a program is ready. */\nexport interface ReadySpec {\n readonly probe: ReadyProbe;\n /** This time is the pause between two uses of the probe. */\n readonly interval: Quantity;\n /** This time is the most that one use of the probe can take. */\n readonly timeout: Quantity;\n /** This time is the most that the program can take to be ready. After it, the supervisor stops the program and starts it again. */\n readonly within: Quantity;\n}\n\n/**\n * An alive spec tells how the supervisor finds that a ready program still works. A program can hang and not exit:\n * its process stays, and only a probe finds it. After `failures` failures in sequence, the supervisor stops the\n * program in stages and starts it again after its backoff.\n */\nexport interface AliveSpec {\n readonly probe: ReadyProbe;\n /** This time is the pause between two uses of the probe. The first use is one interval after the program is ready. */\n readonly interval: Quantity;\n /** This time is the most that one use of the probe can take. */\n readonly timeout: Quantity;\n /** This count of failures in sequence stops the program: a whole number of 1 or more. A pass sets the count to 0. */\n readonly failures: number;\n}\n\n/** A program restart tells how the supervisor starts a program again after it stops. */\nexport interface ProgramRestart {\n /** This backoff gives the wait before each start again, in milliseconds, as `retrier` uses it. */\n readonly backoff: Backoff;\n /** This time is how long a program is ready before its count of tries goes back to 0. */\n readonly resetAfter: Quantity;\n}\n\n/** A stop spec tells how the supervisor stops a program. */\nexport interface StopSpec {\n /** This time is the wait for the staged stop, before the supervisor stops the process tree. */\n readonly grace: Quantity;\n /** This message goes on the IPC channel of a child that has one. The default is `\"shutdown\"`, which `run()` can match. */\n readonly message?: MessageShape | undefined;\n /** This signal goes to a child without an IPC channel on Linux. The default is `SIGTERM`. */\n readonly signal?: \"SIGINT\" | \"SIGTERM\" | undefined;\n}\n\n/** A program spec tells one program of a group, and what it needs before it starts. */\nexport interface ProgramSpec {\n /** This name is the name of the program in the group: letters, digits, `.`, `_` and `-`. */\n readonly name: string;\n readonly program: string;\n readonly args?: readonly string[] | undefined;\n readonly cwd?: string | undefined;\n /** These variables go to the program. They replace the variables of the env file and of the host. */\n readonly env?: Readonly<Record<string, string>> | undefined;\n /** This file gives variables to the program at each start (`parseEnvFile`). They replace the variables of the host. */\n readonly envFile?: string | undefined;\n /** These are the programs that must be ready before this program starts. */\n readonly after?: readonly string[] | undefined;\n /** This spec tells when the program is ready. Without it, the program is ready when it starts. */\n readonly ready?: ReadySpec | undefined;\n /** This spec tells how the supervisor finds that the ready program still works. Without it, only an exit starts the program again. */\n readonly alive?: AliveSpec | undefined;\n /** This policy starts the program again after it stops. The default is `DEFAULT_RESTART`. Null does not start it again. */\n readonly restart?: ProgramRestart | null | undefined;\n /** This spec tells the log file. The default is `<stateDir>/logs/<name>.log`, 10 MB, with 3 old files. Null keeps no log. */\n readonly log?: LogSpec | null | undefined;\n /** True gives the child an IPC channel, for the staged stop of a Node program. The default is false. */\n readonly ipc?: boolean | undefined;\n /** This spec tells the stop. The default is a grace of 10 s. */\n readonly stop?: StopSpec | undefined;\n /** These fields go in the discovery file of the program, `<stateDir>/<name>.json`. */\n readonly listen?: { readonly port?: number | null | undefined; readonly url?: string | null | undefined } | undefined;\n}\n\n/** A group spec tells a group of programs that one supervisor starts in sequence and keeps alive. */\nexport interface GroupSpec {\n readonly name: string;\n /** This folder keeps the lock, the discovery file and the log of each program. */\n readonly stateDir: string;\n readonly programs: readonly ProgramSpec[];\n}\n\n/** These options go with a supervisor. */\nexport interface GroupOptions {\n /** This function gives a number in [0, 1) for the jitter of the backoff. The default is `Math.random`. */\n readonly random?: (() => number) | undefined;\n}\n\n/**\n * A program phase tells where a program of a group is.\n * - `waiting`: a program that it needs is not ready.\n * - `starting`: it runs, and its probe did not pass.\n * - `ready`: it runs, and its probe passed.\n * - `backoff`: it stopped, and it starts again after its backoff.\n * - `held`: another instance holds its lock. The supervisor tries again after the backoff.\n * - `exited`: it stopped, and it has no restart.\n * - `stopping`, `stopped`: the stop of the group.\n */\nexport type ProgramPhase = \"waiting\" | \"starting\" | \"ready\" | \"backoff\" | \"held\" | \"exited\" | \"stopping\" | \"stopped\";\n\n/** A program state is the state of one program of a group, for a status. */\nexport interface ProgramState {\n readonly name: string;\n readonly phase: ProgramPhase;\n /** This number is the process ID of the child, or null. */\n readonly pid: number | null;\n /** This count is the number of starts again since the start of the group. */\n readonly restarts: number;\n /** This text tells the last problem, for example why the probe failed, or it is null. */\n readonly detail: string | null;\n}\n\n/** A group supervisor starts the programs of a group in sequence, starts each again after it stops, and stops them in stages. */\nexport interface GroupSupervisor {\n /** This method starts each program whose programs are ready. A second use does nothing. */\n start(): void;\n /** This method stops each program in the reverse sequence of the start. A second use gives the same promise. */\n stop(): Promise<void>;\n /** This method gives the state of each program, in the sequence of the spec. */\n states(): readonly ProgramState[];\n}\n\n/**\n * This restart is the default. The first wait is 1 s, and each wait after it is two times longer, to 1 min.\n * The jitter subtracts up to half of each wait. The count of tries goes back to 0 after 1 min ready.\n */\nexport const DEFAULT_RESTART: ProgramRestart = {\n backoff: { base: 1000, factor: 2, cap: 60_000, jitter: { kind: \"subtract\", fraction: 0.5 } },\n resetAfter: { value: 60, unit: \"s\" },\n};\n\nconst DEFAULT_GRACE: Quantity = { value: 10, unit: \"s\" };\nconst DEFAULT_LOG_SIZE: Quantity = { value: 10, unit: \"MB\" };\nconst DEFAULT_LOG_KEEP = 3;\nconst NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\nconst ms = (time: Quantity): number => valueIn(time, \"ms\");\n\n/**\n * This function gives the start sequence of a group, as layers of names. Each program of a layer needs only programs of the\n * layers before it. A program in a cycle, or after an unknown program, is in no layer. `groupProblems` names it.\n */\nexport const startOrder = (spec: GroupSpec): string[][] => {\n const names = new Set(spec.programs.map((program) => program.name));\n const placed = new Set<string>();\n const layers: string[][] = [];\n for (;;) {\n const layer = spec.programs\n .filter((program) => !placed.has(program.name))\n .filter((program) => (program.after ?? []).every((name) => names.has(name) && placed.has(name)))\n .map((program) => program.name);\n if (layer.length === 0) return layers;\n for (const name of layer) placed.add(name);\n layers.push([...new Set(layer)]);\n }\n};\n\nconst isTimeAtLeast = (value: unknown, floor: number, strict: boolean): boolean =>\n isTime(value) && (strict ? ms(value) > floor : ms(value) >= floor);\n\n/** This function gives the problems of a group spec: each value that the supervisor cannot use. */\nexport const groupProblems = (spec: GroupSpec): string[] => {\n const problems: string[] = [];\n if (!NAME.test(spec.name)) problems.push(`the group name ${JSON.stringify(spec.name)} is not letters, digits, \".\", \"_\" and \"-\"`);\n if (spec.stateDir === \"\") problems.push(\"the stateDir is empty\");\n if (spec.programs.length === 0) problems.push(\"the group has no programs\");\n const seen = new Set<string>();\n const names = new Set(spec.programs.map((program) => program.name));\n for (const program of spec.programs) {\n const name = program.name;\n const of = `the program ${JSON.stringify(name)}`;\n if (!NAME.test(name)) problems.push(`${of}: the name is not letters, digits, \".\", \"_\" and \"-\"`);\n if (seen.has(name)) problems.push(`${of} comes two times`);\n seen.add(name);\n if (program.program === \"\") problems.push(`${of}: the program is empty`);\n for (const need of program.after ?? []) {\n if (need === name) problems.push(`${of} is after itself`);\n else if (!names.has(need)) problems.push(`${of} is after ${JSON.stringify(need)}, which is not in the group`);\n }\n if (program.ready !== undefined) {\n problems.push(...probeProblems(program.ready.probe).map((problem) => `${of}: ${problem}`));\n for (const field of [\"interval\", \"timeout\", \"within\"] as const)\n if (!isTimeAtLeast(program.ready[field], 0, true)) problems.push(`${of}: the ${field} of the probe is not a time above zero`);\n }\n if (program.alive !== undefined) {\n problems.push(...probeProblems(program.alive.probe).map((problem) => `${of}: the liveness probe: ${problem}`));\n for (const field of [\"interval\", \"timeout\"] as const)\n if (!isTimeAtLeast(program.alive[field], 0, true)) problems.push(`${of}: the ${field} of the liveness probe is not a time above zero`);\n if (!(Number.isInteger(program.alive.failures) && program.alive.failures >= 1))\n problems.push(`${of}: the failures of the liveness probe is not a whole number of 1 or more`);\n }\n if (program.restart !== undefined && program.restart !== null) {\n problems.push(...backoffProblems(program.restart.backoff).map((problem) => `${of}: ${problem}`));\n if (!isTimeAtLeast(program.restart.resetAfter, 0, false)) problems.push(`${of}: the resetAfter is not a time of zero or more`);\n }\n if (program.log !== undefined && program.log !== null) {\n const size = program.log.maxSize;\n if (!(isQuantity(size) && convertible(size.unit, \"B\") && valueIn(size, \"B\") > 0)) problems.push(`${of}: the maxSize of the log is not a size above zero`);\n if (!(Number.isInteger(program.log.keep) && program.log.keep >= 0)) problems.push(`${of}: the keep of the log is not a whole number of zero or more`);\n if (program.log.path === \"\") problems.push(`${of}: the path of the log is empty`);\n }\n if (program.stop !== undefined) {\n if (!isTimeAtLeast(program.stop.grace, 0, false)) problems.push(`${of}: the grace of the stop is not a time of zero or more`);\n if (program.stop.message !== undefined && !isMessageShape(program.stop.message)) problems.push(`${of}: the stop message is not a value of JSON`);\n const signal = program.stop.signal;\n if (signal !== undefined && signal !== \"SIGINT\" && signal !== \"SIGTERM\") problems.push(`${of}: the stop signal ${JSON.stringify(signal)} is not SIGINT or SIGTERM`);\n }\n const port = program.listen?.port;\n if (port !== undefined && port !== null && !(Number.isInteger(port) && port >= 1 && port <= 65_535))\n problems.push(`${of}: the port ${port} is not a port from 1 to 65535`);\n }\n const placed = new Set(startOrder(spec).flat());\n const left = spec.programs.filter((program) => !placed.has(program.name) && (program.after ?? []).every((need) => names.has(need) && need !== program.name));\n if (left.length > 0) problems.push(`the programs ${left.map((program) => JSON.stringify(program.name)).join(\", \")} are in a cycle of \"after\", or after a program in one`);\n return problems;\n};\n\n/** The supervisor keeps one unit for each program: its spec, its files and its state. */\ninterface Unit {\n readonly spec: ProgramSpec;\n readonly lockPath: string;\n readonly discoveryPath: string;\n readonly log: RotatingLog | null;\n readonly retry: Retrier | null;\n phase: ProgramPhase;\n child: ChildHandle | null;\n lock: InstanceLock | null;\n timers: Cancel[];\n /** This cancel stops the next use of the liveness probe. It is one timer, thus a long life adds no timers. */\n watch: Cancel | null;\n restarts: number;\n detail: string | null;\n /** This text tells why the supervisor stopped the child, or it is null. */\n reason: string | null;\n waiters: Array<() => void>;\n}\n\n/**\n * This function makes the supervisor of a group. It refuses a spec with problems. Each effect goes\n * through the ports, thus a test gives `fakeHost()` and starts no process.\n * - A program starts when each program of its `after` is ready. It takes its lock first, thus a second instance does not start.\n * - A program with a probe is ready when its probe passes. A program that is not ready in `within` stops, and starts again.\n * - A program that stops starts again after the backoff of its `retrier`, when its programs are ready.\n * - Its output goes to its rotating log. Its environment is the host, then its env file, then its `env`.\n * - The stop goes in the reverse sequence: the staged stop first, and after the grace, the stop of the process tree by its ID.\n */\nexport const superviseGroup = (spec: GroupSpec, ports: HostPorts, options: GroupOptions = {}): GroupSupervisor => {\n const problems = groupProblems(spec);\n if (problems.length > 0) throw new Error(`the group ${spec.name} has problems: ${problems.join(\"; \")}`);\n const abort = new AbortController();\n const layers = startOrder(spec);\n let started = false;\n let stopping = false;\n let stopped: Promise<void> | null = null;\n\n const say = (level: LogLevel, message: string, fields: LogFields): void => {\n try {\n ports.logger?.log(level, message, { group: spec.name, ...fields });\n } catch {\n // the supervisor does not depend on its logger\n }\n };\n\n const units = new Map<string, Unit>();\n for (const program of spec.programs) {\n const restart = program.restart === undefined ? DEFAULT_RESTART : program.restart;\n const logSpec =\n program.log === undefined\n ? { path: joinPath(ports.platform, spec.stateDir, \"logs\", `${program.name}.log`), maxSize: DEFAULT_LOG_SIZE, keep: DEFAULT_LOG_KEEP }\n : program.log;\n units.set(program.name, {\n spec: program,\n lockPath: joinPath(ports.platform, spec.stateDir, `${program.name}.lock`),\n discoveryPath: joinPath(ports.platform, spec.stateDir, `${program.name}.json`),\n log: logSpec === null ? null : rotatingLog(logSpec, ports.files),\n retry:\n restart === null\n ? null\n : retrier({ ...restart.backoff, clock: ports.clock, signal: abort.signal, ...(options.random === undefined ? {} : { random: options.random }) }),\n phase: \"waiting\",\n child: null,\n lock: null,\n timers: [],\n watch: null,\n restarts: 0,\n detail: null,\n reason: null,\n waiters: [],\n });\n }\n const unitOf = (name: string): Unit => units.get(name)!;\n\n const clearTimers = (unit: Unit): void => {\n for (const cancel of unit.timers.splice(0)) cancel();\n unit.watch?.();\n unit.watch = null;\n };\n\n const environment = async (unit: Unit): Promise<Record<string, string>> => {\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(ports.env)) if (value !== undefined) env[key] = value;\n const file = unit.spec.envFile;\n if (file !== undefined) {\n try {\n const text = await ports.files.read(file);\n if (text === null) say(\"warn\", `the env file ${file} of ${unit.spec.name} does not exist`, { program: unit.spec.name, file });\n else {\n const parsed = parseEnvFile(text);\n Object.assign(env, parsed.env);\n for (const problem of parsed.problems) say(\"warn\", `the env file ${file} of ${unit.spec.name}: ${problem}`, { program: unit.spec.name, file });\n }\n } catch (error) {\n say(\"warn\", `the read of the env file ${file} of ${unit.spec.name} failed`, { program: unit.spec.name, file, error });\n }\n }\n return Object.assign(env, unit.spec.env ?? {});\n };\n\n const consider = (unit: Unit): void => {\n if (!started || stopping || unit.phase !== \"waiting\") return;\n if (!(unit.spec.after ?? []).every((name) => unitOf(name).phase === \"ready\")) return;\n void launch(unit);\n };\n const considerAll = (): void => {\n for (const layer of layers) for (const name of layer) consider(unitOf(name));\n };\n\n /** This function starts the program again after the backoff, or ends it when it has no restart. */\n const later = (unit: Unit, phase: \"backoff\" | \"held\"): void => {\n const delay = unit.retry?.schedule(() => {\n if (stopping) return;\n unit.phase = \"waiting\";\n unit.restarts += 1;\n consider(unit);\n });\n if (delay === undefined || delay === null) {\n unit.phase = phase === \"held\" ? \"held\" : \"exited\";\n void unit.lock?.release();\n unit.lock = null;\n return;\n }\n unit.phase = phase;\n say(\"info\", `${unit.spec.name} starts again in ${delay} ms`, { program: unit.spec.name, delay: { value: delay, unit: \"ms\" }, attempt: unit.retry?.attempts });\n };\n\n const markReady = (unit: Unit, child: ChildHandle): void => {\n if (unit.child !== child || stopping) return;\n unit.phase = \"ready\";\n unit.detail = null;\n say(\"info\", `${unit.spec.name} is ready`, { program: unit.spec.name, pid: child.pid });\n const restart = unit.spec.restart === undefined ? DEFAULT_RESTART : unit.spec.restart;\n if (unit.retry !== null && restart !== null)\n unit.timers.push(\n ports.clock.after(ms(restart.resetAfter), () => {\n if (unit.child === child && unit.phase === \"ready\") unit.retry?.reset();\n }),\n );\n if (unit.spec.alive !== undefined) watch(unit, child, unit.spec.alive);\n considerAll();\n };\n\n /** This function uses the liveness probe of a ready program each interval, and stops the program after `failures` failures in sequence. */\n const watch = (unit: Unit, child: ChildHandle, alive: AliveSpec): void => {\n let failures = 0;\n const current = (): boolean => unit.child === child && unit.phase === \"ready\" && !stopping;\n const next = (): void => {\n unit.watch = ports.clock.after(ms(alive.interval), () => {\n unit.watch = null;\n void check();\n });\n };\n const check = async (): Promise<void> => {\n if (!current()) return;\n const result = await probeOnce(alive.probe, ms(alive.timeout), ports);\n if (!current()) return;\n if (result.ok) {\n if (failures > 0) say(\"info\", `${unit.spec.name} is alive again`, { program: unit.spec.name, pid: child.pid, failures });\n failures = 0;\n unit.detail = null;\n next();\n return;\n }\n failures += 1;\n unit.detail = `the liveness probe failed ${failures} of ${alive.failures} times in sequence (${result.why})`;\n if (failures < alive.failures) {\n say(\"warn\", `${unit.spec.name}: ${unit.detail}`, { program: unit.spec.name, pid: child.pid, why: result.why });\n next();\n return;\n }\n unit.reason = `its liveness probe failed ${failures} times in sequence (${result.why})`;\n unit.detail = unit.reason;\n say(\"warn\", `${unit.spec.name} is not alive, thus it stops`, { program: unit.spec.name, pid: child.pid, why: result.why });\n void stagedStop(unit, child);\n };\n next();\n };\n\n const probe = (unit: Unit, child: ChildHandle, ready: ReadySpec): void => {\n const deadline = ports.clock.now() + ms(ready.within);\n const attempt = async (): Promise<void> => {\n if (unit.child !== child || stopping) return;\n const result = await probeOnce(ready.probe, ms(ready.timeout), ports);\n if (unit.child !== child || stopping) return;\n if (result.ok) {\n markReady(unit, child);\n return;\n }\n unit.detail = result.why;\n if (ports.clock.now() >= deadline) {\n unit.reason = `it was not ready in ${ms(ready.within)} ms (${result.why})`;\n unit.detail = unit.reason;\n say(\"warn\", `${unit.spec.name} is not ready in its time, thus it stops`, { program: unit.spec.name, pid: child.pid, why: result.why });\n void stagedStop(unit, child);\n return;\n }\n unit.timers.push(ports.clock.after(ms(ready.interval), () => void attempt()));\n };\n void attempt();\n };\n\n const exited = (unit: Unit, child: ChildHandle, code: number | null, signal: string | null): void => {\n if (unit.child !== child) return;\n clearTimers(unit);\n unit.child = null;\n for (const waiter of unit.waiters.splice(0)) waiter();\n if (child.pid !== null) void removeDiscovery(unit.discoveryPath, ports, child.pid);\n void unit.lock?.update(null).catch(() => {});\n if (stopping || unit.phase === \"stopping\") {\n unit.phase = \"stopped\";\n return;\n }\n const end = child.pid === null ? `${unit.spec.program} did not start` : `it exited with ${code === null ? `the signal ${signal ?? \"unknown\"}` : `the code ${code}`}`;\n unit.detail = unit.reason === null ? end : `${unit.reason}, then ${end}`;\n unit.reason = null;\n say(\"warn\", `${unit.spec.name} stopped: ${unit.detail}`, { program: unit.spec.name, pid: child.pid, code, signal });\n later(unit, \"backoff\");\n };\n\n const launch = async (unit: Unit): Promise<void> => {\n unit.phase = \"starting\";\n unit.detail = null;\n const name = unit.spec.name;\n if (unit.lock === null) {\n const taken = await acquireInstanceLock(unit.lockPath, ports);\n if (stopping) {\n if (taken.kind === \"acquired\") await taken.lock.release();\n return;\n }\n if (taken.kind !== \"acquired\") {\n unit.detail = taken.kind === \"held\" ? `the process ${taken.owner.child?.pid ?? taken.owner.pid} holds the lock ${unit.lockPath}` : taken.problem;\n say(\"warn\", `${name} does not start: ${unit.detail}`, { program: name, lock: unit.lockPath });\n later(unit, \"held\");\n return;\n }\n unit.lock = taken.lock;\n }\n const lock = unit.lock;\n const env = await environment(unit);\n if (stopping) {\n await lock.release();\n unit.lock = null;\n return;\n }\n const child = ports.processes.spawn({ program: unit.spec.program, args: unit.spec.args ?? [], cwd: unit.spec.cwd, env, ipc: unit.spec.ipc ?? false });\n const startedAt = ports.wall();\n unit.child = child;\n child.onOutput((_stream, chunk) => unit.log?.write(chunk));\n child.onExit((code, signal) => exited(unit, child, code, signal));\n const pid = child.pid;\n if (pid === null) return;\n say(\"info\", `${name} started`, { program: name, pid });\n const mark = { pid, startedAt };\n try {\n await lock.update(mark);\n await writeDiscovery(\n unit.discoveryPath,\n { pid, startedAt: new Date(startedAt).toISOString(), port: unit.spec.listen?.port ?? null, url: unit.spec.listen?.url ?? null, extra: { group: spec.name, program: name } },\n ports,\n );\n } catch (error) {\n say(\"warn\", `the files of ${name} were not written`, { program: name, error });\n }\n // a child that ended during the writes leaves no discovery file\n if (unit.child !== child) await removeDiscovery(unit.discoveryPath, ports, pid);\n if (unit.child !== child || stopping) return;\n if (unit.spec.ready === undefined) markReady(unit, child);\n else probe(unit, child, unit.spec.ready);\n };\n\n /** This function waits for the end of a child, for at most `wait` milliseconds. It tells if the child ended. */\n const ended = (unit: Unit, child: ChildHandle, wait: number): Promise<boolean> =>\n new Promise((resolve) => {\n if (unit.child !== child) {\n resolve(true);\n return;\n }\n const cancel = ports.clock.after(wait, () => resolve(unit.child !== child));\n unit.waiters.push(() => {\n cancel();\n resolve(true);\n });\n });\n\n /**\n * This function stops a child in stages. The message goes on its IPC channel when it has one. Else\n * Linux gets SIGTERM, and Windows gets `taskkill /T` without `/F`. After the grace, the process tree stops by its ID.\n */\n const stagedStop = async (unit: Unit, child: ChildHandle): Promise<void> => {\n const pid = child.pid;\n if (pid === null || unit.child !== child) return;\n const grace = ms(unit.spec.stop?.grace ?? DEFAULT_GRACE);\n const gone = ended(unit, child, grace);\n let asked: string | null = null;\n if (child.ipc && child.send(unit.spec.stop?.message ?? \"shutdown\")) asked = \"the IPC message\";\n else if (ports.platform === \"win32\") {\n const result = await ports.commands.run(\"taskkill\", [\"/T\", \"/PID\", String(pid)]).catch(() => null);\n if (result?.code === 0) asked = \"taskkill\";\n } else {\n const signal = unit.spec.stop?.signal ?? \"SIGTERM\";\n if (ports.processes.signal(pid, signal)) asked = signal;\n }\n say(\"info\", `${unit.spec.name} stops${asked === null ? \"\" : ` through ${asked}`}`, { program: unit.spec.name, pid, grace: { value: grace, unit: \"ms\" } });\n if (asked !== null && (await gone)) return;\n const tree = await stopTree(pid, ports);\n const why = asked === null ? \"the staged stop did not go\" : \"it did not stop in its grace\";\n say(tree.kind === \"failed\" ? \"error\" : \"warn\", `${unit.spec.name}: ${why}, thus its process tree stops: ${tree.kind}`, {\n program: unit.spec.name,\n pid,\n outcome: tree.kind,\n });\n if (!(await ended(unit, child, grace))) say(\"error\", `${unit.spec.name} did not end after the stop of its process tree`, { program: unit.spec.name, pid });\n };\n\n const stopUnit = async (unit: Unit): Promise<void> => {\n clearTimers(unit);\n const child = unit.child;\n const pid = child?.pid ?? null;\n if (child !== null && pid !== null) {\n unit.phase = \"stopping\";\n await stagedStop(unit, child);\n await removeDiscovery(unit.discoveryPath, ports, pid);\n }\n unit.phase = \"stopped\";\n await unit.lock?.release();\n unit.lock = null;\n };\n\n return {\n start() {\n if (started || stopping) return;\n started = true;\n say(\"info\", `the group ${spec.name} starts`, { layers });\n considerAll();\n },\n stop() {\n if (stopped !== null) return stopped;\n stopping = true;\n abort.abort();\n stopped = (async () => {\n for (const layer of [...layers].reverse()) await Promise.all(layer.map((name) => stopUnit(unitOf(name))));\n await Promise.all([...units.values()].map((unit) => unit.log?.flush()));\n say(\"info\", `the group ${spec.name} stopped`, {});\n })();\n return stopped;\n },\n states() {\n return spec.programs.map((program) => {\n const unit = unitOf(program.name);\n return { name: program.name, phase: unit.phase, pid: unit.child?.pid ?? null, restarts: unit.restarts, detail: unit.detail };\n });\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAoJA,MAAa,kBAAkC;CAC7C,SAAS;EAAE,MAAM;EAAM,QAAQ;EAAG,KAAK;EAAQ,QAAQ;GAAE,MAAM;GAAY,UAAU;EAAI;CAAE;CAC3F,YAAY;EAAE,OAAO;EAAI,MAAM;CAAI;AACrC;AAEA,MAAM,gBAA0B;CAAE,OAAO;CAAI,MAAM;AAAI;AACvD,MAAM,mBAA6B;CAAE,OAAO;CAAI,MAAM;AAAK;AAC3D,MAAM,mBAAmB;AACzB,MAAM,OAAO;AAEb,MAAM,MAAM,SAA2B,QAAQ,MAAM,IAAI;;;;;AAMzD,MAAa,cAAc,SAAgC;CACzD,MAAM,QAAQ,IAAI,IAAI,KAAK,SAAS,KAAK,YAAY,QAAQ,IAAI,CAAC;CAClE,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,SAAqB,CAAC;CAC5B,SAAS;EACP,MAAM,QAAQ,KAAK,SAChB,QAAQ,YAAY,CAAC,OAAO,IAAI,QAAQ,IAAI,CAAC,CAAC,CAC9C,QAAQ,aAAa,QAAQ,SAAS,CAAC,EAAA,CAAG,OAAO,SAAS,MAAM,IAAI,IAAI,KAAK,OAAO,IAAI,I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