mirror of
https://github.com/unraid/api.git
synced 2026-01-02 06:30:02 -06:00
feat: pm2 fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { PM2_PATH } from '@app/consts';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
export const status = async () => {
|
||||
execSync('pm2 status unraid-api', { stdio: 'inherit' });
|
||||
execSync(`${PM2_PATH} status unraid-api`, { stdio: 'inherit' });
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import { setEnv } from '@app/cli/set-env';
|
||||
import { env } from '@app/dotenv';
|
||||
import { getters } from '@app/store';
|
||||
import { execSync } from 'child_process';
|
||||
import { PM2_PATH } from '@app/consts';
|
||||
|
||||
const command = mainOptions.command as unknown as string;
|
||||
|
||||
@@ -31,7 +32,7 @@ export const main = async (...argv: string[]) => {
|
||||
start: import('@app/cli/commands/start').then((pkg) => pkg.start),
|
||||
stop: import('@app/cli/commands/stop').then((pkg) => pkg.stop),
|
||||
restart: import('@app/cli/commands/restart').then((pkg) => pkg.restart),
|
||||
logs: async () => execSync('pm2 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),
|
||||
version: import('@app/cli/commands/version').then((pkg) => pkg.version),
|
||||
status: import('@app/cli/commands/status').then((pkg) => pkg.status),
|
||||
|
||||
@@ -5,25 +5,22 @@ export const isUnraidApiRunning = async (): Promise<boolean | undefined> => {
|
||||
pm2.connect(function (err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
reject('Could not connect to pm2');
|
||||
reject('Could not connect to pm2');
|
||||
}
|
||||
|
||||
pm2.describe('unraid-api', function (err, processDescription) {
|
||||
console.log(err)
|
||||
console.log(err);
|
||||
if (err || processDescription.length === 0) {
|
||||
console.log(false); // Service not found or error occurred
|
||||
resolve(false);
|
||||
resolve(false);
|
||||
} else {
|
||||
const isOnline = processDescription?.[0]?.pm2_env?.status === 'online';
|
||||
console.log(isOnline); // Output true if online, false otherwise
|
||||
resolve(isOnline);
|
||||
resolve(isOnline);
|
||||
}
|
||||
|
||||
pm2.disconnect();
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user