@mark1russell7/service 0.8.19 → 0.9.0

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.
Files changed (335) hide show
  1. package/README.md +6 -2
  2. package/build/backoff.d.ts +44 -2
  3. package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
  4. package/build/builder.js +499 -0
  5. package/build/builder.js.map +1 -0
  6. package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
  7. package/build/channel.d.ts +1 -1
  8. package/build/channel.js.map +1 -1
  9. package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
  10. package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
  11. package/build/client/core.js.map +1 -0
  12. package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
  13. package/build/client/dial.js +52 -0
  14. package/build/client/dial.js.map +1 -0
  15. package/build/client/machine.js +29 -0
  16. package/build/client/machine.js.map +1 -0
  17. package/build/client/meets.d.ts +35 -0
  18. package/build/client/meets.js +78 -0
  19. package/build/client/meets.js.map +1 -0
  20. package/build/clock.d.ts +2 -2
  21. package/build/clock.js +1 -1
  22. package/build/conformance.d.ts +122 -0
  23. package/build/conformance.js +469 -0
  24. package/build/conformance.js.map +1 -0
  25. package/build/contract.d.ts +28 -0
  26. package/build/contract.js +184 -0
  27. package/build/contract.js.map +1 -0
  28. package/build/description.d.ts +161 -0
  29. package/build/description.js +11 -0
  30. package/build/description.js.map +1 -0
  31. package/build/drains.js +35 -0
  32. package/build/drains.js.map +1 -0
  33. package/build/events.d.ts +25 -0
  34. package/build/fakes.d.ts +43 -0
  35. package/build/fakes.js +93 -0
  36. package/build/fakes.js.map +1 -0
  37. package/build/grpc/client.d.ts +153 -0
  38. package/build/grpc/client.js +474 -0
  39. package/build/grpc/client.js.map +1 -0
  40. package/build/grpc/connection.d.ts +97 -0
  41. package/build/grpc/connection.js +59 -0
  42. package/build/grpc/connection.js.map +1 -0
  43. package/build/grpc/machine.d.ts +12 -0
  44. package/build/grpc/machine.js +149 -0
  45. package/build/grpc/machine.js.map +1 -0
  46. package/build/grpc/meets.d.ts +14 -0
  47. package/build/grpc/meets.js +105 -0
  48. package/build/grpc/meets.js.map +1 -0
  49. package/build/grpc/starting.d.ts +33 -0
  50. package/build/grpc/starting.js +89 -0
  51. package/build/grpc/starting.js.map +1 -0
  52. package/build/grpc.d.ts +9 -303
  53. package/build/grpc.js +7 -854
  54. package/build/health.d.ts +93 -0
  55. package/build/health.js +225 -0
  56. package/build/health.js.map +1 -0
  57. package/build/heartbeat.d.ts +6 -2
  58. package/build/heartbeat.js.map +1 -1
  59. package/build/host/discovery.d.ts +61 -0
  60. package/build/host/discovery.js +113 -0
  61. package/build/host/discovery.js.map +1 -0
  62. package/build/host/env.d.ts +14 -0
  63. package/build/host/env.js +57 -0
  64. package/build/host/env.js.map +1 -0
  65. package/build/host/fakes.d.ts +82 -0
  66. package/build/host/fakes.js +239 -0
  67. package/build/host/fakes.js.map +1 -0
  68. package/build/host/group.d.ts +142 -0
  69. package/build/host/group.js +524 -0
  70. package/build/host/group.js.map +1 -0
  71. package/build/host/install.d.ts +96 -0
  72. package/build/host/install.js +330 -0
  73. package/build/host/install.js.map +1 -0
  74. package/build/host/lock.d.ts +78 -0
  75. package/build/host/lock.js +190 -0
  76. package/build/host/lock.js.map +1 -0
  77. package/build/host/logs.d.ts +26 -0
  78. package/build/host/logs.js +48 -0
  79. package/build/host/logs.js.map +1 -0
  80. package/build/host/node.d.ts +14 -0
  81. package/build/host/node.js +309 -0
  82. package/build/host/node.js.map +1 -0
  83. package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
  84. package/build/host/ports.js +17 -0
  85. package/build/host/ports.js.map +1 -0
  86. package/build/host/probes.d.ts +51 -0
  87. package/build/host/probes.js +139 -0
  88. package/build/host/probes.js.map +1 -0
  89. package/build/host/processes.d.ts +32 -0
  90. package/build/host/processes.js +63 -0
  91. package/build/host/processes.js.map +1 -0
  92. package/build/host/render.d.ts +84 -0
  93. package/build/host/render.js +235 -0
  94. package/build/host/render.js.map +1 -0
  95. package/build/host/watch.d.ts +90 -0
  96. package/build/host/watch.js +165 -0
  97. package/build/host/watch.js.map +1 -0
  98. package/build/host.d.ts +13 -671
  99. package/build/host.js +12 -2126
  100. package/build/http/answers.js +29 -0
  101. package/build/http/answers.js.map +1 -0
  102. package/build/http/fake-server.js +61 -0
  103. package/build/http/fake-server.js.map +1 -0
  104. package/build/http/outcome.d.ts +115 -0
  105. package/build/http/outcome.js +325 -0
  106. package/build/http/outcome.js.map +1 -0
  107. package/build/http/probes.d.ts +83 -0
  108. package/build/http/probes.js +232 -0
  109. package/build/http/probes.js.map +1 -0
  110. package/build/http/transport.d.ts +165 -0
  111. package/build/http/transport.js +518 -0
  112. package/build/http/transport.js.map +1 -0
  113. package/build/http-client/client.d.ts +121 -0
  114. package/build/http-client/client.js +330 -0
  115. package/build/http-client/client.js.map +1 -0
  116. package/build/http-client/connection.d.ts +78 -0
  117. package/build/http-client/connection.js +54 -0
  118. package/build/http-client/connection.js.map +1 -0
  119. package/build/http-client/machine.d.ts +14 -0
  120. package/build/http-client/machine.js +109 -0
  121. package/build/http-client/machine.js.map +1 -0
  122. package/build/http-client/meets.d.ts +11 -0
  123. package/build/http-client/meets.js +74 -0
  124. package/build/http-client/meets.js.map +1 -0
  125. package/build/http-client/session.d.ts +87 -0
  126. package/build/http-client/session.js +99 -0
  127. package/build/http-client/session.js.map +1 -0
  128. package/build/http-client/starting.d.ts +25 -0
  129. package/build/http-client/starting.js +65 -0
  130. package/build/http-client/starting.js.map +1 -0
  131. package/build/http-client.d.ts +9 -330
  132. package/build/http-client.js +8 -707
  133. package/build/http.d.ts +5 -353
  134. package/build/http.js +3 -1086
  135. package/build/identity.d.ts +16 -0
  136. package/build/identity.js +44 -0
  137. package/build/identity.js.map +1 -0
  138. package/build/index.d.ts +35 -412
  139. package/build/index.js +25 -3278
  140. package/build/knobs.d.ts +1 -0
  141. package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
  142. package/build/knobs.js.map +1 -0
  143. package/build/latch.d.ts +29 -0
  144. package/build/latch.js +122 -0
  145. package/build/latch.js.map +1 -0
  146. package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
  147. package/build/law.js +149 -0
  148. package/build/law.js.map +1 -0
  149. package/build/lifecycle.d.ts +144 -0
  150. package/build/lifecycle.js +411 -0
  151. package/build/lifecycle.js.map +1 -0
  152. package/build/limiter/machine.d.ts +40 -0
  153. package/build/limiter/machine.js +279 -0
  154. package/build/limiter/machine.js.map +1 -0
  155. package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
  156. package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
  157. package/build/limiter/policy.js.map +1 -0
  158. package/build/{limiter-BNKnwzeY.d.ts → limiter/quota.d.ts} +32 -74
  159. package/build/{limiter-DrM0PQV9.js → limiter/quota.js} +3 -418
  160. package/build/limiter/quota.js.map +1 -0
  161. package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
  162. package/build/limiter/store.js +145 -0
  163. package/build/limiter/store.js.map +1 -0
  164. package/build/limiter.d.ts +4 -3
  165. package/build/limiter.js +4 -2
  166. package/build/lint.d.ts +152 -0
  167. package/build/lint.js +576 -0
  168. package/build/lint.js.map +1 -0
  169. package/build/logger.d.ts +71 -0
  170. package/build/logger.js +183 -0
  171. package/build/logger.js.map +1 -0
  172. package/build/machines.d.ts +41 -0
  173. package/build/machines.js +451 -0
  174. package/build/machines.js.map +1 -0
  175. package/build/metrics.d.ts +53 -0
  176. package/build/metrics.js +111 -0
  177. package/build/metrics.js.map +1 -0
  178. package/build/mongodb/client.d.ts +131 -0
  179. package/build/mongodb/client.js +388 -0
  180. package/build/mongodb/client.js.map +1 -0
  181. package/build/mongodb/connection.d.ts +112 -0
  182. package/build/mongodb/connection.js +12 -0
  183. package/build/mongodb/connection.js.map +1 -0
  184. package/build/mongodb/machine.d.ts +14 -0
  185. package/build/mongodb/machine.js +122 -0
  186. package/build/mongodb/machine.js.map +1 -0
  187. package/build/mongodb/meets.d.ts +15 -0
  188. package/build/mongodb/meets.js +103 -0
  189. package/build/mongodb/meets.js.map +1 -0
  190. package/build/mongodb/starting.d.ts +29 -0
  191. package/build/mongodb/starting.js +77 -0
  192. package/build/mongodb/starting.js.map +1 -0
  193. package/build/mongodb.d.ts +8 -296
  194. package/build/mongodb.js +7 -682
  195. package/build/operation.d.ts +27 -0
  196. package/build/{operation-DF73RZOI.js → operation.js} +2 -2
  197. package/build/operation.js.map +1 -0
  198. package/build/otel.d.ts +2 -2
  199. package/build/pg/client.d.ts +96 -0
  200. package/build/pg/client.js +277 -0
  201. package/build/pg/client.js.map +1 -0
  202. package/build/pg/connection.d.ts +75 -0
  203. package/build/pg/connection.js +11 -0
  204. package/build/pg/connection.js.map +1 -0
  205. package/build/pg/machine.d.ts +13 -0
  206. package/build/pg/machine.js +111 -0
  207. package/build/pg/machine.js.map +1 -0
  208. package/build/pg/meets.d.ts +14 -0
  209. package/build/pg/meets.js +83 -0
  210. package/build/pg/meets.js.map +1 -0
  211. package/build/pg/starting.d.ts +26 -0
  212. package/build/pg/starting.js +62 -0
  213. package/build/pg/starting.js.map +1 -0
  214. package/build/pg.d.ts +8 -219
  215. package/build/pg.js +7 -525
  216. package/build/poller.d.ts +9 -0
  217. package/build/poller.js +154 -0
  218. package/build/poller.js.map +1 -0
  219. package/build/process.d.ts +114 -0
  220. package/build/process.js +170 -0
  221. package/build/process.js.map +1 -0
  222. package/build/profiles.d.ts +68 -0
  223. package/build/profiles.js +120 -0
  224. package/build/profiles.js.map +1 -0
  225. package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
  226. package/build/queue.js +279 -0
  227. package/build/queue.js.map +1 -0
  228. package/build/rabbitmq/client.d.ts +144 -0
  229. package/build/rabbitmq/client.js +426 -0
  230. package/build/rabbitmq/client.js.map +1 -0
  231. package/build/rabbitmq/connection.d.ts +91 -0
  232. package/build/rabbitmq/connection.js +15 -0
  233. package/build/rabbitmq/connection.js.map +1 -0
  234. package/build/rabbitmq/machine.d.ts +13 -0
  235. package/build/rabbitmq/machine.js +159 -0
  236. package/build/rabbitmq/machine.js.map +1 -0
  237. package/build/rabbitmq/meets.d.ts +12 -0
  238. package/build/rabbitmq/meets.js +96 -0
  239. package/build/rabbitmq/meets.js.map +1 -0
  240. package/build/rabbitmq/starting.d.ts +27 -0
  241. package/build/rabbitmq/starting.js +67 -0
  242. package/build/rabbitmq/starting.js.map +1 -0
  243. package/build/rabbitmq.d.ts +8 -283
  244. package/build/rabbitmq.js +7 -742
  245. package/build/redis/client.d.ts +86 -0
  246. package/build/redis/client.js +285 -0
  247. package/build/redis/client.js.map +1 -0
  248. package/build/redis/connection.d.ts +57 -0
  249. package/build/redis/connection.js +11 -0
  250. package/build/redis/connection.js.map +1 -0
  251. package/build/redis/limiter.d.ts +43 -0
  252. package/build/redis/limiter.js +164 -0
  253. package/build/redis/limiter.js.map +1 -0
  254. package/build/redis/machine.d.ts +12 -0
  255. package/build/redis/machine.js +144 -0
  256. package/build/redis/machine.js.map +1 -0
  257. package/build/redis/meets.d.ts +11 -0
  258. package/build/redis/meets.js +75 -0
  259. package/build/redis/meets.js.map +1 -0
  260. package/build/redis/operations.d.ts +5 -0
  261. package/build/redis/operations.js +114 -0
  262. package/build/redis/operations.js.map +1 -0
  263. package/build/redis.d.ts +10 -207
  264. package/build/redis.js +9 -771
  265. package/build/requests.d.ts +66 -0
  266. package/build/requests.js +279 -0
  267. package/build/requests.js.map +1 -0
  268. package/build/retrier.d.ts +62 -0
  269. package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
  270. package/build/retrier.js.map +1 -0
  271. package/build/routes.d.ts +35 -0
  272. package/build/routes.js +77 -0
  273. package/build/routes.js.map +1 -0
  274. package/build/rules.d.ts +19 -2
  275. package/build/stops.d.ts +51 -0
  276. package/build/stops.js +86 -0
  277. package/build/stops.js.map +1 -0
  278. package/build/testing.d.ts +8 -270
  279. package/build/testing.js +4 -1027
  280. package/build/testing.js.map +1 -1
  281. package/build/timing.d.ts +63 -0
  282. package/build/{timing-DZl36uXs.js → timing.js} +2 -2
  283. package/build/timing.js.map +1 -0
  284. package/build/units.d.ts +17 -0
  285. package/build/units.js +236 -0
  286. package/build/units.js.map +1 -0
  287. package/build/watchdog.d.ts +38 -0
  288. package/build/watchdog.js +57 -0
  289. package/build/watchdog.js.map +1 -0
  290. package/build/websocket/client.d.ts +136 -0
  291. package/build/websocket/client.js +422 -0
  292. package/build/websocket/client.js.map +1 -0
  293. package/build/websocket/connection.d.ts +83 -0
  294. package/build/websocket/connection.js +57 -0
  295. package/build/websocket/connection.js.map +1 -0
  296. package/build/websocket/machine.d.ts +12 -0
  297. package/build/websocket/machine.js +155 -0
  298. package/build/websocket/machine.js.map +1 -0
  299. package/build/websocket/meets.d.ts +14 -0
  300. package/build/websocket/meets.js +92 -0
  301. package/build/websocket/meets.js.map +1 -0
  302. package/build/websocket/starting.d.ts +25 -0
  303. package/build/websocket/starting.js +69 -0
  304. package/build/websocket/starting.js.map +1 -0
  305. package/build/websocket.d.ts +9 -264
  306. package/build/websocket.js +8 -774
  307. package/build/worker.d.ts +92 -0
  308. package/build/worker.js +153 -0
  309. package/build/worker.js.map +1 -0
  310. package/package.json +5 -4
  311. package/build/backoff-QTRGfkEK.d.ts +0 -45
  312. package/build/clock-DpVgpY4h.d.ts +0 -2
  313. package/build/grpc.js.map +0 -1
  314. package/build/host.js.map +0 -1
  315. package/build/http-client.js.map +0 -1
  316. package/build/http.js.map +0 -1
  317. package/build/index.js.map +0 -1
  318. package/build/knobs-BJcz6m01.js.map +0 -1
  319. package/build/lifecycle-D0J-zwZF.d.ts +0 -374
  320. package/build/limiter-DrM0PQV9.js.map +0 -1
  321. package/build/logger-B6drv9w0.d.ts +0 -488
  322. package/build/machine-BhVeHr_m.js.map +0 -1
  323. package/build/mongodb.js.map +0 -1
  324. package/build/operation-DF73RZOI.js.map +0 -1
  325. package/build/pg.js.map +0 -1
  326. package/build/policy-UYALkqVq.js.map +0 -1
  327. package/build/process-7R9M29wN.js +0 -437
  328. package/build/process-7R9M29wN.js.map +0 -1
  329. package/build/rabbitmq.js.map +0 -1
  330. package/build/redis.js.map +0 -1
  331. package/build/requests-DD2ALv0_.js +0 -583
  332. package/build/requests-DD2ALv0_.js.map +0 -1
  333. package/build/retrier-Dnjhvxol.js.map +0 -1
  334. package/build/timing-DZl36uXs.js.map +0 -1
  335. package/build/websocket.js.map +0 -1
