@tpsdev-ai/flair 0.57.0 → 0.58.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.
- package/README.md +4 -4
- package/SECURITY.md +4 -1
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1685 -279
- package/dist/commands/doctor.js +162 -4
- package/dist/commands/federation.js +2 -1
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +150 -44
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/daemon-liveness.js +61 -0
- package/dist/lib/doctor-run.js +5 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +176 -6
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +27 -14
- package/dist/resources/AgentSeed.js +35 -1
- package/dist/resources/Federation.js +70 -52
- package/dist/resources/Memory.js +567 -72
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +4 -0
- package/dist/resources/MemoryFeed.js +204 -3
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +53 -3
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +167 -78
- package/dist/resources/SemanticSearch.js +19 -6
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +7 -3
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/auth-middleware.js +135 -48
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +12 -0
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/health.js +57 -14
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/instance-identity.js +3 -2
- package/dist/resources/mcp-handler.js +147 -51
- package/dist/resources/mcp-tools.js +25 -21
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +9 -12
- package/dist/resources/record-types.js +6 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +289 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +19 -21
- package/dist/resources/semantic-retrieval-core.js +5 -1
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/memory-attributes.js +77 -0
- package/docs/api-reference.md +79 -15
- package/docs/claude-code.md +132 -0
- package/docs/deployment.md +1 -1
- package/docs/federation.md +1 -1
- package/docs/integrations.md +5 -5
- package/docs/mcp-clients.md +11 -21
- package/docs/notes/mcp-oauth-model2.md +15 -1
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +134 -2
- package/docs/supply-chain-policy.md +10 -5
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +187 -61
- package/package.json +9 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +106 -17
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
- package/dist/resources/federation-nonce-store.js +0 -195
package/dist/lib/owned-pins.js
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
import { existsSync, lstatSync, readFileSync, statSync } from "node:fs";
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { withHome } from "./home.js";
|
|
19
|
-
import { ALL_CLIENTS, clientConfigPath, repinCodexPin, repinJsonMcpPin, } from "../install/clients.js";
|
|
20
|
-
import { checkSessionStartHook, isFlairHookCommand, readClientMcpBlock, } from "../doctor-client.js";
|
|
19
|
+
import { ALL_CLIENTS, clientConfigPath, codexWiringPin, repinCodexPin, repinJsonMcpPin, } from "../install/clients.js";
|
|
20
|
+
import { checkSessionStartHook, isFlairHookCommand, SESSION_START_HOOK_INVOCATION_RE, readClientMcpBlock, } from "../doctor-client.js";
|
|
21
21
|
import { decodeWiringSpec, decodeWiringSpecs, isComparableWiringPin, wiringPinString, } from "./wiring-spec.js";
|
|
22
22
|
import { isUnsafeAdapterPin } from "./stale-client-pin.js";
|
|
23
|
-
import { hookInstallHint, hookSettingsPath, repinSessionStartHook, SUPPORTED_HARNESSES, } from "../hook-install.js";
|
|
23
|
+
import { hookInstallHint, parseInstallerHookForm, hookSettingsPath, repinSessionStartHook, SUPPORTED_HARNESSES, } from "../hook-install.js";
|
|
24
24
|
import { flairCliVersion, isResolvedVersion, FLAIR_MCP_PACKAGE } from "./mcp-spec.js";
|
|
25
25
|
import { comparePinVersions, pinWriteWouldLowerOrIsUnknown } from "./upgrade-status.js";
|
|
26
26
|
function displayHomePath(homeDir, path) {
|
|
@@ -87,7 +87,9 @@ export function readOwnedPin(target, homeDir) {
|
|
|
87
87
|
entryExists: block.entryExists,
|
|
88
88
|
// Read the pin whenever the ENTRY exists — an entry without an identity is
|
|
89
89
|
// still a pin we own and may refresh (flair#1834 A1 item 1).
|
|
90
|
-
pin: block.entryExists
|
|
90
|
+
pin: block.entryExists
|
|
91
|
+
? wiringPinString(decodeWiringSpec(target.id === "codex" ? codexWiringPin(text) : text, FLAIR_MCP_PACKAGE))
|
|
92
|
+
: null,
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
export function readOwnedPins(homeDir) {
|
|
@@ -280,8 +282,20 @@ export function repinSessionStartHookGuarded(homeDir, harness, target) {
|
|
|
280
282
|
displayPath: hookSettingsPath(homeDir, harness),
|
|
281
283
|
};
|
|
282
284
|
const wouldWrite = flairCliVersion();
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
+
const command = checkSessionStartHook(homeDir, resolved.path).command;
|
|
286
|
+
const form = command ? parseInstallerHookForm(command) : null;
|
|
287
|
+
// A form supplies the exact span the writer replaces. For a rejected form,
|
|
288
|
+
// the status-only match may recover an unreadable pin for a HOLD; it cannot
|
|
289
|
+
// authorize a write. The writer still validates the full command in-lock.
|
|
290
|
+
const invocation = form ? undefined : command?.match(SESSION_START_HOOK_INVOCATION_RE)?.[0];
|
|
291
|
+
const spec = form?.pkgSpec
|
|
292
|
+
?? invocation?.slice("npx -y -p ".length, -" flair-session-start".length);
|
|
293
|
+
const existing = spec ? wiringPinString(decodeWiringSpec(spec, FLAIR_MCP_PACKAGE)) : null;
|
|
294
|
+
// A comparable pin in a non-installer command is a shape refusal, not an
|
|
295
|
+
// unknown pin. Let the writer retain its "not one of the installer forms"
|
|
296
|
+
// classification. Unreadable pins retain their raw-value hold diagnostic.
|
|
297
|
+
if (pinWriteWouldLowerOrIsUnknown(existing, wouldWrite)
|
|
298
|
+
&& (form !== null || comparePinVersions(existing, wouldWrite) === null)) {
|
|
285
299
|
return {
|
|
286
300
|
target: resolved,
|
|
287
301
|
action: "hold",
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* service-repoint-apply.ts — commit a re-point plan to an operator's unit file
|
|
3
|
+
* (flair#2034 §2).
|
|
4
|
+
*
|
|
5
|
+
* The planners in service-repoint.ts are pure. This module is where a plan
|
|
6
|
+
* meets the file and the service manager, and it holds three rules:
|
|
7
|
+
*
|
|
8
|
+
* 1. A plan is written only over the file it was PLANNED FROM: the file was
|
|
9
|
+
* read as a regular file (never through a symlink), and immediately before
|
|
10
|
+
* the rename it is re-checked — same file, same bytes — or nothing is
|
|
11
|
+
* written (atomic-write.ts, `expect`).
|
|
12
|
+
* 2. systemd: after the write, the manager is reloaded and asked what it now
|
|
13
|
+
* holds for the unit (the file it loaded, its drop-ins, its working
|
|
14
|
+
* directory). When the reload fails or the manager does not hold what was
|
|
15
|
+
* written, the previous bytes are put back, the manager is reloaded again
|
|
16
|
+
* and ASKED AGAIN. That query compares three fields — FragmentPath,
|
|
17
|
+
* drop-ins, WorkingDirectory — with the values captured before the write;
|
|
18
|
+
* when they are back, the result says exactly that, and still calls full
|
|
19
|
+
* agreement between the restored file and the manager unverified (three
|
|
20
|
+
* fields are not the whole unit). Anything short of that — a failed
|
|
21
|
+
* restore, a failed second reload, a different or missing answer — is
|
|
22
|
+
* reported with the manager's state as UNVERIFIED.
|
|
23
|
+
* 3. Linux: a unit with drop-ins — any the manager reports, from any
|
|
24
|
+
* location, or a `<unit>.d` directory beside the file — is refused, and
|
|
25
|
+
* so is one whose MainPID, asked again immediately before the write, is
|
|
26
|
+
* not the serving process the unit was proven to run.
|
|
27
|
+
* 4. `flair restart` on Linux (restartOnLinux): a proven user unit is
|
|
28
|
+
* restarted through systemd and its new main process verified; a process
|
|
29
|
+
* that is the main process of any other systemd unit is never stopped and
|
|
30
|
+
* respawned outside it.
|
|
31
|
+
*
|
|
32
|
+
* Every filesystem and service-manager call is injectable, so each branch is
|
|
33
|
+
* driven by a test with no real launchd, systemd or operator file.
|
|
34
|
+
*/
|
|
35
|
+
import { snapshotRegularFile, writeFilesAtomically } from "./atomic-write.js";
|
|
36
|
+
import { planSystemdUnitRuntimeRepoint } from "./service-repoint.js";
|
|
37
|
+
import { planLinuxRestart, restartedUnitProblem, } from "./tree-divergence.js";
|
|
38
|
+
function msg(err) {
|
|
39
|
+
return err?.message ?? String(err);
|
|
40
|
+
}
|
|
41
|
+
/** Apply `plan`, which was computed from `planned` (see the module header). */
|
|
42
|
+
export function applyRepointPlan(plan, planned, opts = {}) {
|
|
43
|
+
const unitPath = planned.path;
|
|
44
|
+
switch (plan.kind) {
|
|
45
|
+
case "current":
|
|
46
|
+
case "pinned-node":
|
|
47
|
+
return { kind: plan.kind, unitPath, detail: plan.detail };
|
|
48
|
+
case "refuse":
|
|
49
|
+
return { kind: "refused", unitPath, detail: plan.detail };
|
|
50
|
+
case "repoint":
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
if (opts.dryRun)
|
|
54
|
+
return { kind: "would-repoint", unitPath, detail: plan.detail.replace(/^re-pointed/, "would re-point") };
|
|
55
|
+
const handEdit = opts.handEdit ? ` ${opts.handEdit}` : "";
|
|
56
|
+
try {
|
|
57
|
+
writeFilesAtomically([{ path: unitPath, content: plan.text, mode: planned.mode, expect: planned }], opts.atomic);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return {
|
|
61
|
+
kind: "refused",
|
|
62
|
+
unitPath,
|
|
63
|
+
detail: `${unitPath} was not re-pointed: ${msg(err)}. Re-run the command to plan again from the file as it is now.${handEdit}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!opts.reload)
|
|
67
|
+
return { kind: "repointed", unitPath, detail: plan.detail };
|
|
68
|
+
let failure = null;
|
|
69
|
+
try {
|
|
70
|
+
opts.reload();
|
|
71
|
+
failure = opts.verifyLoaded?.("planned") ?? null;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
failure = `the service manager could not reload it (${msg(err)})`;
|
|
75
|
+
}
|
|
76
|
+
if (failure === null)
|
|
77
|
+
return { kind: "repointed", unitPath, detail: plan.detail };
|
|
78
|
+
const unverified = "Run: systemctl --user daemon-reload, then check the unit with systemctl --user show.";
|
|
79
|
+
// Put the planned-from bytes back — only over the bytes flair itself wrote.
|
|
80
|
+
try {
|
|
81
|
+
const written = snapshotRegularFile(unitPath, { lstat: opts.atomic?.lstat, readBytes: opts.atomic?.readBytes });
|
|
82
|
+
if (written.content !== plan.text)
|
|
83
|
+
throw new Error(`${unitPath} was changed after flair wrote it`);
|
|
84
|
+
writeFilesAtomically([{ path: unitPath, content: planned.content, mode: planned.mode, expect: written }], opts.atomic);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
return {
|
|
88
|
+
kind: "refused",
|
|
89
|
+
unitPath,
|
|
90
|
+
detail: `${unitPath} was re-pointed on disk, but ${failure}, and restoring its previous content failed (${msg(err)}). ` +
|
|
91
|
+
"The file holds the RE-POINTED unit flair wrote (or, if it was changed after that write, the change); which " +
|
|
92
|
+
`unit the service manager holds is UNVERIFIED. Check the file by hand. ${unverified}`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
opts.reload();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
return {
|
|
100
|
+
kind: "refused",
|
|
101
|
+
unitPath,
|
|
102
|
+
detail: `${unitPath} was not re-pointed: ${failure}. flair restored the file's previous content, but reloading the ` +
|
|
103
|
+
`service manager again failed (${msg(err)}): the file holds the previous unit; which unit the manager holds is ` +
|
|
104
|
+
`UNVERIFIED. ${unverified}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let back;
|
|
108
|
+
try {
|
|
109
|
+
back = opts.verifyLoaded ? opts.verifyLoaded("previous") : "flair cannot query this service manager";
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
back = `the service manager could not be queried (${msg(err)})`;
|
|
113
|
+
}
|
|
114
|
+
if (back !== null) {
|
|
115
|
+
return {
|
|
116
|
+
kind: "refused",
|
|
117
|
+
unitPath,
|
|
118
|
+
detail: `${unitPath} was not re-pointed: ${failure}. flair restored the file's previous content and reloaded the ` +
|
|
119
|
+
"service manager, but the manager does not report the FragmentPath, drop-ins and WorkingDirectory captured " +
|
|
120
|
+
`before the write (${back}): the file holds the previous unit; which unit the manager holds is UNVERIFIED. ${unverified}`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
kind: "refused",
|
|
125
|
+
unitPath,
|
|
126
|
+
detail: `${unitPath} was not re-pointed: ${failure}. flair restored the file's previous content and reloaded the service ` +
|
|
127
|
+
"manager; the manager's FragmentPath, drop-ins and WorkingDirectory are back at the values captured before the " +
|
|
128
|
+
"write. Only those three fields were checked, so full agreement between the restored file and what the manager " +
|
|
129
|
+
`loaded is unverified.${handEdit}`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Re-point the systemd USER unit proven to own the serving process (Linux).
|
|
134
|
+
* Refuses drop-ins and anything that is not a regular unit file; plans from the
|
|
135
|
+
* snapshot; after the reload, requires the manager to report the same file, no
|
|
136
|
+
* drop-ins, and the new working directory — else restores (see applyRepointPlan).
|
|
137
|
+
*/
|
|
138
|
+
export function repointSystemdUserUnit(serving, targets, deps, opts = {}) {
|
|
139
|
+
const unitPath = serving.unitPath;
|
|
140
|
+
const handEdit = `point its node, Harper entry${targets.launcher ? ", launcher (if it runs one)" : ""} and WorkingDirectory at ` +
|
|
141
|
+
`${targets.workingDirectory} by hand, then run: flair restart`;
|
|
142
|
+
if (serving.dropInPaths.length > 0) {
|
|
143
|
+
return {
|
|
144
|
+
kind: "refused",
|
|
145
|
+
unitPath,
|
|
146
|
+
detail: `systemd applies drop-ins to ${serving.unitName} (${serving.dropInPaths.join(", ")}), and a drop-in can set ` +
|
|
147
|
+
`ExecStart= or WorkingDirectory=, so flair does not re-point it. To move it, ${handEdit}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (deps.exists(`${unitPath}.d`)) {
|
|
151
|
+
return {
|
|
152
|
+
kind: "refused",
|
|
153
|
+
unitPath,
|
|
154
|
+
detail: `${unitPath}.d exists and can hold drop-ins that set ExecStart= or WorkingDirectory=, so flair does not ` +
|
|
155
|
+
`re-point the unit. To move it, ${handEdit}`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
let planned;
|
|
159
|
+
try {
|
|
160
|
+
planned = snapshotRegularFile(unitPath, { lstat: deps.atomic?.lstat, readBytes: deps.atomic?.readBytes });
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
return {
|
|
164
|
+
kind: "refused",
|
|
165
|
+
unitPath,
|
|
166
|
+
detail: `${unitPath} is not re-pointed: ${msg(err)}; flair rewrites only a regular unit file in place. To move it, ${handEdit}`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const plan = planSystemdUnitRuntimeRepoint(planned.content, serving.unitTree ?? serving.dir, targets, deps.repoint, unitPath);
|
|
170
|
+
// Capture what the manager holds BEFORE writing: a restore is confirmed
|
|
171
|
+
// against it. When it cannot be read, a failed reload could never be
|
|
172
|
+
// verified, so nothing is written. The same answer must still name the
|
|
173
|
+
// serving process as the unit's MainPID.
|
|
174
|
+
let before = null;
|
|
175
|
+
if (plan.kind === "repoint" && !opts.dryRun) {
|
|
176
|
+
before = deps.unitState(serving.unitName);
|
|
177
|
+
if (!before || before.fragmentPath === null || !deps.repoint.samePath(before.fragmentPath, unitPath) || before.dropInPaths.length > 0) {
|
|
178
|
+
return {
|
|
179
|
+
kind: "refused",
|
|
180
|
+
unitPath,
|
|
181
|
+
detail: `${unitPath} is not re-pointed: systemd ${before ? `reports ${serving.unitName} from ${before.fragmentPath ?? "no file"} with drop-ins [${before.dropInPaths.join(", ")}]` : `did not report ${serving.unitName}`}, ` +
|
|
182
|
+
`so the state to restore to cannot be captured. To move it, ${handEdit}`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// The write rests on the proof that this unit runs the serving process (its
|
|
186
|
+
// MainPID). A fresh answer naming another main process, or none, contradicts
|
|
187
|
+
// that proof, so nothing is written.
|
|
188
|
+
if (before.mainPid !== serving.pid) {
|
|
189
|
+
return {
|
|
190
|
+
kind: "refused",
|
|
191
|
+
unitPath,
|
|
192
|
+
detail: `${unitPath} is not re-pointed: systemd now reports ` +
|
|
193
|
+
`${before.mainPid === null ? "no main process" : `pid ${before.mainPid} as the main process`} ` +
|
|
194
|
+
`of ${serving.unitName}, ` +
|
|
195
|
+
`not the serving process (pid ${serving.pid}) it was proven to run, so the unit is not shown to run this ` +
|
|
196
|
+
`instance. Run \`flair status\` to see which process serves it, then re-run the command. To move it, ${handEdit}`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const same = (a, b) => (a === null || b === null ? a === b : deps.repoint.samePath(a, b));
|
|
201
|
+
return applyRepointPlan(plan, planned, {
|
|
202
|
+
dryRun: opts.dryRun,
|
|
203
|
+
atomic: deps.atomic,
|
|
204
|
+
reload: deps.reload,
|
|
205
|
+
handEdit: `To move it, ${handEdit}`,
|
|
206
|
+
verifyLoaded: (want) => {
|
|
207
|
+
const st = deps.unitState(serving.unitName);
|
|
208
|
+
if (!st)
|
|
209
|
+
return `systemd did not report ${serving.unitName} after the reload`;
|
|
210
|
+
if (want === "previous") {
|
|
211
|
+
const was = before;
|
|
212
|
+
if (!same(st.fragmentPath, was.fragmentPath) ||
|
|
213
|
+
st.dropInPaths.join("\n") !== was.dropInPaths.join("\n") ||
|
|
214
|
+
!same(st.workingDirectory, was.workingDirectory)) {
|
|
215
|
+
return (`systemd reports ${serving.unitName} from ${st.fragmentPath ?? "no file"}, drop-ins [${st.dropInPaths.join(", ")}], ` +
|
|
216
|
+
`WorkingDirectory ${st.workingDirectory ?? "(none)"}; before the write it was ${was.fragmentPath}, drop-ins [], ` +
|
|
217
|
+
`WorkingDirectory ${was.workingDirectory ?? "(none)"}`);
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
if (st.fragmentPath === null || !deps.repoint.samePath(st.fragmentPath, unitPath)) {
|
|
222
|
+
return `after the reload systemd loads ${serving.unitName} from ${st.fragmentPath ?? "no file"}, not ${unitPath}`;
|
|
223
|
+
}
|
|
224
|
+
if (st.dropInPaths.length > 0) {
|
|
225
|
+
return `after the reload systemd applies drop-ins to ${serving.unitName} (${st.dropInPaths.join(", ")})`;
|
|
226
|
+
}
|
|
227
|
+
if (st.workingDirectory === null || !deps.repoint.samePath(st.workingDirectory, targets.workingDirectory)) {
|
|
228
|
+
return `after the reload systemd reports WorkingDirectory ${st.workingDirectory ?? "(none)"}, not ${targets.workingDirectory}`;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* `flair restart` on Linux (see planLinuxRestart). A proven user unit is
|
|
236
|
+
* restarted THROUGH systemd and its new main process must run from the unit's
|
|
237
|
+
* WorkingDirectory; a process that is the main process (MainPID) of any other
|
|
238
|
+
* systemd unit is refused, never stopped and respawned outside its manager, and
|
|
239
|
+
* so is one whose cgroup or unit MainPID cannot be read. A process no unit
|
|
240
|
+
* supervises — none in its cgroup, or one whose MainPID is another process —
|
|
241
|
+
* takes the direct path.
|
|
242
|
+
*/
|
|
243
|
+
export async function restartOnLinux(d) {
|
|
244
|
+
const plan = planLinuxRestart({
|
|
245
|
+
serving: d.serving,
|
|
246
|
+
pids: d.pids,
|
|
247
|
+
procCgroup: d.procCgroup,
|
|
248
|
+
uid: d.uid,
|
|
249
|
+
unitMainPid: d.unitMainPid,
|
|
250
|
+
});
|
|
251
|
+
if (plan.kind === "refuse")
|
|
252
|
+
throw new Error(plan.detail);
|
|
253
|
+
if (plan.kind === "direct") {
|
|
254
|
+
await d.direct();
|
|
255
|
+
return "direct";
|
|
256
|
+
}
|
|
257
|
+
const s = d.serving;
|
|
258
|
+
d.beforeRestart?.(s);
|
|
259
|
+
d.log?.(` (restarting through the systemd user unit that runs this instance: ${plan.unit})`);
|
|
260
|
+
d.systemctl(["--user", "daemon-reload"]);
|
|
261
|
+
d.systemctl(["--user", "restart", plan.unit]);
|
|
262
|
+
await d.waitHealthy();
|
|
263
|
+
const problem = restartedUnitProblem(plan.unit, s.pid, d.unitState(plan.unit), d.cwdOf, d.samePath);
|
|
264
|
+
if (problem)
|
|
265
|
+
throw new Error(`restarted ${plan.unit} through systemd, but ${problem}`);
|
|
266
|
+
return "systemd";
|
|
267
|
+
}
|