mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 18:18:43 +00:00
fix(cliproxy): keep daemon running after parent exit
This commit is contained in:
@@ -76,7 +76,7 @@ async function waitForPort(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register cleanup handlers to stop proxy on process exit
|
* Register process-exit cleanup handlers for in-process workers.
|
||||||
*/
|
*/
|
||||||
function registerCleanup(): void {
|
function registerCleanup(): void {
|
||||||
if (cleanupRegistered) return;
|
if (cleanupRegistered) return;
|
||||||
@@ -87,11 +87,8 @@ function registerCleanup(): void {
|
|||||||
tokenRefreshWorker.stop();
|
tokenRefreshWorker.stop();
|
||||||
tokenRefreshWorker = null;
|
tokenRefreshWorker = null;
|
||||||
}
|
}
|
||||||
// Then stop proxy process
|
// Do not stop detached CLIProxy on parent exit.
|
||||||
if (proxyProcess && !proxyProcess.killed) {
|
// Persistence is expected across CCS command lifecycles.
|
||||||
proxyProcess.kill('SIGTERM');
|
|
||||||
proxyProcess = null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
process.once('exit', cleanup);
|
process.once('exit', cleanup);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import { initUI, header, color, dim, ok, warn, info } from '../../utils/ui';
|
import { initUI, header, color, dim, ok, warn, info } from '../../utils/ui';
|
||||||
import { getProxyStatus, stopProxy } from '../../cliproxy/services';
|
import { getProxyStatus, stopProxy } from '../../cliproxy/services';
|
||||||
|
import { detectRunningProxy } from '../../cliproxy/proxy-detector';
|
||||||
|
import { CLIPROXY_DEFAULT_PORT } from '../../cliproxy/config-generator';
|
||||||
|
|
||||||
export async function handleProxyStatus(): Promise<void> {
|
export async function handleProxyStatus(): Promise<void> {
|
||||||
await initUI();
|
await initUI();
|
||||||
@@ -26,9 +28,23 @@ export async function handleProxyStatus(): Promise<void> {
|
|||||||
console.log('');
|
console.log('');
|
||||||
console.log(dim('To stop: ccs cliproxy stop'));
|
console.log(dim('To stop: ccs cliproxy stop'));
|
||||||
} else {
|
} else {
|
||||||
console.log(` Status: ${color('Not running', 'warning')}`);
|
// Fallback: detect untracked/orphaned proxy process (e.g. detached session without lock file).
|
||||||
console.log('');
|
const detected = await detectRunningProxy();
|
||||||
console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.'));
|
if (detected.running && detected.verified) {
|
||||||
|
console.log(` Status: ${color('Running', 'success')}`);
|
||||||
|
console.log(` PID: ${detected.pid ?? 'unknown'}`);
|
||||||
|
console.log(` Port: ${CLIPROXY_DEFAULT_PORT}`);
|
||||||
|
console.log(` Sessions: ${detected.sessionCount || 0} active`);
|
||||||
|
if (!detected.sessionCount) {
|
||||||
|
console.log(dim(' Note: Detected running proxy without local session lock'));
|
||||||
|
}
|
||||||
|
console.log('');
|
||||||
|
console.log(dim('To stop: ccs cliproxy stop'));
|
||||||
|
} else {
|
||||||
|
console.log(` Status: ${color('Not running', 'warning')}`);
|
||||||
|
console.log('');
|
||||||
|
console.log(dim('CLIProxy starts automatically when you run ccs gemini, codex, etc.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log('');
|
console.log('');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user