11import { execSync } from 'child_process' ;
22import { join } from 'path' ;
33
4+ import { execa } from 'execa' ;
45import { Command , CommandRunner , Option } from 'nest-commander' ;
56
6- import { PM2_PATH } from '@app/consts' ;
7+ import { ECOSYSTEM_PATH , PM2_PATH } from '@app/consts' ;
78import { levels } from '@app/core/log' ;
89import { LogService } from '@app/unraid-api/cli/log.service' ;
910
@@ -21,27 +22,23 @@ export class StartCommand extends CommandRunner {
2122 }
2223
2324 async run ( _ , options : StartCommandOptions ) : Promise < void > {
24- this . logger . debug ( options ) ;
25- this . logger . log (
26- `Starting unraid-api with command:
27- ${ PM2_PATH } start ${ join ( import . meta. dirname , 'ecosystem.config.json' ) } --update-env`
28- ) ;
29-
30- execSync (
31- `${ PM2_PATH } start ${ join ( import . meta. dirname , '../../' , 'ecosystem.config.json' ) } --update-env` ,
32- {
33- env : process . env ,
34- stdio : 'inherit' ,
35- cwd : process . cwd ( ) ,
36- }
37- ) ;
25+ this . logger . info ( 'Starting the Unraid API' ) ;
26+ const envLog = options [ 'log-level' ] ? `LOG_LEVEL=${ options [ 'log-level' ] } ` : ''
27+ const { stderr, stdout } = await execa ( `${ envLog } ${ PM2_PATH } ` . trim ( ) , [ 'start' , ECOSYSTEM_PATH , '--update-env' ] ) ;
28+ if ( stdout ) {
29+ this . logger . log ( stdout ) ;
30+ }
31+ if ( stderr ) {
32+ this . logger . error ( stderr ) ;
33+ process . exit ( 1 ) ;
34+ }
3835 }
3936
4037 @Option ( {
41- flags : ' --log-level [string]' ,
38+ flags : ` --log-level < ${ levels . join ( '|' ) } >` ,
4239 description : 'log level to use' ,
4340 } )
44- parseLogLevel ( val : unknown ) : typeof levels {
41+ parseLogLevel ( val : string ) : typeof levels {
4542 return ( levels . includes ( val as ( typeof levels ) [ number ] )
4643 ? ( val as ( typeof levels ) [ number ] )
4744 : 'info' ) as unknown as typeof levels ;
0 commit comments