@crvouga/homelab 0.23.6 → 0.23.7
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 +26 -26
- package/ansible/macos/legacy-monitoring.yml +22 -0
- package/ansible/macos/manager.yml +1 -0
- package/ansible/macos/policy.json +4 -0
- package/ansible/macos/tasks/legacy-agent.yml +28 -3
- package/ansible/ubuntu/disk-gc.py +60 -10
- package/ansible/ubuntu/policy.json +40 -16
- package/ansible/ubuntu/pressure-guard.py +2 -5
- package/ansible/ubuntu/tasks/recovery.yml +4 -0
- package/ansible/ubuntu/tasks/resources.yml +38 -8
- package/cliproxy/docs/backup.md +15 -0
- package/cliproxy/scripts/backup +218 -182
- package/cliproxy/scripts/cli.py +1 -1
- package/cliproxy/scripts/retention.py +16 -12
- package/docs/convergence.md +3 -0
- package/docs/manager-recovery.md +7 -0
- package/docs/runbooks.md +14 -3
- package/docs/ubuntu-sync.md +27 -5
- package/mise.lock +82 -138
- package/mise.toml +16 -16
- package/package.json +4 -3
- package/src/cli/fleet-sync.ts +23 -4
- package/src/cli/legacy-monitoring.ts +41 -0
- package/src/cli/register-fleet.ts +1 -1
- package/src/manager-health.ts +1 -1
- package/src/node-converge-linux.ts +2 -17
- package/src/platform/resource-verify.ts +84 -12
- package/src/platform/ubuntu-baseline.ts +47 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { PACKAGE_ROOT } from '../package-info';
|
|
3
|
+
import { runAnsible } from '../platform/ansible';
|
|
4
|
+
import type { Runner } from '../types';
|
|
5
|
+
import type { CommandOutcome } from './contracts';
|
|
6
|
+
|
|
7
|
+
/** A local migration with no enrollment, tool upgrade or service restart. */
|
|
8
|
+
export async function retireLegacyMonitoring(
|
|
9
|
+
options: { dryRun?: boolean },
|
|
10
|
+
run: Runner
|
|
11
|
+
): Promise<CommandOutcome> {
|
|
12
|
+
const result = await runAnsible(
|
|
13
|
+
run,
|
|
14
|
+
join(PACKAGE_ROOT, 'ansible/macos/legacy-monitoring.yml'),
|
|
15
|
+
{
|
|
16
|
+
input: '{}',
|
|
17
|
+
check: options.dryRun === true,
|
|
18
|
+
timeoutMs: 60_000,
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const summary = result.ok
|
|
22
|
+
? options.dryRun
|
|
23
|
+
? 'Legacy monitoring retirement preview passed; no jobs changed.'
|
|
24
|
+
: 'Legacy monitoring retired; the replacement kept its running process.'
|
|
25
|
+
: 'Legacy monitoring retirement refused or failed. Inspect the migration playbook in check mode; the replacement must be running.';
|
|
26
|
+
return {
|
|
27
|
+
exitCode: result.ok ? 0 : 1,
|
|
28
|
+
data: {
|
|
29
|
+
version: 1,
|
|
30
|
+
ok: result.ok,
|
|
31
|
+
checks: [
|
|
32
|
+
{
|
|
33
|
+
id: 'manager:playbook',
|
|
34
|
+
status: result.ok ? 'pass' : 'fail',
|
|
35
|
+
summary,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
text: summary,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -284,7 +284,7 @@ function registerSync({ program, defaults, complete }: Registration) {
|
|
|
284
284
|
)
|
|
285
285
|
.option(
|
|
286
286
|
'--only <scope>',
|
|
287
|
-
'accounts:
|
|
287
|
+
'accounts: account configuration on every node; legacy-monitoring: retire only the replaced manager monitoring job (supports --dry-run)'
|
|
288
288
|
)
|
|
289
289
|
.action(async (_options, command: Command) => {
|
|
290
290
|
const options = command.optsWithGlobals<
|
package/src/manager-health.ts
CHANGED
|
@@ -494,7 +494,7 @@ export async function managerLegacyAgents(
|
|
|
494
494
|
summary: `MANAGER_LEGACY_AGENTS_REMAIN ${remaining.join(', ')}`,
|
|
495
495
|
remedy: {
|
|
496
496
|
action:
|
|
497
|
-
'Run converge to
|
|
497
|
+
'Run converge to retire replaced LaunchAgents. For monitoring only, preview with homelab converge --only legacy-monitoring --dry-run, then omit --dry-run; the replacement must remain running.',
|
|
498
498
|
},
|
|
499
499
|
}
|
|
500
500
|
: {
|
|
@@ -6,6 +6,7 @@ import ubuntuPolicy from '../ansible/ubuntu/policy.json';
|
|
|
6
6
|
import { workerReadiness } from './worker-readiness';
|
|
7
7
|
import { runAnsible } from './platform/ansible';
|
|
8
8
|
import { runAnsibleWithReceipt } from './platform/ansible-receipt';
|
|
9
|
+
import { ubuntuBaseline } from './platform/ubuntu-baseline';
|
|
9
10
|
import {
|
|
10
11
|
loadedT3Policy,
|
|
11
12
|
stageT3Policy,
|
|
@@ -247,12 +248,11 @@ async function applyBaseline(
|
|
|
247
248
|
const user = userInfo();
|
|
248
249
|
const features = workerFeatures(fleet, node);
|
|
249
250
|
const ubuntu = resolve(root, 'ansible/ubuntu');
|
|
250
|
-
|
|
251
|
+
return ubuntuBaseline(
|
|
251
252
|
run,
|
|
252
253
|
resolve(ubuntu, 'baseline.yml'),
|
|
253
254
|
{
|
|
254
255
|
cwd: ubuntu,
|
|
255
|
-
timeoutMs: 900_000,
|
|
256
256
|
input: JSON.stringify({
|
|
257
257
|
development_source: stablePath(root),
|
|
258
258
|
development_user: user.username,
|
|
@@ -285,21 +285,6 @@ async function applyBaseline(
|
|
|
285
285
|
),
|
|
286
286
|
}
|
|
287
287
|
);
|
|
288
|
-
return {
|
|
289
|
-
cached: result.cached,
|
|
290
|
-
checks: [
|
|
291
|
-
{
|
|
292
|
-
id: 'ubuntu:baseline',
|
|
293
|
-
status: result.ok ? 'pass' : 'fail',
|
|
294
|
-
summary: result.ok
|
|
295
|
-
? result.cached
|
|
296
|
-
? 'Ubuntu baseline unchanged since its last successful apply and its services are active (re-applied in full at least daily).'
|
|
297
|
-
: 'Ubuntu baseline tasks completed, including always-on service recovery; effective boot/session policies require separate verification.'
|
|
298
|
-
: 'UBUNTU_BASELINE_INCOMPLETE',
|
|
299
|
-
...(result.ok && result.cached ? { reused: 'receipt' as const } : {}),
|
|
300
|
-
},
|
|
301
|
-
],
|
|
302
|
-
};
|
|
303
288
|
}
|
|
304
289
|
|
|
305
290
|
/** Cheap probe for what the baseline owns: system services and user timers. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import policy from '../../ansible/ubuntu/policy.json';
|
|
2
|
+
import { userInfo } from 'node:os';
|
|
2
3
|
import { threshold } from '../worker-sizing';
|
|
3
4
|
import { diskGcReportCheck, readDiskGcReport } from '../disk-gc-report';
|
|
4
5
|
import type { Check, Runner } from '../types';
|
|
@@ -11,6 +12,8 @@ const GUARDS = {
|
|
|
11
12
|
'personal-fleet-disk-guard.service': 'DISK_GUARD_INACTIVE',
|
|
12
13
|
'personal-fleet-disk-gc.timer': 'DISK_GC_TIMER_MISSING',
|
|
13
14
|
};
|
|
15
|
+
const PRESSURE_POLICY_REMEDY =
|
|
16
|
+
'Run homelab converge to restore pressure policy for the worker user service and agent slices. The policy reload applies to active agents. Inspect user.control or system.control overrides if pressure killing remains enabled; retrying an agent does not repair the policy.';
|
|
14
17
|
const MIB = 1024 * 1024;
|
|
15
18
|
|
|
16
19
|
/** A failure code and remedy, or undefined when the probe passes. */
|
|
@@ -77,23 +80,52 @@ const diskGcRecent: Probe = async (run) => {
|
|
|
77
80
|
'DISK_GC_RUN_STALE',
|
|
78
81
|
'Inspect the disk GC service journal and run converge for this worker.',
|
|
79
82
|
];
|
|
83
|
+
const budget = await run([
|
|
84
|
+
'systemctl',
|
|
85
|
+
'show',
|
|
86
|
+
'--property=MemoryMax',
|
|
87
|
+
'--',
|
|
88
|
+
'personal-fleet-disk-gc.service',
|
|
89
|
+
]);
|
|
90
|
+
if (
|
|
91
|
+
!budget.ok ||
|
|
92
|
+
budget.stdout.trim() !==
|
|
93
|
+
`MemoryMax=${policy.resourceSafety.diskGcMemoryMaxMiB * MIB}`
|
|
94
|
+
)
|
|
95
|
+
return [
|
|
96
|
+
'DISK_GC_MEMORY_POLICY_STALE',
|
|
97
|
+
'Run homelab converge to restore the bounded Git maintenance memory budget. Inspect service drop-ins if the effective limit still differs.',
|
|
98
|
+
];
|
|
80
99
|
return undefined;
|
|
81
100
|
};
|
|
82
101
|
|
|
83
102
|
const memoryReserved: Probe = async (run) => {
|
|
84
103
|
const show = (property: string, unit: string) =>
|
|
85
104
|
run(['systemctl', 'show', `--property=${property}`, '--', unit]);
|
|
86
|
-
const user = await
|
|
87
|
-
|
|
105
|
+
const [user, root, service, memory] = await Promise.all([
|
|
106
|
+
show('MemoryMax', 'user.slice'),
|
|
107
|
+
show('ManagedOOMSwap', '-.slice'),
|
|
108
|
+
show('ManagedOOMMemoryPressure', `user@${userInfo().uid}.service`),
|
|
109
|
+
run(['cat', '/proc/meminfo']),
|
|
110
|
+
]);
|
|
111
|
+
const limit = Number(/^MemoryMax=(\d+)$/m.exec(user.stdout)?.[1]);
|
|
112
|
+
const physical =
|
|
113
|
+
Number(/^MemTotal:\s+(\d+) kB$/m.exec(memory.stdout)?.[1]) * 1024;
|
|
88
114
|
const ok =
|
|
89
|
-
|
|
115
|
+
user.ok &&
|
|
116
|
+
root.ok &&
|
|
117
|
+
memory.ok &&
|
|
118
|
+
limit > 0 &&
|
|
119
|
+
limit < physical &&
|
|
90
120
|
/^ManagedOOMSwap=kill$/m.test(root.stdout);
|
|
91
|
-
|
|
121
|
+
if (!ok)
|
|
122
|
+
return [
|
|
123
|
+
'MEMORY_RESERVE_MISSING',
|
|
124
|
+
'User workloads are not capped below physical memory, or swap exhaustion is unmanaged. Reapply converge.',
|
|
125
|
+
];
|
|
126
|
+
return service.ok && /^ManagedOOMMemoryPressure=auto$/m.test(service.stdout)
|
|
92
127
|
? undefined
|
|
93
|
-
: [
|
|
94
|
-
'MEMORY_RESERVE_MISSING',
|
|
95
|
-
'User workloads are not capped below physical memory, or swap exhaustion is unmanaged. Reapply converge.',
|
|
96
|
-
];
|
|
128
|
+
: ['AGENT_PRESSURE_KILL_ENABLED', PRESSURE_POLICY_REMEDY];
|
|
97
129
|
};
|
|
98
130
|
|
|
99
131
|
const agentsBounded: Probe = async (run) =>
|
|
@@ -111,7 +143,7 @@ const agentSliceBounded: Probe = async (run) => {
|
|
|
111
143
|
'--user',
|
|
112
144
|
'show',
|
|
113
145
|
'app-t3code-agents.slice',
|
|
114
|
-
'--property=LoadState,MemoryHigh,MemoryMax,MemorySwapMax,TasksMax,CPUWeight,IOWeight',
|
|
146
|
+
'--property=LoadState,MemoryHigh,MemoryMax,MemorySwapMax,TasksMax,CPUWeight,IOWeight,ManagedOOMMemoryPressure',
|
|
115
147
|
]),
|
|
116
148
|
run(['cat', '/proc/meminfo']),
|
|
117
149
|
]);
|
|
@@ -126,6 +158,24 @@ const agentSliceBounded: Probe = async (run) => {
|
|
|
126
158
|
'AGENT_SLICE_MISSING',
|
|
127
159
|
'Run converge and verify T3 uses app-t3code-agents.slice.',
|
|
128
160
|
];
|
|
161
|
+
const threads = await run([
|
|
162
|
+
'systemctl',
|
|
163
|
+
'--user',
|
|
164
|
+
'show',
|
|
165
|
+
'app-t3code-agents-*.slice',
|
|
166
|
+
'--property=ManagedOOMMemoryPressure',
|
|
167
|
+
'--value',
|
|
168
|
+
]);
|
|
169
|
+
if (
|
|
170
|
+
fields['ManagedOOMMemoryPressure'] !== 'auto' ||
|
|
171
|
+
!threads.ok ||
|
|
172
|
+
threads.stdout
|
|
173
|
+
.trim()
|
|
174
|
+
.split(/\s+/)
|
|
175
|
+
.filter(Boolean)
|
|
176
|
+
.some((mode) => mode !== 'auto')
|
|
177
|
+
)
|
|
178
|
+
return ['AGENT_PRESSURE_KILL_ENABLED', PRESSURE_POLICY_REMEDY];
|
|
129
179
|
const mib = Math.floor(
|
|
130
180
|
Number(/^MemTotal:\s+(\d+) kB$/m.exec(memory.stdout)?.[1]) / 1024
|
|
131
181
|
);
|
|
@@ -416,6 +466,25 @@ export function protectionWaitsForReboot(check: Check): boolean {
|
|
|
416
466
|
return check.id === 'worker:t3-protection' && check.status === 'warn';
|
|
417
467
|
}
|
|
418
468
|
|
|
469
|
+
async function oomdAgentKills(run: Runner): Promise<number | undefined> {
|
|
470
|
+
const oomd = await run([
|
|
471
|
+
'sudo',
|
|
472
|
+
'-n',
|
|
473
|
+
'journalctl',
|
|
474
|
+
'--quiet',
|
|
475
|
+
'--unit=systemd-oomd.service',
|
|
476
|
+
'--since=24 hours ago',
|
|
477
|
+
'--output=cat',
|
|
478
|
+
'--grep=Killed ',
|
|
479
|
+
]);
|
|
480
|
+
const oomdReadable =
|
|
481
|
+
oomd.ok || (oomd.reason === 'exit' && !oomd.stderr.trim());
|
|
482
|
+
const oomdKills = oomd.stdout
|
|
483
|
+
.split('\n')
|
|
484
|
+
.filter((line) => /Killed .*app-t3code-agents(?:[/.-])/.test(line)).length;
|
|
485
|
+
return oomdReadable ? oomdKills : undefined;
|
|
486
|
+
}
|
|
487
|
+
|
|
419
488
|
export async function pressureEvents(run: Runner): Promise<Check> {
|
|
420
489
|
const id = 'worker:pressure-events';
|
|
421
490
|
const events = await run([
|
|
@@ -436,6 +505,7 @@ export async function pressureEvents(run: Runner): Promise<Check> {
|
|
|
436
505
|
status: 'warn',
|
|
437
506
|
summary: 'Recent pressure guard activity could not be read.',
|
|
438
507
|
};
|
|
508
|
+
const oomdKills = await oomdAgentKills(run);
|
|
439
509
|
const { stops, dryRuns, unclassified } = pressureCounts(events.stdout);
|
|
440
510
|
const count = stops.cpu + stops.io + stops.memory + stops.unknown;
|
|
441
511
|
const active = await run([
|
|
@@ -443,19 +513,21 @@ export async function pressureEvents(run: Runner): Promise<Check> {
|
|
|
443
513
|
'-e',
|
|
444
514
|
'/run/personal-fleet-pressure-guard/active',
|
|
445
515
|
]);
|
|
446
|
-
const warn = Boolean(
|
|
516
|
+
const warn = Boolean(
|
|
517
|
+
count || unclassified || active.ok || oomdKills || oomdKills === undefined
|
|
518
|
+
);
|
|
447
519
|
const pressure = active.ok
|
|
448
520
|
? 'The guard currently reports sustained pressure.'
|
|
449
521
|
: 'The sustained-pressure marker is absent.';
|
|
450
522
|
return {
|
|
451
523
|
id,
|
|
452
524
|
status: warn ? 'warn' : 'pass',
|
|
453
|
-
summary: `In the last 24 hours the pressure guard stopped ${count} workloads (CPU: ${stops.cpu}, I/O: ${stops.io}, memory: ${stops.memory}, unknown cause: ${stops.unknown}). Dry runs: ${dryRuns}. Unclassified historical records: ${unclassified}. ${pressure}
|
|
525
|
+
summary: `In the last 24 hours the pressure guard stopped ${count} workloads (CPU: ${stops.cpu}, I/O: ${stops.io}, memory: ${stops.memory}, unknown cause: ${stops.unknown}). Dry runs: ${dryRuns}. Unclassified historical records: ${unclassified}. ${pressure} systemd-oomd agent kills: ${oomdKills ?? 'unavailable'}.`,
|
|
454
526
|
...(warn
|
|
455
527
|
? {
|
|
456
528
|
remedy: {
|
|
457
529
|
action:
|
|
458
|
-
'Inspect current CPU, I/O and memory stalls before changing capacity. The counts describe past interventions.',
|
|
530
|
+
'Inspect current CPU, I/O and memory stalls before changing capacity. The counts describe past interventions. For systemd-oomd kills, run homelab converge to migrate the slice policy, then inspect the systemd-oomd journal for ancestor or swap-exhaustion kills before retrying a session.',
|
|
459
531
|
command:
|
|
460
532
|
'cat /proc/pressure/cpu /proc/pressure/io /proc/pressure/memory',
|
|
461
533
|
},
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Check, CommandOptions, Runner } from '../types';
|
|
2
|
+
import { runAnsibleWithReceipt, type Receipt } from './ansible-receipt';
|
|
3
|
+
|
|
4
|
+
/** Cold snapshot indexes and packages can exceed fifteen minutes. Keep the
|
|
5
|
+
* installation bounded without cutting it off at the old cold-start deadline.
|
|
6
|
+
* Other playbooks retain their own budgets.
|
|
7
|
+
*/
|
|
8
|
+
export async function ubuntuBaseline(
|
|
9
|
+
run: Runner,
|
|
10
|
+
playbook: string,
|
|
11
|
+
options: CommandOptions & { input: string },
|
|
12
|
+
receipt: Receipt
|
|
13
|
+
): Promise<{ cached: boolean; checks: Check[] }> {
|
|
14
|
+
const result = await runAnsibleWithReceipt(
|
|
15
|
+
run,
|
|
16
|
+
playbook,
|
|
17
|
+
{ ...options, timeoutMs: 30 * 60_000 },
|
|
18
|
+
receipt
|
|
19
|
+
);
|
|
20
|
+
const summary = result.ok
|
|
21
|
+
? result.cached
|
|
22
|
+
? 'Ubuntu baseline unchanged since its last successful apply and its services are active (re-applied in full at least daily).'
|
|
23
|
+
: 'Ubuntu baseline tasks completed, including always-on service recovery; effective boot/session policies require separate verification.'
|
|
24
|
+
: result.reason === 'timeout'
|
|
25
|
+
? 'UBUNTU_BASELINE_TIMEOUT'
|
|
26
|
+
: 'UBUNTU_BASELINE_INCOMPLETE';
|
|
27
|
+
return {
|
|
28
|
+
cached: result.cached,
|
|
29
|
+
checks: [
|
|
30
|
+
{
|
|
31
|
+
id: 'ubuntu:baseline',
|
|
32
|
+
status: result.ok ? 'pass' : 'fail',
|
|
33
|
+
summary,
|
|
34
|
+
...(result.ok && result.cached ? { reused: 'receipt' as const } : {}),
|
|
35
|
+
...(result.reason === 'timeout'
|
|
36
|
+
? {
|
|
37
|
+
remedy: {
|
|
38
|
+
action:
|
|
39
|
+
'The Ubuntu baseline reached its bounded installation deadline. Check snapshot connectivity and package-manager activity, then run homelab converge.',
|
|
40
|
+
command: 'homelab converge',
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
: {}),
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|