fix: Initialize license in queue mode correctly (#6301)

This commit is contained in:
Omar Ajoue
2023-05-23 13:01:50 +02:00
committed by GitHub
parent 55b755cb44
commit 42c79cd6f1
5 changed files with 26 additions and 23 deletions

View File

@@ -19,6 +19,7 @@ import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import type { IExternalHooksClass } from '@/Interfaces';
import { InternalHooks } from '@/InternalHooks';
import { PostHogClient } from '@/posthog';
import { License } from '@/License';
export const UM_FIX_INSTRUCTION =
'Please fix the database by running ./packages/cli/bin/n8n user-management:reset';
@@ -119,6 +120,28 @@ export abstract class BaseCommand extends Command {
await this.externalHooks.init();
}
async initLicense(): Promise<void> {
const license = Container.get(License);
await license.init(this.instanceId);
const activationKey = config.getEnv('license.activationKey');
if (activationKey) {
const hasCert = (await license.loadCertStr()).length > 0;
if (hasCert) {
return LoggerProxy.debug('Skipping license activation');
}
try {
LoggerProxy.debug('Attempting license activation');
await license.activate(activationKey);
} catch (e) {
LoggerProxy.error('Could not activate license', e as Error);
}
}
}
async finally(error: Error | undefined) {
if (inTest || this.id === 'start') return;
if (Db.connectionState.connected) {