feat: use execa for start and stop

This commit is contained in:
Eli Bosley
2025-01-17 14:52:11 -05:00
parent a892a3ce35
commit 05e77a4bc6
2 changed files with 20 additions and 10 deletions

View File

@@ -1,6 +1,3 @@
import { execSync } from 'child_process';
import { join } from 'path';
import { execa } from 'execa';
import { Command, CommandRunner, Option } from 'nest-commander';
@@ -23,8 +20,12 @@ export class StartCommand extends CommandRunner {
async run(_, options: StartCommandOptions): Promise<void> {
this.logger.info('Starting the Unraid API');
const envLog = options['log-level'] ? `LOG_LEVEL=${options['log-level']}` : ''
const { stderr, stdout } = await execa(`${envLog} ${PM2_PATH}`.trim(), ['start', ECOSYSTEM_PATH, '--update-env']);
const envLog = options['log-level'] ? `LOG_LEVEL=${options['log-level']}` : '';
const { stderr, stdout } = await execa(
`${envLog} ${PM2_PATH}`.trim(),
['start', ECOSYSTEM_PATH, '--update-env'],
{ stdio: 'inherit' }
);
if (stdout) {
this.logger.log(stdout);
}

View File

@@ -1,14 +1,23 @@
import { execSync } from 'child_process';
import { execa } from 'execa';
import { Command, CommandRunner } from 'nest-commander';
import { Command, CommandRunner, SubCommand } from 'nest-commander';
import { PM2_PATH } from '@app/consts';
import { ECOSYSTEM_PATH, PM2_PATH } from '@app/consts';
import { LogService } from '@app/unraid-api/cli/log.service';
@Command({
name: 'stop',
})
export class StopCommand extends CommandRunner {
constructor(private readonly logger: LogService) {
super();
}
async run() {
execSync(`${PM2_PATH} stop unraid-api`, { stdio: 'inherit' });
const { stderr, stdout } = await execa(PM2_PATH, ['stop', ECOSYSTEM_PATH]);
if (stdout) {
this.logger.info(stdout);
} else if (stderr) {
this.logger.warn(stderr);
process.exit(1);
}
}
}