Files
flyer-crawler.projectium.com/src/services/systemService.ts
Torben Sorensen b7f3182fd6
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 4m24s
clean up routes
2025-12-29 13:34:26 -08:00

31 lines
1.1 KiB
TypeScript

// src/services/systemService.ts
import { exec } from 'child_process';
import { promisify } from 'util';
import { logger } from './logger.server';
const execAsync = promisify(exec);
class SystemService {
async getPm2Status(): Promise<{ success: boolean; message: string }> {
try {
const { stdout } = await execAsync('pm2 describe flyer-crawler-api');
const isOnline = /│ status\s+│ online\s+│/m.test(stdout);
const message = isOnline
? 'Application is online and running under PM2.'
: 'Application process exists but is not online.';
return { success: isOnline, message };
} catch (error: any) {
if (error.stdout && error.stdout.includes("doesn't exist")) {
logger.warn('[SystemService] PM2 process "flyer-crawler-api" not found.');
return {
success: false,
message: 'Application process is not running under PM2.',
};
}
logger.error({ error: error.stderr || error.message }, '[SystemService] Error executing pm2 describe:');
throw error;
}
}
}
export const systemService = new SystemService();