diff --git a/api/src/dotenv.ts b/api/src/dotenv.ts index 08fec0d35..c772e5b7a 100644 --- a/api/src/dotenv.ts +++ b/api/src/dotenv.ts @@ -2,10 +2,15 @@ import { config } from 'dotenv'; const env = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' - ? config({ debug: true, path: `./.env.${process.env.NODE_ENV}`, encoding: 'utf-8' }) + ? config({ + debug: true, + path: `./.env.${process.env.NODE_ENV}`, + encoding: 'utf-8', + override: true, + }) : config({ path: '/usr/local/unraid-api/.env', encoding: 'utf-8', }); -export default env; \ No newline at end of file +export default env; diff --git a/api/src/environment.ts b/api/src/environment.ts index a66ee8d41..39652e552 100644 --- a/api/src/environment.ts +++ b/api/src/environment.ts @@ -3,7 +3,8 @@ import { version } from 'package.json'; export const API_VERSION = process.env.npm_package_version ?? version ?? new Error('API_VERSION not set'); -export const NODE_ENV = process.env.NODE_ENV as 'development' | 'test' | 'staging' | 'production' ?? 'production'; +export const NODE_ENV = + (process.env.NODE_ENV as 'development' | 'test' | 'staging' | 'production') ?? 'production'; export const environment = { IS_MAIN_PROCESS: false, }; @@ -11,7 +12,9 @@ export const CHOKIDAR_USEPOLLING = process.env.CHOKIDAR_USEPOLLING === 'true'; export const IS_DOCKER = process.env.IS_DOCKER === 'true'; export const DEBUG = process.env.DEBUG === 'true'; export const INTROSPECTION = process.env.INTROSPECTION === 'true'; -export const ENVIRONMENT = process.env.ENVIRONMENT as 'production' | 'staging' | 'development' ?? 'production'; +export const ENVIRONMENT = process.env.ENVIRONMENT + ? (process.env.ENVIRONMENT as 'production' | 'staging' | 'development') + : 'production'; export const GRAPHQL_INTROSPECTION = Boolean(INTROSPECTION ?? DEBUG ?? ENVIRONMENT !== 'production'); export const PORT = process.env.PORT ?? '/var/run/unraid-api.sock'; export const DRY_RUN = process.env.DRY_RUN === 'true'; @@ -19,15 +22,13 @@ export const BYPASS_PERMISSION_CHECKS = process.env.BYPASS_PERMISSION_CHECKS === export const BYPASS_CORS_CHECKS = process.env.BYPASS_CORS_CHECKS === 'true'; export const LOG_CORS = process.env.LOG_CORS === 'true'; export const LOG_TYPE = (process.env.LOG_TYPE as 'pretty' | 'raw') ?? 'pretty'; -export const LOG_LEVEL = process.env.LOG_LEVEL?.toUpperCase() as - | 'TRACE' - | 'DEBUG' - | 'INFO' - | 'WARN' - | 'ERROR' - | 'FATAL' ?? process.env.ENVIRONMENT === 'production' ? 'INFO' : 'TRACE'; -export const MOTHERSHIP_GRAPHQL_LINK = - process.env.MOTHERSHIP_GRAPHQL_LINK ?? - (process.env.ENVIRONMENT === 'staging' - ? 'https://staging.mothership.unraid.net/ws' - : 'https://mothership.unraid.net/ws'); \ No newline at end of file +export const LOG_LEVEL = process.env.LOG_LEVEL + ? (process.env.LOG_LEVEL.toUpperCase() as 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL') + : process.env.ENVIRONMENT === 'production' + ? 'INFO' + : 'TRACE'; +export const MOTHERSHIP_GRAPHQL_LINK = process.env.MOTHERSHIP_GRAPHQL_LINK + ? process.env.MOTHERSHIP_GRAPHQL_LINK + : ENVIRONMENT === 'staging' + ? 'https://staging.mothership.unraid.net/ws' + : 'https://mothership.unraid.net/ws'; diff --git a/api/src/index.ts b/api/src/index.ts index 2e4f55710..68dc9c134 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -13,8 +13,6 @@ import exitHook from 'exit-hook'; import { WebSocket } from 'ws'; import { logger } from '@app/core/log'; -import { setupLogRotation } from '@app/core/logrotate/setup-logrotate'; -import { setupAuthRequest } from '@app/core/sso/auth-request-setup'; import { fileExistsSync } from '@app/core/utils/files/file-exists'; import { environment, PORT } from '@app/environment'; import * as envVars from '@app/environment'; diff --git a/api/src/unraid-api/cli/log.service.ts b/api/src/unraid-api/cli/log.service.ts index ad1f5424e..e3389f687 100644 --- a/api/src/unraid-api/cli/log.service.ts +++ b/api/src/unraid-api/cli/log.service.ts @@ -13,10 +13,11 @@ export class LogService { shouldLog(level: LogLevel): boolean { const logLevelsLowToHigh = levels; - return ( + const shouldLog = ( logLevelsLowToHigh.indexOf(level) >= logLevelsLowToHigh.indexOf(LOG_LEVEL.toLowerCase() as LogLevel) ); + return shouldLog; } log(message: string): void { diff --git a/api/src/unraid-api/cli/start.command.ts b/api/src/unraid-api/cli/start.command.ts index 7f9975a9b..a604fdfb5 100644 --- a/api/src/unraid-api/cli/start.command.ts +++ b/api/src/unraid-api/cli/start.command.ts @@ -8,6 +8,7 @@ import type { LogLevel } from '@app/core/log'; import { ECOSYSTEM_PATH, PM2_PATH } from '@app/consts'; import { levels } from '@app/core/log'; import { LogService } from '@app/unraid-api/cli/log.service'; +import { LOG_LEVEL, NODE_ENV } from '@app/environment'; interface StartCommandOptions { 'log-level'?: string; @@ -21,6 +22,7 @@ export class StartCommand extends CommandRunner { async configurePm2(): Promise { if (existsSync('/tmp/pm2-configured')) { + this.logger.debug('PM2 already configured'); return; } // Write a temp file when first started to prevent needing to run this again @@ -58,7 +60,6 @@ export class StartCommand extends CommandRunner { async run(_: string[], options: StartCommandOptions): Promise { this.logger.info('Starting the Unraid API'); - await this.configurePm2(); const envLog = options['log-level'] ? `LOG_LEVEL=${options['log-level']}` : '';