mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: use execa for start and stop
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user