@ours.network/install 1.2.1-nightly.52 → 1.2.1-nightly.53
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/assets/release.json +1 -1
- package/assets/sources.json +1 -1
- package/lib/orchestrate.mjs +117 -1
- package/package.json +1 -1
package/assets/release.json
CHANGED
package/assets/sources.json
CHANGED
package/lib/orchestrate.mjs
CHANGED
|
@@ -1069,6 +1069,116 @@ export async function runFleetManagedCliSetup(args, effects, plan, target) {
|
|
|
1069
1069
|
return { state: declared.every(role => good.includes(role.setup.state)) ? 'prepared' : 'attention', report };
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
+
export const FLEET_SERVICE_REFRESH_CAPABILITY = 'service.refresh-v1';
|
|
1073
|
+
|
|
1074
|
+
/** Order matters only for the supervisor: it stops and resumes agents, so it goes last. */
|
|
1075
|
+
const FLEET_RESTART_ORDER = ['web', 'watchdogs', 'supervisor'];
|
|
1076
|
+
const FLEET_RESTART_TIMEOUT_MS = 120_000;
|
|
1077
|
+
|
|
1078
|
+
/** Whether this installer runs inside `unit`'s cgroup, where restarting it would kill this run. */
|
|
1079
|
+
function insideUnit(effects, unit) {
|
|
1080
|
+
const cgroup = effects.readText('/proc/self/cgroup');
|
|
1081
|
+
return cgroup === null || cgroup.split('\n').some(line => line.split(':').slice(2).join(':').split('/').includes(unit));
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/** The platform's own restart command for a Fleet service definition. */
|
|
1085
|
+
function fleetRestartCommand(effects, service) {
|
|
1086
|
+
return effects.platform.platform === 'darwin'
|
|
1087
|
+
? `launchctl kickstart -k gui/$(id -u)/${basename(service.path, '.plist')}`
|
|
1088
|
+
: `systemctl --user try-restart ${basename(service.path)}`;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* An active Fleet service started from the replaced release keeps running it.
|
|
1093
|
+
* Restart each one that `service refresh` reports running a stale release once
|
|
1094
|
+
* its definition starts this release, then confirm with the read-only
|
|
1095
|
+
* `service check` that it now runs this release. The restart is systemd's
|
|
1096
|
+
* `try-restart`, which acts only on an active unit, so a service stopped at
|
|
1097
|
+
* any point is never started. A service whose definition still points
|
|
1098
|
+
* elsewhere, launchd, or the unit hosting this run is left alone with a notice
|
|
1099
|
+
* naming the manual restart; a running state Fleet cannot determine is never
|
|
1100
|
+
* restarted and is reported as unconfirmed.
|
|
1101
|
+
*/
|
|
1102
|
+
async function restartStaleFleetServices(effects, fleet, shown, env, services) {
|
|
1103
|
+
const attention = [];
|
|
1104
|
+
for (const service of services.filter(service => service.running === 'unknown' && (service.state === 'refreshed' || service.state === 'current'))) {
|
|
1105
|
+
attention.push(service.service);
|
|
1106
|
+
effects.out(warn(`Could not confirm which release the Fleet ${service.service} service is running; if it is running and was started before this update, restart it: ${fleetRestartCommand(effects, service)}${service.service === 'supervisor' ? ' (agents resume through their supervisor)' : ''}.`));
|
|
1107
|
+
}
|
|
1108
|
+
const stale = services.filter(service => service.running === 'stale')
|
|
1109
|
+
.sort((a, b) => FLEET_RESTART_ORDER.indexOf(a.service) - FLEET_RESTART_ORDER.indexOf(b.service));
|
|
1110
|
+
if (!stale.length) return attention;
|
|
1111
|
+
const linux = effects.platform.platform === 'linux';
|
|
1112
|
+
const restarted = [];
|
|
1113
|
+
for (const service of stale) {
|
|
1114
|
+
const unit = basename(service.path);
|
|
1115
|
+
const left = why => { attention.push(service.service); effects.out(warn(`Running Fleet ${service.service} service still uses the previous release: ${why}; when convenient: ${fleetRestartCommand(effects, service)}${service.service === 'supervisor' ? ' (agents resume through their supervisor)' : ''}.`)); };
|
|
1116
|
+
if (!linux) { left('this installer restarts Fleet services only under systemd'); continue; }
|
|
1117
|
+
if (service.state !== 'refreshed' && service.state !== 'current') { left('its definition does not start this release yet, so a restart would not help'); continue; }
|
|
1118
|
+
if (insideUnit(effects, unit)) { left('this installer runs inside it, so restarting it would stop this run'); continue; }
|
|
1119
|
+
try {
|
|
1120
|
+
// try-restart: a unit stopped since the report was taken stays stopped.
|
|
1121
|
+
await effects.run('systemctl', ['--user', 'try-restart', unit], { timeout: FLEET_RESTART_TIMEOUT_MS });
|
|
1122
|
+
restarted.push(service);
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
left(`restarting it failed (${installerFailure(error)})`);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (!restarted.length) return attention;
|
|
1128
|
+
let checked;
|
|
1129
|
+
try {
|
|
1130
|
+
const result = await effects.run(fleet, ['service', 'check', '--json'], { env, allowCodes: [1] });
|
|
1131
|
+
checked = JSON.parse(result.stdout ?? '').services;
|
|
1132
|
+
if (!Array.isArray(checked)) throw new Error('unrecognised report');
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
effects.out(warn(`Restarted Fleet ${restarted.map(service => service.service).join(', ')} service, but could not confirm which release it runs (${installerFailure(error)}); check: ${shown} service check`));
|
|
1135
|
+
return [...attention, ...restarted.map(service => service.service)];
|
|
1136
|
+
}
|
|
1137
|
+
for (const service of restarted) {
|
|
1138
|
+
const now = checked.find(entry => entry.service === service.service);
|
|
1139
|
+
if (now?.running === 'current') effects.out(ok(`Restarted Fleet ${service.service} service; it now runs this release${service.service === 'supervisor' ? ' and resumes its agents' : ''}.`));
|
|
1140
|
+
else {
|
|
1141
|
+
attention.push(service.service);
|
|
1142
|
+
effects.out(warn(now?.running === 'stopped'
|
|
1143
|
+
? `Fleet ${service.service} service is not running after the restart (it was stopped, or exited); this installer did not start it. Check: systemctl --user status ${basename(service.path)}`
|
|
1144
|
+
: `Restarted Fleet ${service.service} service, but it is not confirmed on this release (${now?.running ?? 'not reported'}); check: systemctl --user status ${basename(service.path)}`));
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return attention;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Fleet service definitions pin the release tree that wrote them, and an update
|
|
1152
|
+
* installs a new tree. Ask the installed Fleet to re-point its own existing
|
|
1153
|
+
* definitions (it never creates, starts, stops or restarts a service), then
|
|
1154
|
+
* restart only the services that were already running the replaced release.
|
|
1155
|
+
*/
|
|
1156
|
+
export async function runFleetServiceRefresh(args, effects, plan, target) {
|
|
1157
|
+
const fleet = args.acquiredFleet || plan.init[0];
|
|
1158
|
+
const env = target.mode === 'host-profile' ? profileEnv(target) : daemonEnv(target.stateDir, target.port);
|
|
1159
|
+
const capabilities = await effects.fleetCapabilities(fleet, env);
|
|
1160
|
+
if (!capabilities.includes(FLEET_SERVICE_REFRESH_CAPABILITY)) return { state: 'unavailable' };
|
|
1161
|
+
const shown = fleet === plan.init[0] ? fleet : shellQuote(fleet);
|
|
1162
|
+
const manual = `${shown} service refresh`;
|
|
1163
|
+
let services;
|
|
1164
|
+
try {
|
|
1165
|
+
const result = await effects.run(fleet, ['service', 'refresh', '--json'], { env });
|
|
1166
|
+
services = JSON.parse(result.stdout ?? '').services;
|
|
1167
|
+
if (!Array.isArray(services)) throw new Error('unrecognised report');
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
effects.out(warn(`Fleet service definitions were not refreshed (${installerFailure(error)}). After a reboot the previous Fleet release may start; retry: ${manual}`));
|
|
1170
|
+
return { state: 'failed' };
|
|
1171
|
+
}
|
|
1172
|
+
for (const service of services) {
|
|
1173
|
+
if (service.state === 'refreshed') effects.out(ok(`Fleet ${service.service} service now starts this release (${service.path}).`));
|
|
1174
|
+
if (service.state === 'unrecognized') effects.out(warn(`Fleet ${service.service} service definition was left unchanged: ${service.detail ?? 'not generated by Fleet'} (${service.path}).`));
|
|
1175
|
+
if (service.state === 'stale') effects.out(warn(`Fleet ${service.service} service still starts another release${service.detail ? `: ${service.detail}` : ''}; retry: ${manual}`));
|
|
1176
|
+
if (service.state === 'reload-failed') effects.out(warn(`Fleet ${service.service} service definition was updated, but the service manager did not reload it, so it still starts the previous release${service.detail ? ` (${service.detail})` : ''}; retry: systemctl --user daemon-reload`));
|
|
1177
|
+
}
|
|
1178
|
+
const unrestarted = await restartStaleFleetServices(effects, fleet, shown, env, services);
|
|
1179
|
+
return { state: unrestarted.length || services.some(service => service.state !== 'refreshed' && service.state !== 'current' && service.state !== 'absent') ? 'attention' : 'refreshed', services };
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1072
1182
|
/** Install Fleet and let its interactive wizard publish the owned configuration. */
|
|
1073
1183
|
export async function runFleetPhase(args, effects, { target, isDefaultStateDir }) {
|
|
1074
1184
|
effects.out(heading('ours-fleet (your always-online agent team)'));
|
|
@@ -1089,7 +1199,12 @@ export async function runFleetPhase(args, effects, { target, isDefaultStateDir }
|
|
|
1089
1199
|
if (!install.ok) return { key: 'fleet', label: plan.label, state: 'failed', note: 'Fleet installation failed' };
|
|
1090
1200
|
effects.out(ok('Fleet CLI installed; agent and model setup deferred to the App. Existing Fleet configuration was retained.'));
|
|
1091
1201
|
// A retained configuration may already declare the workflow; its generated policy names the package path this run just replaced.
|
|
1092
|
-
|
|
1202
|
+
// A retained configuration means Fleet was set up before, so its service
|
|
1203
|
+
// definitions may pin the release this run just replaced.
|
|
1204
|
+
if (!args.dryRun && effects.readText(plan.configPath) !== null) {
|
|
1205
|
+
await runFleetManagedCliSetup(args, effects, plan, target);
|
|
1206
|
+
await runFleetServiceRefresh(args, effects, plan, target);
|
|
1207
|
+
}
|
|
1093
1208
|
return { key: 'fleet', label: plan.label, state: 'installed', note: 'agents setup deferred' };
|
|
1094
1209
|
}
|
|
1095
1210
|
// Fleet owns its v2 manifest, roles, models and permissions. With no prepared
|
|
@@ -1116,6 +1231,7 @@ export async function runFleetPhase(args, effects, { target, isDefaultStateDir }
|
|
|
1116
1231
|
}
|
|
1117
1232
|
effects.out(ok('ours-fleet installed and initialized; no fleet roles were started.'));
|
|
1118
1233
|
if (!args.dryRun) await runFleetManagedCliSetup(args, effects, plan, target);
|
|
1234
|
+
if (!args.dryRun) await runFleetServiceRefresh(args, effects, plan, target);
|
|
1119
1235
|
if (plan.instruction) effects.out(info(plan.instruction));
|
|
1120
1236
|
return { key: 'fleet', label: plan.label, state: 'installed', note: `configured at ${plan.configPath}; stopped` };
|
|
1121
1237
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/install",
|
|
3
|
-
"version": "1.2.1-nightly.
|
|
3
|
+
"version": "1.2.1-nightly.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The all-in-one ours.network installer: one shared daemon, MCP, cowork, Telegram, Fleet initialization, harness plugins, Human identity, progress UI, and guided next steps.",
|
|
6
6
|
"type": "module",
|