MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / installDaemon

Function installDaemon

packages/codex-native-api/src/daemon_manager.ts:548–575  ·  view source on GitHub ↗
(plan: CodexNativeApiDaemonInstallPlan)

Source from the content-addressed store, hash-verified

546}
547
548async function installDaemon(plan: CodexNativeApiDaemonInstallPlan): Promise<void> {
549 await ensureDaemonDirectories(plan.layout);
550 await fsp.writeFile(plan.layout.envFile, plan.serviceEnvFileContent, 'utf8');
551
552 switch (plan.layout.platform) {
553 case 'darwin':
554 await fsp.writeFile(plan.layout.launchdPlistPath!, plan.artifactContent ?? '', 'utf8');
555 await runCommand('launchctl', ['bootout', `gui/${process.getuid?.() ?? 0}`, plan.layout.launchdPlistPath!], { allowFailure: true });
556 await runCommand('launchctl', ['bootstrap', `gui/${process.getuid?.() ?? 0}`, plan.layout.launchdPlistPath!]);
557 await runCommand('launchctl', ['enable', `gui/${process.getuid?.() ?? 0}/${plan.layout.launchdLabel!}`]);
558 await runCommand('launchctl', ['kickstart', '-k', `gui/${process.getuid?.() ?? 0}/${plan.layout.launchdLabel!}`]);
559 return;
560 case 'linux':
561 await fsp.mkdir(path.dirname(plan.layout.systemdUnitPath!), { recursive: true });
562 await fsp.writeFile(plan.layout.systemdUnitPath!, plan.artifactContent ?? '', 'utf8');
563 await runCommand('systemctl', ['--user', 'daemon-reload']);
564 await runCommand('systemctl', ['--user', 'enable', '--now', plan.layout.systemdServiceName!]);
565 if (await commandExists('loginctl')) {
566 await runCommand('loginctl', ['enable-linger', resolveUserName(process.env)], { allowFailure: true });
567 }
568 return;
569 case 'win32':
570 await runPowerShellScript(buildWindowsInstallScript(plan));
571 return;
572 default:
573 throw new Error(`Unsupported daemon platform: ${plan.layout.platform}`);
574 }
575}
576
577async function startDaemon(): Promise<void> {
578 const layout = resolveDaemonLayout();

Callers 1

runDaemonCommandFunction · 0.85

Calls 6

ensureDaemonDirectoriesFunction · 0.85
runCommandFunction · 0.85
commandExistsFunction · 0.85
resolveUserNameFunction · 0.85
runPowerShellScriptFunction · 0.85

Tested by

no test coverage detected