Skip to content

Commit 920b8ee

Browse files
committed
feat: async hypervisor and FIXED vm listing
1 parent 700d096 commit 920b8ee

File tree

16 files changed

+52
-41
lines changed

16 files changed

+52
-41
lines changed

api/scripts/deploy-dev.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ if [ ! -d "$source_directory" ]; then
3434
fi
3535
fi
3636

37+
# Change ownership on copy
3738
# Replace the value inside the rsync command with the user's input
3839
rsync_command="rsync -avz -e ssh $source_directory root@${server_name}:/usr/local/unraid-api"
3940

@@ -44,14 +45,11 @@ echo "$rsync_command"
4445
eval "$rsync_command"
4546
exit_code=$?
4647

47-
# Run unraid-api restart on remote host
48-
dev=${DEV:-true}
48+
# Chown the directory
49+
ssh root@"${server_name}" "chown -R root:root /usr/local/unraid-api"
4950

50-
if [ "$dev" = true ]; then
51-
ssh root@"${server_name}" "INTROSPECTION=true unraid-api restart"
52-
else
53-
ssh root@"${server_name}" "unraid-api restart"
54-
fi
51+
# Run unraid-api restart on remote host
52+
ssh root@"${server_name}" "INTROSPECTION=true LOG_LEVEL=trace unraid-api restart"
5553

5654
# Play built-in sound based on the operating system
5755
if [[ "$OSTYPE" == "darwin"* ]]; then

api/src/cli.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,36 @@ import '@app/dotenv';
55
import { execa } from 'execa';
66
import { CommandFactory } from 'nest-commander';
77

8-
import { cliLogger, internalLogger } from '@app/core/log';
8+
import { internalLogger, logger } from '@app/core/log';
9+
import { LOG_LEVEL } from '@app/environment';
910
import { CliModule } from '@app/unraid-api/cli/cli.module';
11+
import { LogService } from '@app/unraid-api/cli/log.service';
12+
13+
const getUnraidApiLocation = async () => {
14+
try {
15+
const shellToUse = await execa('which unraid-api');
16+
if (shellToUse.code !== 0) {
17+
throw new Error('unraid-api not found');
18+
}
19+
return shellToUse.stdout.trim();
20+
} finally {
21+
return '/usr/bin/unraid-api';
22+
}
23+
};
1024

1125
try {
12-
const shellToUse = await execa('which unraid-api')
13-
.then((res) => res.toString().trim())
14-
.catch((_) => '/usr/local/bin/unraid-api');
1526
await CommandFactory.run(CliModule, {
1627
cliName: 'unraid-api',
17-
logger: false, // new LogService(), - enable this to see nest initialization issues
28+
logger: LOG_LEVEL === 'TRACE' && new LogService(), // - enable this to see nest initialization issues
1829
completion: {
19-
fig: true,
30+
fig: false,
2031
cmd: 'completion-script',
21-
nativeShell: { executablePath: shellToUse },
32+
nativeShell: { executablePath: await getUnraidApiLocation() },
2233
},
2334
});
2435
process.exit(0);
2536
} catch (error) {
26-
cliLogger.error('ERROR:', error);
37+
logger.error('ERROR:', error);
2738
internalLogger.error({
2839
message: 'Failed to start unraid-api',
2940
error,

api/src/core/modules/vms/get-domains.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ const states = {
1818
* Get vm domains.
1919
*/
2020
export const getDomains = async () => {
21-
const { ConnectListAllDomainsFlags } = await import('@vmngr/libvirt');
22-
const { UnraidHypervisor } = await import('@app/core/utils/vms/get-hypervisor');
2321
try {
22+
const { ConnectListAllDomainsFlags } = await import('@vmngr/libvirt');
23+
const { UnraidHypervisor } = await import('@app/core/utils/vms/get-hypervisor');
24+
2425
const hypervisor = await UnraidHypervisor.getInstance().getHypervisor();
2526
if (!hypervisor) {
2627
throw new GraphQLError('VMs Disabled');

api/src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const BYPASS_PERMISSION_CHECKS = process.env.BYPASS_PERMISSION_CHECKS ===
1919
export const BYPASS_CORS_CHECKS = process.env.BYPASS_CORS_CHECKS === 'true';
2020
export const LOG_CORS = process.env.LOG_CORS === 'true';
2121
export const LOG_TYPE = (process.env.LOG_TYPE as 'pretty' | 'raw') ?? 'pretty';
22-
export const LOG_LEVEL = process.env.LOG_LEVEL as
22+
export const LOG_LEVEL = process.env.LOG_LEVEL?.toUpperCase() as
2323
| 'TRACE'
2424
| 'DEBUG'
2525
| 'INFO'

api/src/graphql/schema/types/vms/domain.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type Query {
44
}
55

66
type Vms {
7+
id: ID!
78
domain: [VmDomain!]
89
}
910

api/src/unraid-api/cli/restart.command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export class RestartCommand extends CommandRunner {
1212

1313
async run(_): Promise<void> {
1414
try {
15+
this.logger.info('Restarting the Unraid API');
1516
const { stderr, stdout } = await execa(PM2_PATH, [
1617
'restart',
1718
ECOSYSTEM_PATH,
1819
'--update-env',
1920
]);
21+
this.logger.info('Unraid API restarted');
2022
if (stderr) {
2123
this.logger.error(stderr);
2224
process.exit(1);

api/src/unraid-api/cli/start.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Command, CommandRunner, Option } from 'nest-commander';
33

44
import { ECOSYSTEM_PATH, PM2_PATH } from '@app/consts';
55
import { levels, type LogLevel } from '@app/core/log';
6-
import type { LogService } from '@app/unraid-api/cli/log.service';
6+
import { LogService } from '@app/unraid-api/cli/log.service';
77

88
interface StartCommandOptions {
99
'log-level'?: string;

api/src/unraid-api/graph/resolvers/display/display.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const states = {
5858
},
5959
};
6060

61-
@Resolver()
61+
@Resolver('Display')
6262
export class DisplayResolver {
6363
@Query()
6464
@UsePermissions({

api/src/unraid-api/graph/resolvers/flash/flash.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AuthActionVerb, AuthPossession, UsePermissions } from 'nest-authz';
55
import { Resource } from '@app/graphql/generated/api/types';
66
import { getters } from '@app/store/index';
77

8-
@Resolver()
8+
@Resolver('Flash')
99
export class FlashResolver {
1010
@Query()
1111
@UsePermissions({

api/src/unraid-api/graph/resolvers/me/me.resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { UserAccount } from '@app/graphql/generated/api/types';
66
import { Me, Resource } from '@app/graphql/generated/api/types';
77
import { GraphqlUser } from '@app/unraid-api/auth/user.decorator';
88

9-
@Resolver()
9+
@Resolver('Me')
1010
export class MeResolver {
1111
constructor() {}
1212

0 commit comments

Comments
 (0)