diff --git a/apps/meteor/ee/app/license/server/startup.ts b/apps/meteor/ee/app/license/server/startup.ts index 7cdbe12111b2..f2b5f963f4b0 100644 --- a/apps/meteor/ee/app/license/server/startup.ts +++ b/apps/meteor/ee/app/license/server/startup.ts @@ -96,57 +96,60 @@ export const startLicense = async () => { } }; - // When settings are loaded, apply the current license if there is one. - settings.onReady(async () => { - if (!(await applyLicense(settings.get('Enterprise_License') ?? '', false))) { - // License from the envvar is always treated as new, because it would have been saved on the setting if it was already in use. - if (process.env.ROCKETCHAT_LICENSE && !License.hasValidLicense()) { - await applyLicense(process.env.ROCKETCHAT_LICENSE, true); + License.setLicenseLimitCounter('activeUsers', () => Users.getActiveLocalUserCount()); + License.setLicenseLimitCounter('guestUsers', () => Users.getActiveLocalGuestCount()); + License.setLicenseLimitCounter('roomsPerGuest', async (context) => (context?.userId ? Subscriptions.countByUserId(context.userId) : 0)); + License.setLicenseLimitCounter('privateApps', () => getAppCount('private')); + License.setLicenseLimitCounter('marketplaceApps', () => getAppCount('marketplace')); + License.setLicenseLimitCounter('monthlyActiveContacts', () => LivechatVisitors.countVisitorsOnPeriod(moment.utc().format('YYYY-MM'))); + + return new Promise((resolve) => { + // When settings are loaded, apply the current license if there is one. + settings.onReady(async () => { + if (!(await applyLicense(settings.get('Enterprise_License') ?? '', false))) { + // License from the envvar is always treated as new, because it would have been saved on the setting if it was already in use. + if (process.env.ROCKETCHAT_LICENSE && !License.hasValidLicense()) { + await applyLicense(process.env.ROCKETCHAT_LICENSE, true); + } } - } - // After the current license is already loaded, watch the setting value to react to new licenses being applied. - settings.change('Enterprise_License', (license) => applyLicenseOrRemove(license, true)); + // After the current license is already loaded, watch the setting value to react to new licenses being applied. + settings.change('Enterprise_License', (license) => applyLicenseOrRemove(license, true)); - callbacks.add('workspaceLicenseRemoved', () => License.remove()); + callbacks.add('workspaceLicenseRemoved', () => License.remove()); - callbacks.add('workspaceLicenseChanged', (updatedLicense) => applyLicense(updatedLicense, true)); + callbacks.add('workspaceLicenseChanged', (updatedLicense) => applyLicense(updatedLicense, true)); - License.onInstall(async () => void api.broadcast('license.actions', {} as Record, boolean>)); + License.onInstall(async () => void api.broadcast('license.actions', {} as Record, boolean>)); - License.onInvalidate(async () => void api.broadcast('license.actions', {} as Record, boolean>)); + License.onInvalidate(async () => void api.broadcast('license.actions', {} as Record, boolean>)); - License.onBehaviorTriggered('prevent_action', (context) => syncByTriggerDebounced(`prevent_action_${context.limit}`)); + License.onBehaviorTriggered('prevent_action', (context) => syncByTriggerDebounced(`prevent_action_${context.limit}`)); - License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTriggerDebounced(`start_fair_policy_${context.limit}`)); + License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTriggerDebounced(`start_fair_policy_${context.limit}`)); - License.onBehaviorTriggered('disable_modules', async (context) => syncByTriggerDebounced(`disable_modules_${context.limit}`)); + License.onBehaviorTriggered('disable_modules', async (context) => syncByTriggerDebounced(`disable_modules_${context.limit}`)); - License.onChange(() => api.broadcast('license.sync')); + License.onChange(() => api.broadcast('license.sync')); - License.onBehaviorToggled('prevent_action', (context) => { - if (!context.limit) { - return; - } - void api.broadcast('license.actions', { - [context.limit]: true, - } as Record, boolean>); - }); + License.onBehaviorToggled('prevent_action', (context) => { + if (!context.limit) { + return; + } + void api.broadcast('license.actions', { + [context.limit]: true, + } as Record, boolean>); + }); - License.onBehaviorToggled('allow_action', (context) => { - if (!context.limit) { - return; - } - void api.broadcast('license.actions', { - [context.limit]: false, - } as Record, boolean>); + License.onBehaviorToggled('allow_action', (context) => { + if (!context.limit) { + return; + } + void api.broadcast('license.actions', { + [context.limit]: false, + } as Record, boolean>); + }); + resolve(); }); }); - - License.setLicenseLimitCounter('activeUsers', () => Users.getActiveLocalUserCount()); - License.setLicenseLimitCounter('guestUsers', () => Users.getActiveLocalGuestCount()); - License.setLicenseLimitCounter('roomsPerGuest', async (context) => (context?.userId ? Subscriptions.countByUserId(context.userId) : 0)); - License.setLicenseLimitCounter('privateApps', () => getAppCount('private')); - License.setLicenseLimitCounter('marketplaceApps', () => getAppCount('marketplace')); - License.setLicenseLimitCounter('monthlyActiveContacts', () => LivechatVisitors.countVisitorsOnPeriod(moment.utc().format('YYYY-MM'))); }; diff --git a/apps/meteor/server/main.ts b/apps/meteor/server/main.ts index 2aace34eed6f..fd92a5ea8834 100644 --- a/apps/meteor/server/main.ts +++ b/apps/meteor/server/main.ts @@ -6,6 +6,7 @@ import './models/startup'; * and the startup should be done in parallel */ import './settings'; +import '../app/settings/server'; import { startLicense } from '../ee/app/license/server/startup'; import { registerEEBroker } from '../ee/server'; @@ -16,29 +17,29 @@ import { startup } from './startup'; import './routes'; import '../app/lib/server/startup'; +import './importPackages'; +import './methods'; +import './publications'; +import './lib/logger/startup'; +import '../lib/oauthRedirectUriServer'; +import './lib/pushConfig'; +import './features/EmailInbox/index'; const StartupLogger = new Logger('StartupLogger'); StartupLogger.startup('Starting Rocket.Chat server...'); -await import('../app/settings/server').then(() => StartupLogger.startup('Settings started')); await registerEEBroker().then(() => StartupLogger.startup('EE Broker registered')); -await Promise.all([ - import('./importPackages').then(() => StartupLogger.startup('Imported packages')), - import('./methods').then(() => StartupLogger.startup('Imported methods')), - import('./publications').then(() => StartupLogger.startup('Imported publications')), - import('./lib/logger/startup').then(() => StartupLogger.startup('Logger started')), - import('../lib/oauthRedirectUriServer').then(() => StartupLogger.startup('OAuth redirect uri server started')), - import('./lib/pushConfig').then(() => StartupLogger.startup('Push configuration started')), - import('./features/EmailInbox/index').then(() => StartupLogger.startup('EmailInbox started')), - configureLogLevel().then(() => StartupLogger.startup('Log level configured')), - registerServices().then(() => StartupLogger.startup('Services registered')), - import('../ee/server/startup/services'), - configureLoginServices().then(() => StartupLogger.startup('Login services configured')), - startup().then(() => StartupLogger.startup('Startup finished')), -]); +await (async () => { + await Promise.all([ + configureLogLevel().then(() => StartupLogger.startup('Log level configured')), + registerServices().then(() => StartupLogger.startup('Services registered')), + configureLoginServices().then(() => StartupLogger.startup('Login services configured')), + startup().then(() => StartupLogger.startup('Startup finished')), + ]); +})(); await startLicense().then(() => StartupLogger.startup('License started')); - +await import('../ee/server/startup/services'); StartupLogger.startup('Rocket.Chat server started.');