@nathanstephenson/flow 0.1.0 → 0.1.2
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 +10 -2
- package/dist/backend/fake/index.js +3 -1
- package/dist/backend/pi/effort-capabilities.js +12 -0
- package/dist/backend/pi/index.js +25 -36
- package/dist/backend/pi/workflow-subagent.js +8 -3
- package/dist/build-id +1 -1
- package/dist/cli/application.js +9 -1
- package/dist/cli/bootstrap.js +424 -37
- package/dist/cli/host-control.js +2 -2
- package/dist/cli/install-guard.js +57 -11
- package/dist/cli/systemd-update.js +129 -0
- package/dist/cli/update.js +64 -17
- package/dist/cli/web-update.js +376 -0
- package/dist/client/model-choices.js +22 -4
- package/dist/client/reduce.js +18 -6
- package/dist/client/status.js +34 -20
- package/dist/client/workflow-effort.js +30 -0
- package/dist/daemon/credential-redaction.js +97 -4
- package/dist/daemon/host-control-routes.js +18 -2
- package/dist/daemon/host.js +341 -74
- package/dist/daemon/release-checker.js +104 -0
- package/dist/daemon/runtime.js +12 -4
- package/dist/daemon/server.js +98 -15
- package/dist/daemon/summariser.js +81 -15
- package/dist/daemon/update-api.js +3 -0
- package/dist/daemon/workflow-executions.js +146 -15
- package/dist/protocol/update.js +1 -0
- package/dist/tui/app.js +104 -10
- package/dist/tui/keys.js +46 -10
- package/dist/tui/render.js +58 -13
- package/dist/workflows/records.js +3 -1
- package/dist/workflows/scheduler.js +15 -1
- package/package.json +1 -1
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/index-BlZBshi8.js +170 -0
- package/web/dist/assets/index-DWF4-3Fh.css +2 -0
- package/web/dist/assets/{settings-mcp-CcT0ADJR.js → settings-mcp-ZMIfuuZU.js} +1 -1
- package/web/dist/assets/{settings-secrets-CK4uF7fd.js → settings-secrets-CgTrBpi2.js} +1 -1
- package/web/dist/assets/settings-workflows-1DMYfZtn.js +23 -0
- package/web/dist/assets/{workflows-D4T4Gy_7.css → workflows-9aO6cptD.css} +1 -1
- package/web/dist/assets/workflows-CBuB_bva.js +7 -0
- package/web/dist/assets/workflows-pane-DPXGg0na.js +1 -0
- package/web/dist/favicon-16x16.png +0 -0
- package/web/dist/favicon-32x32.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +8 -3
- package/web/dist/safari-pinned-tab.svg +4 -0
- package/web/dist/assets/index-BC0gLS53.js +0 -106
- package/web/dist/assets/index-CCeZYKES.css +0 -2
- package/web/dist/assets/settings-workflows-CrbZF-nM.js +0 -23
- package/web/dist/assets/workflow-editors-naPqAmYO.js +0 -65
- package/web/dist/assets/workflows-hh6ioeEA.js +0 -7
- package/web/dist/assets/workflows-pane-Db-MHf7Z.js +0 -1
|
@@ -76,25 +76,68 @@ export function registryExists(slot) {
|
|
|
76
76
|
throw error;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
function updateIneligibility(slot, uid = process.getuid?.()) {
|
|
80
80
|
slot = resolve(slot);
|
|
81
81
|
const prefix = resolve(slot, '../../../..');
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
if (slot !== join(prefix, 'lib/node_modules', packageName))
|
|
83
|
+
return 'source';
|
|
84
|
+
if (uid === undefined || uid === 0)
|
|
85
|
+
return 'root';
|
|
85
86
|
for (const path of [prefix, join(prefix, 'lib'), join(prefix, 'lib/node_modules'), join(prefix, 'lib/node_modules/@nathanstephenson'), slot]) {
|
|
86
87
|
const stat = lstatSync(path);
|
|
87
|
-
if (stat.isSymbolicLink()
|
|
88
|
-
return
|
|
88
|
+
if (stat.isSymbolicLink())
|
|
89
|
+
return 'npm-link';
|
|
90
|
+
if (stat.uid !== uid)
|
|
91
|
+
return 'system';
|
|
92
|
+
if ((stat.mode & 0o022) !== 0)
|
|
93
|
+
return 'shared';
|
|
89
94
|
}
|
|
90
95
|
for (let path = dirname(prefix);; path = dirname(path)) {
|
|
91
96
|
const stat = lstatSync(path);
|
|
92
|
-
if (stat.isSymbolicLink()
|
|
93
|
-
return
|
|
97
|
+
if (stat.isSymbolicLink())
|
|
98
|
+
return 'npm-link';
|
|
99
|
+
if (stat.uid !== 0 && stat.uid !== uid)
|
|
100
|
+
return 'system';
|
|
101
|
+
if ((stat.mode & 0o022) !== 0 && (stat.mode & 0o1000) === 0)
|
|
102
|
+
return 'shared';
|
|
94
103
|
if (dirname(path) === path)
|
|
95
104
|
break;
|
|
96
105
|
}
|
|
97
|
-
return realpathSync(prefix) === prefix;
|
|
106
|
+
return realpathSync(prefix) === prefix ? undefined : 'npm-link';
|
|
107
|
+
}
|
|
108
|
+
function pathHasSymlink(path) {
|
|
109
|
+
for (let current = resolve(path);; current = dirname(current)) {
|
|
110
|
+
try {
|
|
111
|
+
if (lstatSync(current).isSymbolicLink())
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error.code !== 'ENOENT')
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
if (dirname(current) === current)
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export function updateUnsupportedReason(kind) {
|
|
123
|
+
return {
|
|
124
|
+
source: 'A source checkout cannot update itself. Install or update Flow through a private global npm prefix.',
|
|
125
|
+
'npm-link': 'An npm-linked Flow checkout cannot update itself. Remove the link and install Flow in a private global npm prefix.',
|
|
126
|
+
sea: 'Single-executable Flow builds cannot update themselves. Install the new binary manually.',
|
|
127
|
+
shared: 'A shared or group/other-writable global npm installation cannot update itself. Use a private, user-owned npm prefix without sudo.',
|
|
128
|
+
system: 'A system-owned or another user\'s global npm installation cannot update itself. Install Flow in your own private npm prefix without sudo.',
|
|
129
|
+
root: 'A root-owned or sudo-installed Flow cannot update itself. Install Flow as your normal user in a private npm prefix.',
|
|
130
|
+
}[kind];
|
|
131
|
+
}
|
|
132
|
+
/** Explain why this process cannot expose web self-update without mislabelling global installs as source. */
|
|
133
|
+
export function explainUnsupportedUpdate(slot, entry = process.argv[1], uid = process.getuid?.()) {
|
|
134
|
+
let kind = updateIneligibility(slot, uid) ?? 'source';
|
|
135
|
+
if (kind === 'source' && entry && pathHasSymlink(entry))
|
|
136
|
+
kind = 'npm-link';
|
|
137
|
+
return updateUnsupportedReason(kind);
|
|
138
|
+
}
|
|
139
|
+
export function updateEligible(slot) {
|
|
140
|
+
return updateIneligibility(slot) === undefined;
|
|
98
141
|
}
|
|
99
142
|
export function installation(slot) {
|
|
100
143
|
slot = resolve(slot);
|
|
@@ -217,7 +260,7 @@ export function installation(slot) {
|
|
|
217
260
|
} } };
|
|
218
261
|
});
|
|
219
262
|
}
|
|
220
|
-
async function beginUpdate(lease, previous, host) {
|
|
263
|
+
async function beginUpdate(lease, previous, host, systemdArgs) {
|
|
221
264
|
const barrier = { pid: process.pid, id: randomUUID(), phase: 'preparing', previous };
|
|
222
265
|
await locked(() => {
|
|
223
266
|
if (readBarrier(barrierPath))
|
|
@@ -225,7 +268,10 @@ export function installation(slot) {
|
|
|
225
268
|
const active = leases();
|
|
226
269
|
if (!active.some(other => other.id === lease.id && other.pid === process.pid && other.root === lease.root))
|
|
227
270
|
throw new Error('Update process has no installation lease');
|
|
228
|
-
|
|
271
|
+
const selected = host && active.find(other => other.pid === host.pid && other.root === lease.root);
|
|
272
|
+
if (systemdArgs && selected && JSON.stringify(selected.args) !== JSON.stringify(systemdArgs))
|
|
273
|
+
throw new Error('Configured systemd hostArgs do not match the running Session Host; correct systemd-update.json before updating');
|
|
274
|
+
if (active.some(other => other.id !== lease.id && !(host && other.pid === host.pid && other.root === lease.root && (systemdArgs ? JSON.stringify(other.args) === JSON.stringify(systemdArgs) : other.args.includes('--background-host')))))
|
|
229
275
|
throw new Error('Stop all other Flow hosts and CLI/TUI clients using this installation first');
|
|
230
276
|
if (host && !active.some(other => other.pid === host.pid && other.root === lease.root))
|
|
231
277
|
throw new Error('Stop all pre-guard Flow processes before updating');
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { getHostStatus, waitUntil } from "./host-control.js";
|
|
6
|
+
import { readHost } from "../daemon/ownership.js";
|
|
7
|
+
const exec = promisify(execFile);
|
|
8
|
+
export function parseSystemdUpdate(value) {
|
|
9
|
+
const c = value;
|
|
10
|
+
const unit = (v) => typeof v === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.-]*\.service$/.test(v);
|
|
11
|
+
if (!c || !['system', 'user'].includes(c.scope) || !unit(c.service) || !unit(c.updater) || c.service === c.updater ||
|
|
12
|
+
!Array.isArray(c.hostArgs) || c.hostArgs[0] !== 'serve' || c.hostArgs.some(a => typeof a !== 'string') || c.hostArgs.includes('--background-host') || c.hostArgs.includes('start')) {
|
|
13
|
+
throw new Error('Invalid systemd-update.json: use distinct fixed service units and foreground serve arguments');
|
|
14
|
+
}
|
|
15
|
+
return c;
|
|
16
|
+
}
|
|
17
|
+
export function systemdUpdate(root) {
|
|
18
|
+
try {
|
|
19
|
+
return parseSystemdUpdate(JSON.parse(readFileSync(join(root, 'systemd-update.json'), 'utf8')));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error.code === 'ENOENT')
|
|
23
|
+
return undefined;
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class SystemdCommandFailed extends Error {
|
|
28
|
+
completed;
|
|
29
|
+
constructor(error) {
|
|
30
|
+
super(String(error), { cause: error });
|
|
31
|
+
const command = error;
|
|
32
|
+
this.completed = typeof command.code === 'number' && !command.killed && !command.signal;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function systemctl(c, action, unit, extra = []) {
|
|
36
|
+
try {
|
|
37
|
+
const { stdout } = await exec('/usr/bin/systemctl', [`--${c.scope}`, '--no-ask-password', action, unit, ...extra], { timeout: 60000 });
|
|
38
|
+
return stdout.trim();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new SystemdCommandFailed(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Undo admission-only quiescence after a definite manager refusal, never an uncertain stop. */
|
|
45
|
+
export async function resumeSystemdAdmission(c, host) {
|
|
46
|
+
await assertSystemdOwner(c, c.service, host.pid);
|
|
47
|
+
if (await systemctl(c, 'show', c.service, ['--property=ActiveState', '--value']) !== 'active' ||
|
|
48
|
+
await systemctl(c, 'show', c.service, ['--property=Job', '--value']) !== '') {
|
|
49
|
+
throw new Error('The original systemd service is not active and job-free; admission cannot safely resume');
|
|
50
|
+
}
|
|
51
|
+
const response = await fetch(`${host.url}/api/host/stop`, {
|
|
52
|
+
method: 'POST', headers: { authorization: `Bearer ${host.token}`, 'content-type': 'application/json' },
|
|
53
|
+
body: JSON.stringify({ instanceId: host.instanceId, resume: true }), signal: AbortSignal.timeout(5000),
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
throw new Error(`Cannot resume Session Host admission: ${await response.text()}`);
|
|
57
|
+
}
|
|
58
|
+
export async function assertSystemdOwner(c, unit, pid) {
|
|
59
|
+
if (await systemctl(c, 'show', unit, ['--property=MainPID', '--value']) !== String(pid))
|
|
60
|
+
throw new Error(`systemd ${unit} does not own the expected process`);
|
|
61
|
+
}
|
|
62
|
+
export class SystemdLaunchUncertain extends Error {
|
|
63
|
+
}
|
|
64
|
+
const requestPath = (root) => join(root, 'systemd-update-request.json');
|
|
65
|
+
export async function launchSystemdUpdate(root, c, request) {
|
|
66
|
+
// A worker removes its request just before exiting. Starting an already-active oneshot is a
|
|
67
|
+
// no-op, so do not enqueue another request in that window (or while a unit is deactivating).
|
|
68
|
+
const state = await systemctl(c, 'show', c.updater, ['--property=ActiveState', '--value']);
|
|
69
|
+
if (!['inactive', 'failed'].includes(state))
|
|
70
|
+
throw new Error(`Systemd updater ${c.updater} is ${state || 'unknown'}; wait for it to stop before updating`);
|
|
71
|
+
// Exclusive durable request also serializes CLI and web launchers. Never overwrite an uncertain job.
|
|
72
|
+
writeFileSync(requestPath(root), JSON.stringify(request), { flag: 'wx', mode: 0o600 });
|
|
73
|
+
// --no-block: Type=oneshot must not wait for the update to finish (and kill this launcher).
|
|
74
|
+
// On an ambiguous systemctl failure retain the request for inspection, not automatic retry.
|
|
75
|
+
try {
|
|
76
|
+
await systemctl(c, 'start', c.updater, ['--no-block']);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new SystemdLaunchUncertain(`Could not confirm systemd update submission: ${String(error)}. Inspect ${c.updater} and ${requestPath(root)} before retrying; the request has been retained.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function readSystemdRequest(root) {
|
|
83
|
+
const r = JSON.parse(readFileSync(requestPath(root), 'utf8'));
|
|
84
|
+
if (!r || typeof r.force !== 'boolean' || (r.id !== undefined && !/^[a-f0-9-]{36}$/.test(r.id)) ||
|
|
85
|
+
(r.version !== undefined && (typeof r.version !== 'string' || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.test(r.version))) || ((r.id === undefined) !== (r.version === undefined)))
|
|
86
|
+
throw new Error('Invalid systemd update request');
|
|
87
|
+
return r;
|
|
88
|
+
}
|
|
89
|
+
export function clearSystemdRequest(root) { unlinkSync(requestPath(root)); }
|
|
90
|
+
export function systemdCapability(root) {
|
|
91
|
+
if (process.env.FLOW_SYSTEMD_HOST !== '1')
|
|
92
|
+
return undefined;
|
|
93
|
+
try {
|
|
94
|
+
return readFileSync(join(root, 'systemd-update-capability'), 'utf8');
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error.code === 'ENOENT')
|
|
98
|
+
return undefined;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function restoreSystemd(root, c, transaction, old, version) {
|
|
103
|
+
const env = await transaction.authorizeRestoration(c.hostArgs);
|
|
104
|
+
const path = join(root, 'systemd-update-capability');
|
|
105
|
+
writeFileSync(path, env.FLOW_UPDATE_CAPABILITY, { flag: 'wx', mode: 0o600 });
|
|
106
|
+
try {
|
|
107
|
+
await systemctl(c, 'start', c.service);
|
|
108
|
+
await waitUntil(async () => {
|
|
109
|
+
const host = readHost(root);
|
|
110
|
+
if (!host || host.instanceId === old.instanceId)
|
|
111
|
+
return false;
|
|
112
|
+
await assertSystemdOwner(c, c.service, host.pid);
|
|
113
|
+
const status = await getHostStatus(host);
|
|
114
|
+
if (status.version !== version || status.mode !== 'foreground' ||
|
|
115
|
+
['port', 'address', 'cwd', 'oidc'].some(k => status.settings[k] !== old.settings[k]))
|
|
116
|
+
throw new Error('Restored systemd Session Host settings or version differ');
|
|
117
|
+
return true;
|
|
118
|
+
}, 'systemd Session Host startup timed out');
|
|
119
|
+
await transaction.assertAuthorizationConsumed();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// Stop a failed restoration before rollback touches package files.
|
|
123
|
+
await systemctl(c, 'stop', c.service);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
unlinkSync(path);
|
|
128
|
+
}
|
|
129
|
+
}
|
package/dist/cli/update.js
CHANGED
|
@@ -5,7 +5,9 @@ import { packageName, privatePath } from "./install-guard.js";
|
|
|
5
5
|
import { readHost } from "../daemon/ownership.js";
|
|
6
6
|
import { backgroundHostArgs, getHostStatus, HostRefusal, launchBackground, processAlive, requestHostStop, requireRestartable, waitUntil } from "./host-control.js";
|
|
7
7
|
import { InstallationProcessUncertain, replacePackage } from "./install-process.js";
|
|
8
|
-
|
|
8
|
+
import { assertSystemdOwner, restoreSystemd, resumeSystemdAdmission, systemctl, SystemdCommandFailed } from "./systemd-update.js";
|
|
9
|
+
import { newerStableVersion } from "../daemon/release-checker.js";
|
|
10
|
+
export function npmExecutable() {
|
|
9
11
|
for (const directory of (process.env.PATH ?? '').split(delimiter)) {
|
|
10
12
|
const path = resolve(directory, 'npm');
|
|
11
13
|
try {
|
|
@@ -19,7 +21,7 @@ function npmExecutable() {
|
|
|
19
21
|
function npmPath(npm, command) {
|
|
20
22
|
return realpathSync(execFileSync(npm, [command, '--global'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 15000 }).trim());
|
|
21
23
|
}
|
|
22
|
-
function packageVersion(slot) {
|
|
24
|
+
export function packageVersion(slot) {
|
|
23
25
|
privatePath(slot);
|
|
24
26
|
const metadata = JSON.parse(readFileSync(join(slot, 'package.json'), 'utf8'));
|
|
25
27
|
if (metadata?.name !== packageName || typeof metadata.version !== 'string' || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(metadata.version))
|
|
@@ -39,36 +41,67 @@ async function verify(install, transaction, expected) {
|
|
|
39
41
|
await transaction.assertAuthorizationConsumed();
|
|
40
42
|
return version;
|
|
41
43
|
}
|
|
42
|
-
async function restore(install, transaction, root, host, version) {
|
|
43
|
-
const
|
|
44
|
+
async function restore(install, transaction, root, host, version, preserveConcretePort) {
|
|
45
|
+
const settings = preserveConcretePort && host.settings.port === 0
|
|
46
|
+
? { ...host.settings, port: Number(new URL(host.url).port) }
|
|
47
|
+
: host.settings;
|
|
48
|
+
const env = await transaction.authorizeRestoration(backgroundHostArgs(settings));
|
|
44
49
|
await launchBackground({
|
|
45
|
-
root, settings
|
|
50
|
+
root, settings, entry: [join(install.slot, 'dist/cli/bootstrap.js')], env,
|
|
46
51
|
validate(status) {
|
|
47
52
|
if (status.instanceId === host.instanceId || status.version !== version || status.mode !== 'background' ||
|
|
48
|
-
['port', 'address', 'cwd', 'oidc'].some(key => status.settings[key] !==
|
|
53
|
+
['port', 'address', 'cwd', 'oidc'].some(key => status.settings[key] !== settings[key])) {
|
|
49
54
|
throw new Error('Restored Session Host settings or version differ');
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
});
|
|
53
58
|
await transaction.assertAuthorizationConsumed();
|
|
54
59
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
throw new Error('usage: flow update [--force]');
|
|
60
|
+
/** Reused by the web surface for an explanation; `update` repeats it immediately before mutation. */
|
|
61
|
+
export function inspectUpdateInstallation(install) {
|
|
58
62
|
const npm = npmExecutable();
|
|
59
63
|
const prefix = npmPath(npm, 'prefix'), root = npmPath(npm, 'root');
|
|
60
64
|
if (prefix !== install.prefix || root !== join(prefix, 'lib/node_modules') || realpathSync(join(root, packageName)) !== install.slot)
|
|
61
65
|
throw new Error('npm selects a different installation. Put the matching npm in PATH and select its prefix.');
|
|
62
|
-
|
|
66
|
+
return { npm, version: packageVersion(install.slot) };
|
|
67
|
+
}
|
|
68
|
+
export async function update(install, lease, args, options = {}) {
|
|
69
|
+
if (args.length > 2 || args[0] !== 'update' || (args.length === 2 && args[1] !== '--force'))
|
|
70
|
+
throw new Error('usage: flow update [--force]');
|
|
71
|
+
const inspected = inspectUpdateInstallation(install);
|
|
72
|
+
const npm = inspected.npm;
|
|
73
|
+
const prefix = install.prefix;
|
|
74
|
+
const previous = inspected.version;
|
|
75
|
+
if (options.expectedVersion !== undefined && !newerStableVersion(previous, options.expectedVersion)) {
|
|
76
|
+
throw new Error(`The confirmed web update target ${options.expectedVersion} is not a newer stable release`);
|
|
77
|
+
}
|
|
78
|
+
const target = options.expectedVersion ?? 'latest';
|
|
79
|
+
const preserveConcretePort = options.preserveConcreteHostPort === true;
|
|
80
|
+
const managed = options.systemd;
|
|
81
|
+
if (managed)
|
|
82
|
+
await assertSystemdOwner(managed, managed.updater, process.pid);
|
|
63
83
|
let host = readHost(lease.root);
|
|
64
84
|
if (host && processAlive(host.pid)) {
|
|
65
85
|
const status = await getHostStatus(host);
|
|
66
|
-
|
|
86
|
+
if (managed) {
|
|
87
|
+
if (status.mode !== 'foreground')
|
|
88
|
+
throw new Error('systemd updates require a foreground Session Host');
|
|
89
|
+
if (preserveConcretePort && status.settings.port === 0)
|
|
90
|
+
throw new Error('Systemd web updates require a fixed service port for browser reconnection');
|
|
91
|
+
await assertSystemdOwner(managed, managed.service, host.pid);
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
requireRestartable(status);
|
|
67
95
|
host = { ...host, ...status };
|
|
68
96
|
}
|
|
69
97
|
else
|
|
70
98
|
host = undefined;
|
|
71
|
-
|
|
99
|
+
if (managed && !host)
|
|
100
|
+
throw new Error('Start the configured systemd Session Host before updating');
|
|
101
|
+
const transaction = await install.beginUpdate(lease, previous, host, managed?.hostArgs);
|
|
102
|
+
const restoreHost = (host, version) => managed
|
|
103
|
+
? restoreSystemd(lease.root, managed, transaction, host, version)
|
|
104
|
+
: restore(install, transaction, lease.root, host, version, preserveConcretePort);
|
|
72
105
|
let needsRestoration = false, replacing = false;
|
|
73
106
|
const repair = () => `Flow startup remains blocked by ${install.barrierPath}. Stop all Flow and npm processes for this prefix. Reinstall ${packageName}@${previous} with the matching npm and prefix ${JSON.stringify(prefix)}. Verify the package files manually, then remove ${install.barrierPath} and start the Session Host again.`;
|
|
74
107
|
async function replace(version, expected) {
|
|
@@ -77,7 +110,7 @@ export async function update(install, lease, args) {
|
|
|
77
110
|
await replacePackage(npm, prefix, `${packageName}@${version}`);
|
|
78
111
|
const installed = await verify(install, transaction, expected);
|
|
79
112
|
if (host && needsRestoration) {
|
|
80
|
-
await
|
|
113
|
+
await restoreHost(host, installed);
|
|
81
114
|
needsRestoration = false;
|
|
82
115
|
}
|
|
83
116
|
await transaction.complete();
|
|
@@ -87,7 +120,9 @@ export async function update(install, lease, args) {
|
|
|
87
120
|
if (host) {
|
|
88
121
|
needsRestoration = true;
|
|
89
122
|
try {
|
|
90
|
-
await requestHostStop(host, args.includes('--force'));
|
|
123
|
+
await requestHostStop(host, args.includes('--force'), !!managed);
|
|
124
|
+
if (managed)
|
|
125
|
+
await systemctl(managed, 'stop', managed.service);
|
|
91
126
|
}
|
|
92
127
|
catch (error) {
|
|
93
128
|
if (error instanceof HostRefusal)
|
|
@@ -97,18 +132,30 @@ export async function update(install, lease, args) {
|
|
|
97
132
|
const pid = host.pid;
|
|
98
133
|
await waitUntil(async () => !processAlive(pid), 'Session Host process did not exit; installation was not changed');
|
|
99
134
|
}
|
|
100
|
-
const version = await replace(
|
|
135
|
+
const version = await replace(target, options.expectedVersion);
|
|
101
136
|
console.log(version === previous ? `Flow is already at ${version}.` : `Flow updated: ${previous} → ${version}`);
|
|
137
|
+
return { previousVersion: previous, installedVersion: version, changed: version !== previous };
|
|
102
138
|
}
|
|
103
139
|
catch (error) {
|
|
104
140
|
if (error instanceof InstallationProcessUncertain)
|
|
105
141
|
throw new Error(`${String(error)}. ${repair()}`);
|
|
106
142
|
if (!replacing) {
|
|
107
|
-
if (needsRestoration && host && processAlive(host.pid))
|
|
143
|
+
if (needsRestoration && host && processAlive(host.pid)) {
|
|
144
|
+
if (managed && error instanceof SystemdCommandFailed && error.completed) {
|
|
145
|
+
try {
|
|
146
|
+
await resumeSystemdAdmission(managed, host);
|
|
147
|
+
}
|
|
148
|
+
catch (failure) {
|
|
149
|
+
throw new Error(`${String(error)}; could not resume admission: ${String(failure)}. No package files were changed. ${repair()}`);
|
|
150
|
+
}
|
|
151
|
+
await transaction.complete();
|
|
152
|
+
throw new Error(`${String(error)}. No package files were changed; the original Session Host is accepting requests again.`);
|
|
153
|
+
}
|
|
108
154
|
throw new Error(`${String(error)}. No package files were changed; wait for the stopping host to exit. ${repair()}`);
|
|
155
|
+
}
|
|
109
156
|
if (needsRestoration && host) {
|
|
110
157
|
try {
|
|
111
|
-
await
|
|
158
|
+
await restoreHost(host, previous);
|
|
112
159
|
}
|
|
113
160
|
catch (failure) {
|
|
114
161
|
throw new Error(`${String(error)}; restoration failed: ${String(failure)}. ${repair()}`);
|