shennian 0.2.83 → 0.2.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -51,6 +51,7 @@ export declare function clearDaemonPidIfOwner(pid: number, instanceId: string):
|
|
|
51
51
|
export declare function writeDaemonLauncher(pid: number, launcher?: DaemonLauncher, instanceId?: string): void;
|
|
52
52
|
export declare function clearDaemonLauncher(instanceId?: string): void;
|
|
53
53
|
export declare function recordStartedDaemon(childPid: number | undefined): void;
|
|
54
|
+
export declare function isShennianRunServiceCommand(command: string): boolean;
|
|
54
55
|
export declare function findRunningDaemonProcessIds(excludePid?: number): number[];
|
|
55
56
|
export declare function getDaemonStatus(opts?: {
|
|
56
57
|
cleanupStale?: boolean;
|
|
@@ -248,13 +248,11 @@ function inferDaemonLauncherFromProcess(pid) {
|
|
|
248
248
|
}
|
|
249
249
|
return 'unknown';
|
|
250
250
|
}
|
|
251
|
-
function isShennianRunServiceCommand(command) {
|
|
252
|
-
const normalized = command.replace(/\\/g, '/');
|
|
253
|
-
return (
|
|
254
|
-
(
|
|
255
|
-
|
|
256
|
-
normalized.includes(' shennian run-service') ||
|
|
257
|
-
normalized.includes(' shennian.js run-service')));
|
|
251
|
+
export function isShennianRunServiceCommand(command) {
|
|
252
|
+
const normalized = command.replace(/\\/g, '/').trim();
|
|
253
|
+
return (/^(?:\S*\/)?node\s+\S*(?:\/node_modules\/shennian\/|\/dist\/bin\/shennian\.js)\s+run-service(?:\s|$)/.test(normalized) ||
|
|
254
|
+
/^(?:\S*\/)?shennian(?:\.cmd)?\s+run-service(?:\s|$)/.test(normalized) ||
|
|
255
|
+
/^(?:\S*\/)?npx(?:\.cmd)?\s+(?:--yes\s+)?shennian\s+run-service(?:\s|$)/.test(normalized));
|
|
258
256
|
}
|
|
259
257
|
export function findRunningDaemonProcessIds(excludePid = process.pid) {
|
|
260
258
|
if (getPlatform() === 'win32')
|
|
@@ -569,21 +567,7 @@ export function startDaemonProcess(opts = {}) {
|
|
|
569
567
|
}
|
|
570
568
|
return;
|
|
571
569
|
}
|
|
572
|
-
|
|
573
|
-
try {
|
|
574
|
-
process.kill(status.pid, 'SIGTERM');
|
|
575
|
-
waitForPidExitSync(status.pid);
|
|
576
|
-
try {
|
|
577
|
-
fs.unlinkSync(PID_FILE);
|
|
578
|
-
}
|
|
579
|
-
catch {
|
|
580
|
-
// The adopted daemon may have cleaned up or another start may have taken over.
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
catch {
|
|
584
|
-
// The adopted orphan may already have exited; continue with a clean start.
|
|
585
|
-
}
|
|
586
|
-
}
|
|
570
|
+
stopAdoptedDaemonForStart(status);
|
|
587
571
|
const logFd = fs.openSync(LOG_FILE, 'a');
|
|
588
572
|
const launch = buildDetachedLaunchSpec(resolveCurrentServiceLaunchSpec());
|
|
589
573
|
const child = spawn(launch.command, launch.args, buildDaemonSpawnOptions(launch, logFd));
|
|
@@ -595,6 +579,23 @@ export function startDaemonProcess(opts = {}) {
|
|
|
595
579
|
console.log(chalk.gray(` Logs: ${LOG_FILE}`));
|
|
596
580
|
}
|
|
597
581
|
}
|
|
582
|
+
function stopAdoptedDaemonForStart(status = getDaemonStatus({ cleanupStale: true })) {
|
|
583
|
+
if (status.pid === null || !status.running || !status.adopted)
|
|
584
|
+
return;
|
|
585
|
+
try {
|
|
586
|
+
process.kill(status.pid, 'SIGTERM');
|
|
587
|
+
waitForPidExitSync(status.pid);
|
|
588
|
+
try {
|
|
589
|
+
fs.unlinkSync(PID_FILE);
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
// The adopted daemon may have cleaned up or another start may have taken over.
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
// The adopted orphan may already have exited; continue with a clean start.
|
|
597
|
+
}
|
|
598
|
+
}
|
|
598
599
|
/**
|
|
599
600
|
* Install the platform-native auto-start service.
|
|
600
601
|
* Returns true if the service was immediately started (so caller can skip startDaemonProcess).
|
|
@@ -724,6 +725,7 @@ async function stopDaemonProcessAndWait(timeoutMs = 5000) {
|
|
|
724
725
|
function enableRemoteAccess(opts = {}) {
|
|
725
726
|
persistServerUrlOverride(resolveServerUrlOverride(opts.api));
|
|
726
727
|
clearRemoteAccessDisabled();
|
|
728
|
+
stopAdoptedDaemonForStart();
|
|
727
729
|
const startedByService = installService();
|
|
728
730
|
if (!startedByService) {
|
|
729
731
|
startDaemonProcess({ quiet: opts.json });
|