feat(daemon): Persist desired process states and add daemon restart command

This commit is contained in:
2025-08-29 17:27:32 +00:00
parent 504725043d
commit 2291348774
5 changed files with 144 additions and 1 deletions

View File

@@ -81,6 +81,7 @@ export class TspmDaemon {
// Load existing process configurations
await this.tspmInstance.loadProcessConfigs();
await this.tspmInstance.loadDesiredStates();
// Set up log publishing
this.tspmInstance.on('process:log', ({ processId, log }) => {
@@ -95,6 +96,9 @@ export class TspmDaemon {
// Set up graceful shutdown handlers
this.setupShutdownHandlers();
// Start processes that should be online per desired state
await this.tspmInstance.startDesired();
console.log(`TSPM daemon started successfully on ${this.socketPath}`);
console.log(`PID: ${process.pid}`);
}
@@ -108,6 +112,7 @@ export class TspmDaemon {
'start',
async (request: RequestForMethod<'start'>) => {
try {
await this.tspmInstance.setDesiredState(request.config.id, 'online');
await this.tspmInstance.start(request.config);
const processInfo = this.tspmInstance.processInfo.get(
request.config.id,
@@ -127,6 +132,7 @@ export class TspmDaemon {
'stop',
async (request: RequestForMethod<'stop'>) => {
try {
await this.tspmInstance.setDesiredState(request.id, 'stopped');
await this.tspmInstance.stop(request.id);
return {
success: true,
@@ -142,6 +148,7 @@ export class TspmDaemon {
'restart',
async (request: RequestForMethod<'restart'>) => {
try {
await this.tspmInstance.setDesiredState(request.id, 'online');
await this.tspmInstance.restart(request.id);
const processInfo = this.tspmInstance.processInfo.get(request.id);
return {
@@ -234,6 +241,7 @@ export class TspmDaemon {
const started: string[] = [];
const failed: Array<{ id: string; error: string }> = [];
await this.tspmInstance.setDesiredStateForAll('online');
await this.tspmInstance.startAll();
// Get status of all processes
@@ -255,6 +263,7 @@ export class TspmDaemon {
const stopped: string[] = [];
const failed: Array<{ id: string; error: string }> = [];
await this.tspmInstance.setDesiredStateForAll('stopped');
await this.tspmInstance.stopAll();
// Get status of all processes