diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a4a37225a..d0178ee2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ ## __WORK IN PROGRESS__ --> -## 6.0.7 (2024-07-12) +## __WORK IN PROGRESS__ - Kiera +* (foxriver76) fixed problem with Sentry plugin + +## 6.0.7 (2024-07-12) - Kiera * (foxriver76) added auto upgrade information to cli `list adapters` and `repo show` * (foxriver76) do not show the stack trace if user does not exist on `iob user check` * (foxriver76) prevent `iob logs --watch` logging the entries two times diff --git a/package-lock.json b/package-lock.json index 2647ac2304..6852f0b7ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -885,16 +885,16 @@ "link": true }, "node_modules/@iobroker/plugin-base": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@iobroker/plugin-base/-/plugin-base-2.0.1.tgz", - "integrity": "sha512-dCcvgNsvjBL5G7vxSJ9awP3W4f6Jj36aPdAKJh4EI6QYOTrlIKoct12VZPVF07Cu+PzKDTJbadHqd/SF2hs+Ow==" + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@iobroker/plugin-base/-/plugin-base-1.2.1.tgz", + "integrity": "sha512-G3liVMb9PIY9+17ErcUxmSdxqBL/cIWxt69rq+6abnprGZP+psLh6isgQn5Dqifgis6us6FyRy1a/t4LP+Lzlg==" }, "node_modules/@iobroker/plugin-sentry": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@iobroker/plugin-sentry/-/plugin-sentry-2.0.4.tgz", - "integrity": "sha512-cA36YYgInBVux3R/byn7D8lx8b4VIT+r5ZWNWFFa69XFAydLh3piq27veUSG07F8lDLuUZrMYCfAKliCbiwZ/Q==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@iobroker/plugin-sentry/-/plugin-sentry-1.2.1.tgz", + "integrity": "sha512-lZIcgjiNVOXp9nupNNagGOEynR/bYWg63WyPIN4vEhtQvqCEGcFjWulSSgZ6HBWLR8uZRQvN8su7MC8VOUvF3w==", "dependencies": { - "@iobroker/plugin-base": "^2.0.1", + "@iobroker/plugin-base": "^1.2.1", "@sentry/integrations": "^7.55.2", "@sentry/node": "^7.55.2", "source-map-support": "^0.5.21" @@ -14836,7 +14836,7 @@ }, "packages/adapter": { "name": "@iobroker/js-controller-adapter", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@alcalzone/pak": "^0.8.1", @@ -14848,7 +14848,8 @@ "@iobroker/db-states-redis": "file:../db-states-redis", "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", + "@iobroker/plugin-base": "~1.2.1", + "@iobroker/plugin-sentry": "~1.2.1", "deep-clone": "^3.0.3", "fs-extra": "^11.1.0", "jsonwebtoken": "^9.0.0", @@ -14865,12 +14866,11 @@ }, "packages/cli": { "name": "@iobroker/js-controller-cli", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", "axios": "^1.6.3", "chokidar": "^3.5.3", "debug": "^4.3.4", @@ -14898,7 +14898,7 @@ }, "packages/common": { "name": "@iobroker/js-controller-common", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@iobroker/db-objects-file": "file:../db-objects-file", @@ -14920,7 +14920,7 @@ }, "packages/common-db": { "name": "@iobroker/js-controller-common-db", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@alcalzone/pak": "^0.8.1", @@ -14961,7 +14961,7 @@ }, "packages/controller": { "name": "iobroker.js-controller", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -14976,8 +14976,8 @@ "@iobroker/js-controller-cli": "file:../cli", "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", - "@iobroker/plugin-sentry": "~2.0.4", + "@iobroker/plugin-base": "~1.2.1", + "@iobroker/plugin-sentry": "~1.2.1", "axios": "^1.6.3", "cron-parser": "^4.9.0", "debug": "^4.3.4", @@ -15014,7 +15014,7 @@ }, "packages/db-base": { "name": "@iobroker/db-base", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@iobroker/js-controller-common-db": "file:../common-db", @@ -15028,7 +15028,7 @@ }, "packages/db-objects-file": { "name": "@iobroker/db-objects-file", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "Apache 2.0", "dependencies": { "@iobroker/db-base": "file:../db-base", @@ -15042,7 +15042,7 @@ }, "packages/db-objects-jsonl": { "name": "@iobroker/db-objects-jsonl", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "Apache 2.0", "dependencies": { "@alcalzone/jsonl-db": "~3.1.1", @@ -15058,7 +15058,7 @@ }, "packages/db-objects-redis": { "name": "@iobroker/db-objects-redis", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "Apache 2.0", "dependencies": { "@iobroker/db-base": "file:../db-base", @@ -15074,7 +15074,7 @@ }, "packages/db-states-file": { "name": "@iobroker/db-states-file", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@iobroker/db-base": "file:../db-base", @@ -15086,7 +15086,7 @@ }, "packages/db-states-jsonl": { "name": "@iobroker/db-states-jsonl", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@alcalzone/jsonl-db": "~3.1.1", @@ -15100,7 +15100,7 @@ }, "packages/db-states-redis": { "name": "@iobroker/db-states-redis", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "dependencies": { "@iobroker/db-base": "file:../db-base", @@ -15112,7 +15112,7 @@ }, "packages/types-dev": { "name": "@iobroker/types-dev", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "engines": { "node": ">=12.0.0" @@ -15120,7 +15120,7 @@ }, "packages/types-public": { "name": "@iobroker/types", - "version": "6.0.7", + "version": "6.0.7-alpha.0-20240702-5c723a4ac", "license": "MIT", "devDependencies": { "tsd": "^0.24.1" diff --git a/packages/adapter/package.json b/packages/adapter/package.json index 8f56a33eb3..c3ab6520b7 100644 --- a/packages/adapter/package.json +++ b/packages/adapter/package.json @@ -15,7 +15,8 @@ "@iobroker/db-states-redis": "file:../db-states-redis", "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", + "@iobroker/plugin-base": "~1.2.1", + "@iobroker/plugin-sentry": "~1.2.1", "deep-clone": "^3.0.3", "fs-extra": "^11.1.0", "jsonwebtoken": "^9.0.0", diff --git a/packages/adapter/src/lib/adapter/adapter.ts b/packages/adapter/src/lib/adapter/adapter.ts index 1e96e40353..bee06b2794 100644 --- a/packages/adapter/src/lib/adapter/adapter.ts +++ b/packages/adapter/src/lib/adapter/adapter.ts @@ -10966,8 +10966,8 @@ export class AdapterClass extends EventEmitter { if (this.pluginHandler.isPluginActive(pluginName) !== state.val) { if (state.val) { - if (!this.pluginHandler.isPluginInstantiated(pluginName)) { - this.pluginHandler.instantiatePlugin( + if (!this.pluginHandler.isPluginInstanciated(pluginName)) { + this.pluginHandler.instanciatePlugin( pluginName, this.pluginHandler.getPluginConfig(pluginName) || {}, thisDir @@ -11403,310 +11403,316 @@ export class AdapterClass extends EventEmitter { return; } this.pluginHandler.setDatabaseForPlugins(this.#objects, this.#states); - await this.pluginHandler.initPlugins(adapterConfig || {}); - if (!this.#states || !this.#objects || this.terminated) { - // if adapterState was destroyed,we should not continue - return; - } + this.pluginHandler.initPlugins(adapterConfig || {}, async () => { + if (!this.#states || !this.#objects || this.terminated) { + // if adapterState was destroyed,we should not continue + return; + } - this.#states.subscribe(`system.adapter.${this.namespace}.plugins.*`); - if (this._options.instance === undefined) { - if (!adapterConfig || !('common' in adapterConfig) || !adapterConfig.common.enabled) { - if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.enabled !== undefined) { - !this._config.isInstall && this._logger.error(`${this.namespaceLog} adapter disabled`); - } else { - !this._config.isInstall && this._logger.error(`${this.namespaceLog} no config found for adapter`); - } + this.#states.subscribe(`system.adapter.${this.namespace}.plugins.*`); + if (this._options.instance === undefined) { + if (!adapterConfig || !('common' in adapterConfig) || !adapterConfig.common.enabled) { + if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.enabled !== undefined) { + !this._config.isInstall && this._logger.error(`${this.namespaceLog} adapter disabled`); + } else { + !this._config.isInstall && + this._logger.error(`${this.namespaceLog} no config found for adapter`); + } - if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) { - const id = `system.adapter.${this.namespace}`; - this.outputCount += 2; - this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id }); - let done = false; - this.#states.setState( - `${id}.connected`, - { - val: true, - ack: true, - expire: 30, - from: id - }, - () => { + if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) { + const id = `system.adapter.${this.namespace}`; + this.outputCount += 2; + this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id }); + let done = false; + this.#states.setState( + `${id}.connected`, + { + val: true, + ack: true, + expire: 30, + from: id + }, + () => { + if (!done) { + done = true; + this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND); + } + } + ); + setTimeout(() => { if (!done) { done = true; this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND); } - } - ); - setTimeout(() => { - if (!done) { - done = true; - this.terminate(EXIT_CODES.NO_ADAPTER_CONFIG_FOUND); - } - }, 1_000); - return; + }, 1_000); + return; + } } - } - - if (!this._config.isInstall && (!adapterConfig || !('_id' in adapterConfig))) { - this._logger.error(`${this.namespaceLog} invalid config: no _id found`); - this.terminate(EXIT_CODES.INVALID_ADAPTER_ID); - return; - } - - let name; - let instance; - if (!this._config.isInstall) { - // @ts-expect-error - const tmp = adapterConfig._id.match(/^system\.adapter\.([a-zA-Z0-9-_]+)\.([0-9]+)$/); - if (!tmp) { - this._logger.error(`${this.namespaceLog} invalid config`); + if (!this._config.isInstall && (!adapterConfig || !('_id' in adapterConfig))) { + this._logger.error(`${this.namespaceLog} invalid config: no _id found`); this.terminate(EXIT_CODES.INVALID_ADAPTER_ID); return; } - name = tmp[1]; - instance = parseInt(tmp[2]) || 0; - } else { - name = this.name; - instance = 0; - adapterConfig = adapterConfig || { - // @ts-expect-error protectedNative exists on instance objects - common: { mode: 'once', name: name, protectedNative: [] }, - native: {} - }; - } - // @ts-expect-error - if (adapterConfig.common.loglevel && !this.overwriteLogLevel) { - // set configured in DB log level - for (const trans of Object.values(this._logger.transports)) { - // set the loglevel on transport only if no loglevel was pinned in log config - // @ts-expect-error it is our own modification - if (!trans._defaultConfigLoglevel) { - // @ts-expect-error - trans.level = adapterConfig.common.loglevel; + let name; + let instance; + + if (!this._config.isInstall) { + // @ts-expect-error + const tmp = adapterConfig._id.match(/^system\.adapter\.([a-zA-Z0-9-_]+)\.([0-9]+)$/); + if (!tmp) { + this._logger.error(`${this.namespaceLog} invalid config`); + this.terminate(EXIT_CODES.INVALID_ADAPTER_ID); + return; } + name = tmp[1]; + instance = parseInt(tmp[2]) || 0; + } else { + name = this.name; + instance = 0; + adapterConfig = adapterConfig || { + // @ts-expect-error protectedNative exists on instance objects + common: { mode: 'once', name: name, protectedNative: [] }, + native: {} + }; } - // @ts-expect-error - this._config.log.level = adapterConfig.common.loglevel; - } - // @ts-expect-error - this.name = adapterConfig.common.name; - this.instance = instance; - this.namespace = `${name}.${instance}`; - this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`); - if (!this.startedInCompactMode) { - process.title = `io.${this.namespace}`; - } + // @ts-expect-error + if (adapterConfig.common.loglevel && !this.overwriteLogLevel) { + // set configured in DB log level + for (const trans of Object.values(this._logger.transports)) { + // set the loglevel on transport only if no loglevel was pinned in log config + // @ts-expect-error it is our own modification + if (!trans._defaultConfigLoglevel) { + // @ts-expect-error + trans.level = adapterConfig.common.loglevel; + } + } + // @ts-expect-error + this._config.log.level = adapterConfig.common.loglevel; + } - // @ts-expect-error - this.config = adapterConfig.native; - // @ts-expect-error - this.host = adapterConfig.common.host; - // @ts-expect-error - this.common = adapterConfig.common; + // @ts-expect-error + this.name = adapterConfig.common.name; + this.instance = instance; + this.namespace = `${name}.${instance}`; + this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`); + if (!this.startedInCompactMode) { + process.title = `io.${this.namespace}`; + } - if ( // @ts-expect-error - adapterConfig.common.mode === 'schedule' || + this.config = adapterConfig.native; // @ts-expect-error - adapterConfig.common.mode === 'once' - ) { - this.stop = params => this._stop({ ...params, isPause: true }); - } else if (this.startedInCompactMode) { - this.stop = params => this._stop({ ...params, isPause: false }); - this.kill = this.stop; - } else { - this.stop = params => this._stop({ ...params, isPause: false }); - } + this.host = adapterConfig.common.host; + // @ts-expect-error + this.common = adapterConfig.common; - // Monitor logging state - this.#states.subscribe(`${SYSTEM_ADAPTER_PREFIX}*.logging`); + if ( + // @ts-expect-error + adapterConfig.common.mode === 'schedule' || + // @ts-expect-error + adapterConfig.common.mode === 'once' + ) { + this.stop = params => this._stop({ ...params, isPause: true }); + } else if (this.startedInCompactMode) { + this.stop = params => this._stop({ ...params, isPause: false }); + this.kill = this.stop; + } else { + this.stop = params => this._stop({ ...params, isPause: false }); + } - if ( - typeof this._options.message === 'function' && - // @ts-expect-error, we should infer correctly that this is an InstanceObject in this case - !isMessageboxSupported(adapterConfig.common) - ) { - this._logger.error( - `${this.namespaceLog} : message handler implemented, but messagebox not enabled. Define common.messagebox in io-package.json for adapter or delete message handler.` - ); - // @ts-expect-error we should infer adapterConfig correctly - } else if (isMessageboxSupported(adapterConfig.common)) { - this.mboxSubscribed = true; - this.#states.subscribeMessage(`system.adapter.${this.namespace}`); + // Monitor logging state + this.#states.subscribe(`${SYSTEM_ADAPTER_PREFIX}*.logging`); + + if ( + typeof this._options.message === 'function' && + // @ts-expect-error, we should infer correctly that this is an InstanceObject in this case + !isMessageboxSupported(adapterConfig.common) + ) { + this._logger.error( + `${this.namespaceLog} : message handler implemented, but messagebox not enabled. Define common.messagebox in io-package.json for adapter or delete message handler.` + ); + // @ts-expect-error we should infer adapterConfig correctly + } else if (isMessageboxSupported(adapterConfig.common)) { + this.mboxSubscribed = true; + this.#states.subscribeMessage(`system.adapter.${this.namespace}`); + } + } else { + // @ts-expect-error + this.name = adapterConfig.name || this.name; + // @ts-expect-error + this.instance = adapterConfig.instance || 0; + this.namespace = `${this.name}.${this.instance!}`; + this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`); + // @ts-expect-error + this.config = adapterConfig.native || {}; + // @ts-expect-error + this.common = adapterConfig.common || {}; + this.host = this.common?.host || tools.getHostName() || os.hostname(); } - } else { - // @ts-expect-error - this.name = adapterConfig.name || this.name; - // @ts-expect-error - this.instance = adapterConfig.instance || 0; - this.namespace = `${this.name}.${this.instance!}`; - this.namespaceLog = this.namespace + (this.startedInCompactMode ? ' (COMPACT)' : ` (${process.pid})`); - // @ts-expect-error - this.config = adapterConfig.native || {}; - // @ts-expect-error - this.common = adapterConfig.common || {}; - this.host = this.common?.host || tools.getHostName() || os.hostname(); - } - this.adapterConfig = adapterConfig; + this.adapterConfig = adapterConfig; - this._utils = new Validator( - this.#objects, - this.#states, - this.namespaceLog, - this._logger, - this.namespace, - this._namespaceRegExp - ); + this._utils = new Validator( + this.#objects, + this.#states, + this.namespaceLog, + this._logger, + this.namespace, + this._namespaceRegExp + ); - this.log = new Log(this.namespaceLog, this._config.log.level, this._logger); + this.log = new Log(this.namespaceLog, this._config.log.level, this._logger); - await this._createInstancesObjects(adapterConfig as ioBroker.InstanceObject); + await this._createInstancesObjects(adapterConfig as ioBroker.InstanceObject); - // auto oObjects - if (this._options.objects) { - this.oObjects = await this.getAdapterObjectsAsync(); - await this.subscribeObjectsAsync('*'); - } + // auto oObjects + if (this._options.objects) { + this.oObjects = await this.getAdapterObjectsAsync(); + await this.subscribeObjectsAsync('*'); + } - // initialize the system secret - await this.getSystemSecret(); + // initialize the system secret + await this.getSystemSecret(); - // Decrypt all attributes of encryptedNative - const promises = []; - // @ts-expect-error - if (Array.isArray(adapterConfig.encryptedNative)) { + // Decrypt all attributes of encryptedNative + const promises = []; // @ts-expect-error - for (const attr of adapterConfig.encryptedNative) { - // we can only decrypt strings + if (Array.isArray(adapterConfig.encryptedNative)) { // @ts-expect-error - if (typeof this.config[attr] === 'string') { - promises.push( - this.getEncryptedConfig(attr) - // @ts-expect-error - .then(decryptedValue => (this.config[attr] = decryptedValue)) - .catch(e => - this._logger.error( - `${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}` + for (const attr of adapterConfig.encryptedNative) { + // we can only decrypt strings + // @ts-expect-error + if (typeof this.config[attr] === 'string') { + promises.push( + this.getEncryptedConfig(attr) + // @ts-expect-error + .then(decryptedValue => (this.config[attr] = decryptedValue)) + .catch(e => + this._logger.error( + `${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}` + ) ) - ) - ); + ); + } + } + } else { + // remove encrypted native from supported features, otherwise this can cause issues, if no adapter upload done with js-c v3+ yet + const idx = this.SUPPORTED_FEATURES.indexOf('ADAPTER_AUTO_DECRYPT_NATIVE'); + if (idx !== -1) { + this.SUPPORTED_FEATURES.splice(idx, 1); } } - } else { - // remove encrypted native from supported features, otherwise this can cause issues, if no adapter upload done with js-c v3+ yet - const idx = this.SUPPORTED_FEATURES.indexOf('ADAPTER_AUTO_DECRYPT_NATIVE'); - if (idx !== -1) { - this.SUPPORTED_FEATURES.splice(idx, 1); - } - } - // Wait till all attributes decrypted - await Promise.all(promises); + // Wait till all attributes decrypted + await Promise.all(promises); - if (!this.#states) { - // if this.adapterStates was destroyed, we should not continue - return; - } - - this.outputCount++; - // set current loglevel - this.#states.setState(`system.adapter.${this.namespace}.logLevel`, { - val: this._config.log.level, - ack: true, - from: `system.adapter.${this.namespace}` - }); + if (!this.#states) { + // if this.adapterStates was destroyed, we should not continue + return; + } - if (this._options.instance === undefined) { - this.version = this.pack?.version - ? this.pack.version - : this.ioPack?.common - ? this.ioPack.common.version - : 'unknown'; - // display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm - // display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm - const isNpmVersion = isInstalledFromNpm({ - adapterName: this.name, - installedFrom: this.ioPack.common.installedFrom + this.outputCount++; + // set current loglevel + this.#states.setState(`system.adapter.${this.namespace}.logLevel`, { + val: this._config.log.level, + ack: true, + from: `system.adapter.${this.namespace}` }); - this._logger.info( - `${this.namespaceLog} starting. Version ${this.version} ${ - !isNpmVersion ? `(non-npm: ${this.ioPack.common.installedFrom}) ` : '' - }in ${this.adapterDir}, node: ${process.version}, js-controller: ${controllerVersion}` - ); - this._config.system = this._config.system || {}; - this._config.system.statisticsInterval = parseInt(this._config.system.statisticsInterval, 10) || 15_000; - if (!this._config.isInstall) { - this._reportInterval = setInterval(() => this._reportStatus(), this._config.system.statisticsInterval); - this._reportStatus(); - const id = `system.adapter.${this.namespace}`; - this.#states.setState(`${id}.compactMode`, { - ack: true, - from: id, - val: !!this.startedInCompactMode + if (this._options.instance === undefined) { + this.version = this.pack?.version + ? this.pack.version + : this.ioPack?.common + ? this.ioPack.common.version + : 'unknown'; + // display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm + const isNpmVersion = isInstalledFromNpm({ + adapterName: this.name, + installedFrom: this.ioPack.common.installedFrom }); - this.outputCount++; - - if (this.startedInCompactMode) { - this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 }); - this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 }); - this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id }); - this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id }); - this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id }); - this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id }); - this.outputCount += 6; - } else { - tools.measureEventLoopLag(1_000, lag => { - if (lag) { - this.eventLoopLags.push(lag); - } + this._logger.info( + `${this.namespaceLog} starting. Version ${this.version} ${ + !isNpmVersion ? `(non-npm: ${this.ioPack.common.installedFrom}) ` : '' + }in ${this.adapterDir}, node: ${process.version}, js-controller: ${controllerVersion}` + ); + this._config.system = this._config.system || {}; + this._config.system.statisticsInterval = parseInt(this._config.system.statisticsInterval, 10) || 15_000; + if (!this._config.isInstall) { + this._reportInterval = setInterval( + () => this._reportStatus(), + this._config.system.statisticsInterval + ); + this._reportStatus(); + const id = `system.adapter.${this.namespace}`; + this.#states.setState(`${id}.compactMode`, { + ack: true, + from: id, + val: this.startedInCompactMode }); + + this.outputCount++; + + if (this.startedInCompactMode) { + this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 }); + this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 }); + this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id }); + this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id }); + this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id }); + this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id }); + this.outputCount += 6; + } else { + tools.measureEventLoopLag(1_000, lag => { + if (lag) { + this.eventLoopLags.push(lag); + } + }); + } } } - } - if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.restartSchedule) { - try { - this._schedule = await import('node-schedule'); - } catch { - this._logger.error(`${this.namespaceLog} Cannot load node-schedule. Scheduled restart is disabled`); - } - if (this._schedule) { - this._logger.debug(`${this.namespaceLog} Schedule restart: ${adapterConfig.common.restartSchedule}`); - this._restartScheduleJob = this._schedule.scheduleJob(adapterConfig.common.restartSchedule, () => { - this._logger.info(`${this.namespaceLog} Scheduled restart.`); - this._stop({ isPause: false, isScheduled: true }); - }); + if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.restartSchedule) { + try { + this._schedule = await import('node-schedule'); + } catch { + this._logger.error(`${this.namespaceLog} Cannot load node-schedule. Scheduled restart is disabled`); + } + if (this._schedule) { + this._logger.debug( + `${this.namespaceLog} Schedule restart: ${adapterConfig.common.restartSchedule}` + ); + this._restartScheduleJob = this._schedule.scheduleJob(adapterConfig.common.restartSchedule, () => { + this._logger.info(`${this.namespaceLog} Scheduled restart.`); + this._stop({ isPause: false, isScheduled: true }); + }); + } } - } - // auto oStates - if (this._options.states) { - this.getStates('*', null, (err, _states) => { - if (this._stopInProgress) { - return; - } + // auto oStates + if (this._options.states) { + this.getStates('*', null, (err, _states) => { + if (this._stopInProgress) { + return; + } - this.oStates = _states; - this.subscribeStates('*'); + this.oStates = _states; + this.subscribeStates('*'); - if (this._firstConnection) { - this._firstConnection = false; - this._callReadyHandler(); - } + if (this._firstConnection) { + this._firstConnection = false; + this._callReadyHandler(); + } + this.adapterReady = true; + }); + } else if (!this._stopInProgress) { + this._callReadyHandler(); this.adapterReady = true; - }); - } else if (!this._stopInProgress) { - this._callReadyHandler(); - this.adapterReady = true; - } + } + }); } /** diff --git a/packages/cli/package.json b/packages/cli/package.json index e50397a536..6f1c3a54fd 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -8,7 +8,6 @@ "dependencies": { "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", "axios": "^1.6.3", "chokidar": "^3.5.3", "debug": "^4.3.4", diff --git a/packages/cli/src/lib/setup/dbConnection.ts b/packages/cli/src/lib/setup/dbConnection.ts index edc9797cad..499177d113 100644 --- a/packages/cli/src/lib/setup/dbConnection.ts +++ b/packages/cli/src/lib/setup/dbConnection.ts @@ -379,7 +379,7 @@ export async function exitApplicationSave(exitCode?: number): Promise { * * @param config - parsed content of iobroker.json */ -async function initializePlugins(config: Record): Promise { +function initializePlugins(config: Record): Promise { const ioPackage = fs.readJsonSync(path.join(tools.getControllerDir(), 'io-package.json')); const packageJson = fs.readJsonSync(path.join(tools.getControllerDir(), 'package.json')); const hostname = tools.getHostName(); @@ -413,7 +413,9 @@ async function initializePlugins(config: Record): Promise { pluginHandler.addPlugins(config.plugins, tools.getControllerDir()); // ... plugins from iobroker.json pluginHandler.setDatabaseForPlugins(objects, states); - await pluginHandler.initPlugins(ioPackage); + return new Promise(resolve => { + pluginHandler.initPlugins(ioPackage, () => resolve()); + }); } /** diff --git a/packages/controller/package.json b/packages/controller/package.json index caa53c0dd3..508544e847 100644 --- a/packages/controller/package.json +++ b/packages/controller/package.json @@ -20,8 +20,8 @@ "@iobroker/js-controller-cli": "file:../cli", "@iobroker/js-controller-common": "file:../common", "@iobroker/js-controller-common-db": "file:../common-db", - "@iobroker/plugin-base": "~2.0.1", - "@iobroker/plugin-sentry": "~2.0.4", + "@iobroker/plugin-base": "~1.2.1", + "@iobroker/plugin-sentry": "~1.2.1", "axios": "^1.6.3", "cron-parser": "^4.9.0", "debug": "^4.3.4", diff --git a/packages/controller/src/main.ts b/packages/controller/src/main.ts index 893f187f46..59b17dbc4b 100644 --- a/packages/controller/src/main.ts +++ b/packages/controller/src/main.ts @@ -39,7 +39,6 @@ import { SYSTEM_REPOSITORIES_ID } from '@iobroker/js-controller-common-db/constants'; import { PluginHandler } from '@iobroker/plugin-base'; -import type SentryPlugin from '@iobroker/plugin-sentry'; import { BlocklistManager } from '@/lib/blocklistManager.js'; import type { Client as ObjectsClient } from '@iobroker/db-objects-redis'; import type { Client as StatesClient } from '@iobroker/db-states-redis'; @@ -614,8 +613,8 @@ function createStates(onConnect: () => void): void { } if (pluginHandler.isPluginActive(pluginName) !== state.val) { if (state.val) { - if (!pluginHandler.isPluginInstantiated(pluginName)) { - pluginHandler.instantiatePlugin( + if (!pluginHandler.isPluginInstanciated(pluginName)) { + pluginHandler.instanciatePlugin( pluginName, pluginHandler.getPluginConfig(pluginName)!, controllerDir @@ -710,15 +709,16 @@ async function initializeController(): Promise { connected = true; if (!isStopping) { pluginHandler.setDatabaseForPlugins(objects, states); - await pluginHandler.initPlugins(ioPackage); - states!.subscribe(`${hostObjectPrefix}.plugins.*`); - - // Do not start if we're still stopping the instances - await checkHost(); - startMultihost(config); - setMeta(); - started = true; - getInstances(); + pluginHandler.initPlugins(ioPackage, async () => { + states!.subscribe(`${hostObjectPrefix}.plugins.*`); + + // Do not start if we're still stopping the instances + await checkHost(); + startMultihost(config); + setMeta(); + started = true; + getInstances(); + }); } } else { connected = true; @@ -3012,9 +3012,8 @@ async function processMessage(msg: ioBroker.SendableMessage): Promise = msg.message.extraInfo; - const sentryObj = ( - pluginHandler.getPluginInstance('sentry') as InstanceType | null - )?.getSentryObject(); + // @ts-expect-error Plugin is not well typed and SentryPlugin has no types at all currently + const sentryObj = pluginHandler.getPluginInstance('sentry')?.getSentryObject(); if (!sentryObj) { logger.debug(`${hostLogPrefix} Do not send message "${message}" to Sentry, because it is disabled`);