@@ -0,0 +1,524 @@
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) {
244
+ const reset = ports.clock.after(ms(restart.resetAfter), () => {
245
+ if (unit.child === child && unit.phase === "ready") unit.retry?.reset();
246
+ });
247
+ reset.unref?.();
248
+ unit.timers.push(reset);
249
+ }
250
+ if (unit.spec.alive !== void 0) watch(unit, child, unit.spec.alive);
251
+ considerAll();
252
+ };
253
+ /** This function uses the liveness probe of a ready program each interval, and stops the program after `failures` failures in sequence. */
254
+ const watch = (unit, child, alive) => {
255
+ let failures = 0;
256
+ const current = () => unit.child === child && unit.phase === "ready" && !stopping;
257
+ const next = () => {
258
+ unit.watch = ports.clock.after(ms(alive.interval), () => {
259
+ unit.watch = null;
260
+ check();
261
+ });
262
+ unit.watch.unref?.();
263
+ };
264
+ const check = async () => {
265
+ if (!current()) return;
266
+ const result = await probeOnce(alive.probe, ms(alive.timeout), ports);
267
+ if (!current()) return;
268
+ if (result.ok) {
269
+ if (failures > 0) say("info", `${unit.spec.name} is alive again`, {
270
+ program: unit.spec.name,
271
+ pid: child.pid,
272
+ failures
273
+ });
274
+ failures = 0;
275
+ unit.detail = null;
276
+ next();
277
+ return;
278
+ }
279
+ failures += 1;
280
+ unit.detail = `the liveness probe failed ${failures} of ${alive.failures} times in sequence (${result.why})`;
281
+ if (failures < alive.failures) {
282
+ say("warn", `${unit.spec.name}: ${unit.detail}`, {
283
+ program: unit.spec.name,
284
+ pid: child.pid,
285
+ why: result.why
286
+ });
287
+ next();
288
+ return;
289
+ }
290
+ unit.reason = `its liveness probe failed ${failures} times in sequence (${result.why})`;
291
+ unit.detail = unit.reason;
292
+ say("warn", `${unit.spec.name} is not alive, thus it stops`, {
293
+ program: unit.spec.name,
294
+ pid: child.pid,
295
+ why: result.why
296
+ });
297
+ stagedStop(unit, child);
298
+ };
299
+ next();
300
+ };
301
+ const probe = (unit, child, ready) => {
302
+ const deadline = ports.clock.now() + ms(ready.within);
303
+ const attempt = async () => {
304
+ if (unit.child !== child || stopping) return;
305
+ const result = await probeOnce(ready.probe, ms(ready.timeout), ports);
306
+ if (unit.child !== child || stopping) return;
307
+ if (result.ok) {
308
+ markReady(unit, child);
309
+ return;
310
+ }
311
+ unit.detail = result.why;
312
+ if (ports.clock.now() >= deadline) {
313
+ unit.reason = `it was not ready in ${ms(ready.within)} ms (${result.why})`;
314
+ unit.detail = unit.reason;
315
+ say("warn", `${unit.spec.name} is not ready in its time, thus it stops`, {
316
+ program: unit.spec.name,
317
+ pid: child.pid,
318
+ why: result.why
319
+ });
320
+ stagedStop(unit, child);
321
+ return;
322
+ }
323
+ const again = ports.clock.after(ms(ready.interval), () => void attempt());
324
+ again.unref?.();
325
+ unit.timers.push(again);
326
+ };
327
+ attempt();
328
+ };
329
+ const exited = (unit, child, code, signal) => {
330
+ if (unit.child !== child) return;
331
+ clearTimers(unit);
332
+ unit.child = null;
333
+ for (const waiter of unit.waiters.splice(0)) waiter();
334
+ if (child.pid !== null) removeDiscovery(unit.discoveryPath, ports, child.pid);
335
+ unit.lock?.update(null).catch(() => {});
336
+ if (stopping || unit.phase === "stopping") {
337
+ unit.phase = "stopped";
338
+ return;
339
+ }
340
+ const end = child.pid === null ? `${unit.spec.program} did not start` : `it exited with ${code === null ? `the signal ${signal ?? "unknown"}` : `the code ${code}`}`;
341
+ unit.detail = unit.reason === null ? end : `${unit.reason}, then ${end}`;
342
+ unit.reason = null;
343
+ say("warn", `${unit.spec.name} stopped: ${unit.detail}`, {
344
+ program: unit.spec.name,
345
+ pid: child.pid,
346
+ code,
347
+ signal
348
+ });
349
+ later(unit, "backoff");
350
+ };
351
+ const launch = async (unit) => {
352
+ unit.phase = "starting";
353
+ unit.detail = null;
354
+ const name = unit.spec.name;
355
+ if (unit.lock === null) {
356
+ const taken = await acquireInstanceLock(unit.lockPath, ports);
357
+ if (stopping) {
358
+ if (taken.kind === "acquired") await taken.lock.release();
359
+ return;
360
+ }
361
+ if (taken.kind !== "acquired") {
362
+ unit.detail = taken.kind === "held" ? `the process ${taken.owner.child?.pid ?? taken.owner.pid} holds the lock ${unit.lockPath}` : taken.problem;
363
+ say("warn", `${name} does not start: ${unit.detail}`, {
364
+ program: name,
365
+ lock: unit.lockPath
366
+ });
367
+ later(unit, "held");
368
+ return;
369
+ }
370
+ unit.lock = taken.lock;
371
+ }
372
+ const lock = unit.lock;
373
+ const env = await environment(unit);
374
+ if (stopping) {
375
+ await lock.release();
376
+ unit.lock = null;
377
+ return;
378
+ }
379
+ const child = ports.processes.spawn({
380
+ program: unit.spec.program,
381
+ args: unit.spec.args ?? [],
382
+ cwd: unit.spec.cwd,
383
+ env,
384
+ ipc: unit.spec.ipc ?? false
385
+ });
386
+ const startedAt = ports.wall();
387
+ unit.child = child;
388
+ child.onOutput((_stream, chunk) => unit.log?.write(chunk));
389
+ child.onExit((code, signal) => exited(unit, child, code, signal));
390
+ const pid = child.pid;
391
+ if (pid === null) return;
392
+ say("info", `${name} started`, {
393
+ program: name,
394
+ pid
395
+ });
396
+ const mark = {
397
+ pid,
398
+ startedAt
399
+ };
400
+ try {
401
+ await lock.update(mark);
402
+ await writeDiscovery(unit.discoveryPath, {
403
+ pid,
404
+ startedAt: new Date(startedAt).toISOString(),
405
+ port: unit.spec.listen?.port ?? null,
406
+ url: unit.spec.listen?.url ?? null,
407
+ extra: {
408
+ group: spec.name,
409
+ program: name
410
+ }
411
+ }, ports);
412
+ } catch (error) {
413
+ say("warn", `the files of ${name} were not written`, {
414
+ program: name,
415
+ error
416
+ });
417
+ }
418
+ if (unit.child !== child) await removeDiscovery(unit.discoveryPath, ports, pid);
419
+ if (unit.child !== child || stopping) return;
420
+ if (unit.spec.ready === void 0) markReady(unit, child);
421
+ else probe(unit, child, unit.spec.ready);
422
+ };
423
+ /** This function waits for the end of a child, for at most `wait` milliseconds. It tells if the child ended. */
424
+ const ended = (unit, child, wait) => new Promise((resolve) => {
425
+ if (unit.child !== child) {
426
+ resolve(true);
427
+ return;
428
+ }
429
+ const cancel = ports.clock.after(wait, () => resolve(unit.child !== child));
430
+ unit.waiters.push(() => {
431
+ cancel();
432
+ resolve(true);
433
+ });
434
+ });
435
+ /**
436
+ * This function stops a child in stages. The message goes on its IPC channel when it has one. Else
437
+ * Linux gets SIGTERM, and Windows gets `taskkill /T` without `/F`. After the grace, the process tree stops by its ID.
438
+ */
439
+ const stagedStop = async (unit, child) => {
440
+ const pid = child.pid;
441
+ if (pid === null || unit.child !== child) return;
442
+ const grace = ms(unit.spec.stop?.grace ?? DEFAULT_GRACE);
443
+ const gone = ended(unit, child, grace);
444
+ let asked = null;
445
+ if (child.ipc && child.send(unit.spec.stop?.message ?? "shutdown")) asked = "the IPC message";
446
+ else if (ports.platform === "win32") {
447
+ if ((await ports.commands.run("taskkill", [
448
+ "/T",
449
+ "/PID",
450
+ String(pid)
451
+ ]).catch(() => null))?.code === 0) asked = "taskkill";
452
+ } else {
453
+ const signal = unit.spec.stop?.signal ?? "SIGTERM";
454
+ if (ports.processes.signal(pid, signal)) asked = signal;
455
+ }
456
+ say("info", `${unit.spec.name} stops${asked === null ? "" : ` through ${asked}`}`, {
457
+ program: unit.spec.name,
458
+ pid,
459
+ grace: {
460
+ value: grace,
461
+ unit: "ms"
462
+ }
463
+ });
464
+ if (asked !== null && await gone) return;
465
+ const tree = await stopTree(pid, ports);
466
+ const why = asked === null ? "the staged stop did not go" : "it did not stop in its grace";
467
+ say(tree.kind === "failed" ? "error" : "warn", `${unit.spec.name}: ${why}, thus its process tree stops: ${tree.kind}`, {
468
+ program: unit.spec.name,
469
+ pid,
470
+ outcome: tree.kind
471
+ });
472
+ if (!await ended(unit, child, grace)) say("error", `${unit.spec.name} did not end after the stop of its process tree`, {
473
+ program: unit.spec.name,
474
+ pid
475
+ });
476
+ };
477
+ const stopUnit = async (unit) => {
478
+ clearTimers(unit);
479
+ const child = unit.child;
480
+ const pid = child?.pid ?? null;
481
+ if (child !== null && pid !== null) {
482
+ unit.phase = "stopping";
483
+ await stagedStop(unit, child);
484
+ await removeDiscovery(unit.discoveryPath, ports, pid);
485
+ }
486
+ unit.phase = "stopped";
487
+ await unit.lock?.release();
488
+ unit.lock = null;
489
+ };
490
+ return {
491
+ start() {
492
+ if (started || stopping) return;
493
+ started = true;
494
+ say("info", `the group ${spec.name} starts`, { layers });
495
+ considerAll();
496
+ },
497
+ stop() {
498
+ if (stopped !== null) return stopped;
499
+ stopping = true;
500
+ abort.abort();
501
+ stopped = (async () => {
502
+ for (const layer of [...layers].reverse()) await Promise.all(layer.map((name) => stopUnit(unitOf(name))));
503
+ await Promise.all([...units.values()].map((unit) => unit.log?.flush()));
504
+ say("info", `the group ${spec.name} stopped`, {});
505
+ })();
506
+ return stopped;
507
+ },
508
+ states() {
509
+ return spec.programs.map((program) => {
510
+ const unit = unitOf(program.name);
511
+ return {
512
+ name: program.name,
513
+ phase: unit.phase,
514
+ pid: unit.child?.pid ?? null,
515
+ restarts: unit.restarts,
516
+ detail: unit.detail
517
+ };
518
+ });
519
+ }
520
+ };
521
+ };
522
+ export { DEFAULT_RESTART, groupProblems, startOrder, superviseGroup };
523
+
524
+ //# 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 const reset = ports.clock.after(ms(restart.resetAfter), () => {\n if (unit.child === child && unit.phase === \"ready\") unit.retry?.reset();\n });\n // the child keeps the supervisor alive, thus this timer does not (SYS-126)\n reset.unref?.();\n unit.timers.push(reset);\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 // the child keeps the supervisor alive, thus the watch does not (SYS-126)\n unit.watch.unref?.();\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 const again = ports.clock.after(ms(ready.interval), () => void attempt());\n // the child keeps the supervisor alive, thus the poll of its readiness does not (SYS-126)\n again.unref?.();\n unit.timers.push(again);\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 // the stop awaits this wait, thus it keeps the process alive (SYS-126)\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,IAAI,CAAC,CAAC,CAAC,CAC/F,KAAK,YAAY,QAAQ,IAAI;EAChC,IAAI,MAAM,WAAW,GAAG,OAAO;EAC/B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