fix: restart repeat provisions and record live controller

This commit is contained in:
冰朔 2026-08-05 11:43:06 +08:00
commit e99135dbb5
4 changed files with 66 additions and 4 deletions

View file

@ -157,7 +157,12 @@ async function provision(request, options = {}) {
else fs.writeFileSync(path.join(backupDir, `${checked.unit}.previously-absent`), "\n", { mode: 0o600 });
writeAtomic(installedUnit, unitText, 0o644);
await run("/usr/bin/systemctl", ["daemon-reload"]);
await run("/usr/bin/systemctl", ["enable", "--now", checked.unit]);
if (unitBackup) {
await run("/usr/bin/systemctl", ["enable", checked.unit]);
await run("/usr/bin/systemctl", ["restart", checked.unit]);
} else {
await run("/usr/bin/systemctl", ["enable", "--now", checked.unit]);
}
const runtime = await getJsonWithRetry(checked.runtimeCheck.url, options.getJson, options.healthAttempts, options.healthDelayMs);
for (const [key, expected] of Object.entries(checked.runtimeCheck.expected)) if (runtime[key] !== expected) throw new Error(`runtime_check_failed:${key}`);
const receipt = { schema: "guanghu.architecture-provision-receipt/v1", request_id: resource.requestId, source_commit: resource.commit, target_node: "JD-FD-PRIMARY", unit: checked.unit, runtime_check: checked.runtimeCheck.url, backup: path.join("backups", resource.requestId, resource.commit), rollback: unitBackup ? "restore-previous-unit" : "remove-new-unit", result: "DEPLOYED_AND_VERIFIED", recorded_at: new Date().toISOString() };

View file

@ -100,6 +100,16 @@ test("provision copies only declared files and verifies loopback health", async
assert.match(fs.readFileSync(path.join(unitDir, "example.service"), "utf8"), new RegExp(commit));
assert.equal(commands.some(([, args]) => args.includes("enable") && args.includes("--now")), true);
assert.equal(healthChecks, 2);
commands.length = 0;
const repeat = await provision({ target: "JD-FD-PRIMARY", action: "provision-approved-architecture", resource: `${requestId}@${commit}` }, {
repoDir, releasesDir, unitDir, receiptsDir,
run: async (file, args) => { commands.push([file, args]); return { stdout: args.includes("rev-parse") ? `${commit}\n` : "" }; },
getJson: async () => ({ ok: true, mode: "read-only" }),
healthDelayMs: 0,
});
assert.equal(repeat.ok, true);
assert.equal(commands.some(([, args]) => args[0] === "restart" && args[1] === "example.service"), true);
assert.equal(commands.some(([, args]) => args.includes("enable") && args.includes("--now")), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});