diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 64a771a..a9429be 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { run } from "./utils"; +import { run, restartService } from "./utils"; import { showStatus } from "./utils/status"; import { executeCodeCommand, PresetConfig } from "./utils/codeCommand"; import { @@ -430,39 +430,7 @@ async function main() { console.log(`claude-code-router version: ${version}`); break; case "restart": - // Stop the service if it's running - try { - const pid = parseInt(readFileSync(PID_FILE, "utf-8")); - process.kill(pid); - cleanupPidFile(); - if (existsSync(REFERENCE_COUNT_FILE)) { - try { - fs.unlinkSync(REFERENCE_COUNT_FILE); - } catch (e) { - // Ignore cleanup errors - } - } - console.log("claude code router service has been stopped."); - } catch (e) { - console.log("Service was not running or failed to stop."); - cleanupPidFile(); - } - - // Start the service again in the background - console.log("Starting claude code router service..."); - const cliPath = join(__dirname, "cli.js"); - const startProcess = spawn("node", [cliPath, "start"], { - detached: true, - stdio: "ignore", - }); - - startProcess.on("error", (error) => { - console.error("Failed to start service:", error); - process.exit(1); - }); - - startProcess.unref(); - console.log("✅ Service started successfully in the background."); + await restartService(); break; case "-h": case "help": diff --git a/packages/cli/src/utils/index.ts b/packages/cli/src/utils/index.ts index 9a76d75..25e092e 100644 --- a/packages/cli/src/utils/index.ts +++ b/packages/cli/src/utils/index.ts @@ -238,7 +238,7 @@ export const restartService = async () => { // Start the service again in the background console.log("Starting claude code router service..."); - const cliPath = path.join(__dirname, "../cli.js"); + const cliPath = path.join(__dirname, "cli.js"); const startProcess = spawn("node", [cliPath, "start"], { detached: true, stdio: "ignore",