MCPcopy Create free account
hub / github.com/EvoMap/evolver / start

Function start

src/ops/lifecycle.js:573–615  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

571// --- Lifecycle ---
572
573function start(options) {
574 var delayMs = (options && options.delayMs) || 0;
575 var pids = getRunningPids();
576 var ownedPids = getOwnedLoopPids(pids);
577 if (ownedPids.length > 0) {
578 if (shouldRestartForProxy(ownedPids, process.env)) {
579 console.log('[Lifecycle] Loop running but proxy is unhealthy; restarting.');
580 stopPids(ownedPids, { unlinkPidFile: true, unlinkLock: true });
581 ownedPids = getOwnedLoopPids(getRunningPids());
582 }
583 }
584 if (ownedPids.length > 0) {
585 console.log('[Lifecycle] Already running (PIDs: ' + ownedPids.join(', ') + ').');
586 return { status: 'already_running', pids: ownedPids };
587 }
588 if (delayMs > 0) {
589 sleepMs(delayMs);
590 }
591
592 var script = getLoopScript();
593 console.log('[Lifecycle] Starting: node ' + path.relative(WORKSPACE_ROOT, script) + ' --loop');
594
595 var out = fs.openSync(LOG_FILE, 'a');
596 var err = fs.openSync(LOG_FILE, 'a');
597
598 var env = prepareStartEnv(process.env);
599 // .npm-global/bin is a Unix-only convention; skip the PATH injection on Windows
600 // to avoid polluting the environment with a path that does not exist.
601 if (process.platform !== 'win32') {
602 var npmGlobal = path.join(os.homedir(), '.npm-global', 'bin');
603 if (env.PATH && !env.PATH.includes(npmGlobal)) {
604 env.PATH = npmGlobal + ':' + env.PATH;
605 }
606 }
607
608 var child = spawn(process.execPath, [script, '--loop'], {
609 detached: true, stdio: ['ignore', out, err], cwd: WORKSPACE_ROOT, env: env, windowsHide: true
610 });
611 child.unref();
612 fs.writeFileSync(PID_FILE, String(child.pid));
613 console.log('[Lifecycle] Started PID ' + child.pid);
614 return { status: 'started', pid: child.pid };
615}
616
617function stop() {
618 var pids = getRunningPids();

Callers 2

restartFunction · 0.70
lifecycle.jsFile · 0.70

Calls 7

getRunningPidsFunction · 0.85
getOwnedLoopPidsFunction · 0.85
shouldRestartForProxyFunction · 0.85
stopPidsFunction · 0.85
getLoopScriptFunction · 0.85
prepareStartEnvFunction · 0.85
sleepMsFunction · 0.70

Tested by

no test coverage detected