BREAKING CHANGE(daemon): Introduce persistent log storage, numeric ProcessId type, and improved process monitoring / IPC handling
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import * as plugins from '../plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
import { toProcessId } from '../shared/protocol/id.js';
|
||||
import type { ProcessId } from '../shared/protocol/id.js';
|
||||
import { ProcessManager } from './processmanager.js';
|
||||
import type {
|
||||
IpcMethodMap,
|
||||
@@ -141,7 +143,7 @@ export class TspmDaemon {
|
||||
'startById',
|
||||
async (request: RequestForMethod<'startById'>) => {
|
||||
try {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
let config = this.tspmInstance.processConfigs.get(id);
|
||||
if (!config) {
|
||||
// Try to reload configs if not found (handles races or stale state)
|
||||
@@ -169,7 +171,7 @@ export class TspmDaemon {
|
||||
'stop',
|
||||
async (request: RequestForMethod<'stop'>) => {
|
||||
try {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
await this.tspmInstance.setDesiredState(id, 'stopped');
|
||||
await this.tspmInstance.stop(id);
|
||||
return {
|
||||
@@ -186,7 +188,7 @@ export class TspmDaemon {
|
||||
'restart',
|
||||
async (request: RequestForMethod<'restart'>) => {
|
||||
try {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
await this.tspmInstance.setDesiredState(id, 'online');
|
||||
await this.tspmInstance.restart(id);
|
||||
const processInfo = this.tspmInstance.processInfo.get(id);
|
||||
@@ -205,7 +207,7 @@ export class TspmDaemon {
|
||||
'delete',
|
||||
async (request: RequestForMethod<'delete'>) => {
|
||||
try {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
await this.tspmInstance.delete(id);
|
||||
return {
|
||||
success: true,
|
||||
@@ -235,7 +237,7 @@ export class TspmDaemon {
|
||||
'remove',
|
||||
async (request: RequestForMethod<'remove'>) => {
|
||||
try {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
await this.tspmInstance.delete(id);
|
||||
return { success: true, message: `Process ${id} deleted successfully` };
|
||||
} catch (error) {
|
||||
@@ -255,7 +257,7 @@ export class TspmDaemon {
|
||||
this.ipcServer.onMessage(
|
||||
'describe',
|
||||
async (request: RequestForMethod<'describe'>) => {
|
||||
const id = String(request.id).trim();
|
||||
const id = toProcessId(request.id);
|
||||
const result = await this.tspmInstance.describe(id);
|
||||
if (!result) {
|
||||
throw new Error(`Process ${id} not found`);
|
||||
@@ -271,7 +273,7 @@ export class TspmDaemon {
|
||||
this.ipcServer.onMessage(
|
||||
'getLogs',
|
||||
async (request: RequestForMethod<'getLogs'>) => {
|
||||
const logs = await this.tspmInstance.getLogs(request.id);
|
||||
const logs = await this.tspmInstance.getLogs(toProcessId(request.id));
|
||||
return { logs };
|
||||
},
|
||||
);
|
||||
@@ -280,8 +282,8 @@ export class TspmDaemon {
|
||||
this.ipcServer.onMessage(
|
||||
'startAll',
|
||||
async (request: RequestForMethod<'startAll'>) => {
|
||||
const started: string[] = [];
|
||||
const failed: Array<{ id: string; error: string }> = [];
|
||||
const started: ProcessId[] = [];
|
||||
const failed: Array<{ id: ProcessId; error: string }> = [];
|
||||
|
||||
await this.tspmInstance.setDesiredStateForAll('online');
|
||||
await this.tspmInstance.startAll();
|
||||
@@ -302,8 +304,8 @@ export class TspmDaemon {
|
||||
this.ipcServer.onMessage(
|
||||
'stopAll',
|
||||
async (request: RequestForMethod<'stopAll'>) => {
|
||||
const stopped: string[] = [];
|
||||
const failed: Array<{ id: string; error: string }> = [];
|
||||
const stopped: ProcessId[] = [];
|
||||
const failed: Array<{ id: ProcessId; error: string }> = [];
|
||||
|
||||
await this.tspmInstance.setDesiredStateForAll('stopped');
|
||||
await this.tspmInstance.stopAll();
|
||||
@@ -324,8 +326,8 @@ export class TspmDaemon {
|
||||
this.ipcServer.onMessage(
|
||||
'restartAll',
|
||||
async (request: RequestForMethod<'restartAll'>) => {
|
||||
const restarted: string[] = [];
|
||||
const failed: Array<{ id: string; error: string }> = [];
|
||||
const restarted: ProcessId[] = [];
|
||||
const failed: Array<{ id: ProcessId; error: string }> = [];
|
||||
|
||||
await this.tspmInstance.restartAll();
|
||||
|
||||
@@ -556,3 +558,11 @@ export const startDaemon = async (): Promise<void> => {
|
||||
// Keep the process alive
|
||||
await new Promise(() => {});
|
||||
};
|
||||
|
||||
// If this file is run directly (not imported), start the daemon
|
||||
if (process.env.TSPM_DAEMON_MODE === 'true') {
|
||||
startDaemon().catch((error) => {
|
||||
console.error('Failed to start TSPM daemon:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user