feat(daemon): Add CLI systemd service refresh on version mismatch and fix daemon memory leak; update dependencies
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tspm',
|
||||
version: '5.3.2',
|
||||
version: '5.4.0',
|
||||
description: 'a no fuzz process manager'
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ import * as plugins from './plugins.js';
|
||||
import { tspmIpcClient } from '../client/tspm.ipcclient.js';
|
||||
import * as paths from '../paths.js';
|
||||
import { Logger, LogLevel } from '../shared/common/utils.errorhandler.js';
|
||||
import { TspmServiceManager } from '../client/tspm.servicemanager.js';
|
||||
|
||||
// Import command registration functions
|
||||
import { registerDefaultCommand } from './commands/default.js';
|
||||
@@ -51,6 +52,38 @@ export const run = async (): Promise<void> => {
|
||||
console.log(
|
||||
`Daemon: running v${status.version || 'unknown'} (pid ${status.pid})`,
|
||||
);
|
||||
// If versions mismatch, offer to refresh the systemd service
|
||||
if (status.version && status.version !== cliVersion) {
|
||||
console.log('\nVersion mismatch detected:');
|
||||
console.log(` CLI: v${cliVersion}`);
|
||||
console.log(` Daemon: v${status.version}`);
|
||||
console.log(
|
||||
'\nThis can happen after upgrading tspm. The systemd service may still point to an older version.\n' +
|
||||
'You can refresh the service (equivalent to "tspm disable" then "tspm enable").',
|
||||
);
|
||||
|
||||
// Ask the user for confirmation
|
||||
const confirm = await plugins.smartinteract.SmartInteract.getCliConfirmation(
|
||||
'Refresh the systemd service now?',
|
||||
true,
|
||||
);
|
||||
if (confirm) {
|
||||
try {
|
||||
const sm = new TspmServiceManager();
|
||||
console.log('Refreshing TSPM system service...');
|
||||
await sm.disableService();
|
||||
await sm.enableService();
|
||||
console.log('✓ Service refreshed. Daemon restarted via systemd.');
|
||||
} catch (err: any) {
|
||||
console.error(
|
||||
'Failed to refresh service automatically. You can try manually:\n tspm disable && tspm enable',
|
||||
);
|
||||
console.error(err?.message || String(err));
|
||||
}
|
||||
} else {
|
||||
console.log('Skipped service refresh.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('Daemon: not running');
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
// Minimal plugin set for lightweight client startup
|
||||
import * as path from 'node:path';
|
||||
import * as smartdaemon from '@push.rocks/smartdaemon';
|
||||
import * as smartipc from '@push.rocks/smartipc';
|
||||
|
||||
export { path, smartipc };
|
||||
export { path, smartdaemon, smartipc };
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import * as plugins from '../plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
|
||||
/**
|
||||
|
@@ -139,6 +139,14 @@ export class ProcessMonitor extends EventEmitter {
|
||||
this.logger.info(exitMsg);
|
||||
this.log(exitMsg);
|
||||
|
||||
// Clear pidusage internal state for this PID to prevent memory leaks
|
||||
try {
|
||||
const pidToClear = this.processWrapper?.getPid();
|
||||
if (pidToClear) {
|
||||
(plugins.pidusage as any)?.clear?.(pidToClear);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
// Flush logs to disk on exit
|
||||
if (this.processId && this.logs.length > 0) {
|
||||
try {
|
||||
@@ -385,6 +393,13 @@ export class ProcessMonitor extends EventEmitter {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
if (this.processWrapper) {
|
||||
// Clear pidusage state for current PID before stopping to avoid leaks
|
||||
try {
|
||||
const pidToClear = this.processWrapper.getPid();
|
||||
if (pidToClear) {
|
||||
(plugins.pidusage as any)?.clear?.(pidToClear);
|
||||
}
|
||||
} catch {}
|
||||
this.processWrapper.stop();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user