fix: forced restarting on commands

This commit is contained in:
Eli Bosley
2024-11-06 15:21:08 -05:00
parent 504283f227
commit abd8e09908
4 changed files with 5 additions and 18 deletions

View File

@@ -7,6 +7,4 @@ import { stop } from '@app/cli/commands/stop';
export const restart = async () => { export const restart = async () => {
await stop(); await stop();
await start(); await start();
process.exit(0);
}; };

View File

@@ -5,14 +5,11 @@ import { join } from 'node:path';
/** /**
* Start a new API process. * Start a new API process.
*/ */
export const start = async (exit = false) => { export const start = async () => {
cliLogger.info('Starting unraid-api with command', `${PM2_PATH} start ${join(import.meta.dirname, 'ecosystem.config.json')} --update-env`); cliLogger.info('Starting unraid-api with command', `${PM2_PATH} start ${join(import.meta.dirname, 'ecosystem.config.json')} --update-env`);
execSync(`${PM2_PATH} start ${join(import.meta.dirname, '../../', 'ecosystem.config.json')} --update-env`, { execSync(`${PM2_PATH} start ${join(import.meta.dirname, '../../', 'ecosystem.config.json')} --update-env`, {
env: process.env, env: process.env,
stdio: 'inherit', stdio: 'inherit',
}); });
if (exit) {
process.exit(0);
}
}; };

View File

@@ -1,9 +1,6 @@
import { PM2_PATH } from '@app/consts'; import { PM2_PATH } from '@app/consts';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
export const stop = async (exit = false) => { export const stop = async () => {
execSync(`${PM2_PATH} stop unraid-api`, { stdio: 'inherit' }); execSync(`${PM2_PATH} stop unraid-api`, { stdio: 'inherit' });
if (exit) {
process.exit(0);
}
}; };

View File

@@ -27,8 +27,8 @@ export const main = async (...argv: string[]) => {
// Only import the command we need when we use it // Only import the command we need when we use it
const commands = { const commands = {
start: import('@app/cli/commands/start').then((pkg) => pkg.start(true)), start: import('@app/cli/commands/start').then((pkg) => pkg.start),
stop: import('@app/cli/commands/stop').then((pkg) => pkg.stop(true)), stop: import('@app/cli/commands/stop').then((pkg) => pkg.stop),
restart: import('@app/cli/commands/restart').then((pkg) => pkg.restart), restart: import('@app/cli/commands/restart').then((pkg) => pkg.restart),
logs: async () => execSync(`${PM2_PATH} logs unraid-api --lines 200`, { stdio: 'inherit' }), logs: async () => execSync(`${PM2_PATH} logs unraid-api --lines 200`, { stdio: 'inherit' }),
'switch-env': import('@app/cli/commands/switch-env').then((pkg) => pkg.switchEnv), 'switch-env': import('@app/cli/commands/switch-env').then((pkg) => pkg.switchEnv),
@@ -49,10 +49,5 @@ export const main = async (...argv: string[]) => {
// Run the command // Run the command
await commandMethod(...argv); await commandMethod(...argv);
// Allow the process to exit process.exit(0);
// Don't exit when we start though
if (!['start', 'restart'].includes(command)) {
// Ensure process is exited
process.exit(0);
}
}; };