@iobroker/js-controller-cli 4.0.0-alpha.42-20220108-6954bae6 → 4.0.0-alpha.46-20220119-9e487e55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  const CLI = require('./messages.js');
3
3
  const CLICommand = require('./cliCommand.js');
4
4
  const CLITools = require('./cliTools');
5
- const { tools } = require('@iobroker/js-controller-common');
5
+ const { tools, EXIT_CODES } = require('@iobroker/js-controller-common');
6
6
  const child_process = require('child_process');
7
7
 
8
8
  /** Command ioBroker debug ... */
@@ -12,6 +12,32 @@ module.exports = class CLICompact extends CLICommand {
12
12
  super(options);
13
13
  }
14
14
 
15
+ /**
16
+ * Cehcks if the adpter instance is running
17
+ *
18
+ * @param {string} adapter
19
+ * @param {string} instance
20
+ * @return {Promise<boolean>}
21
+ * @private
22
+ */
23
+ _isInstanceRunning(adapter, instance) {
24
+ const { dbConnect } = this.options;
25
+ return new Promise(resolve => {
26
+ dbConnect(async (objects, states) => {
27
+ try {
28
+ const state = await states.getStateAsync(`system.adapter.${adapter}.${instance}.alive`);
29
+ if (state && state.val) {
30
+ resolve(true);
31
+ return;
32
+ }
33
+ } catch {
34
+ // ignore
35
+ }
36
+ resolve(false);
37
+ });
38
+ });
39
+ }
40
+
15
41
  /**
16
42
  * Executes a command
17
43
  * @param {any[]} args
@@ -24,7 +50,12 @@ module.exports = class CLICompact extends CLICommand {
24
50
  return void callback(34);
25
51
  }
26
52
 
27
- const { instance } = CLITools.splitAdapterOrInstanceIdentifierWithVersion(adapter);
53
+ const { name, instance } = CLITools.splitAdapterOrInstanceIdentifierWithVersion(adapter);
54
+
55
+ if (await this._isInstanceRunning(name, instance || '0')) {
56
+ CLI.error.instanceAlreadyRunning(`${name}.${instance || '0'}`);
57
+ return void callback(EXIT_CODES.ADAPTER_ALREADY_RUNNING);
58
+ }
28
59
 
29
60
  const adapterDir = tools.getAdapterDir(adapter);
30
61
  if (!adapterDir) {
@@ -51,6 +51,7 @@ function validateAdapterOrInstanceIdentifier(name) {
51
51
  * Ensures that the given string contains a valid identifier for
52
52
  * an adapter (without instance number) or instance (with instance number)
53
53
  * @param {string} name
54
+ * @return {{name: string, instance:string|null, version: string|null, nameWithVersion:string}|null}
54
55
  */
55
56
  function splitAdapterOrInstanceIdentifierWithVersion(name) {
56
57
  const res = name.match(/^([a-z0-9\-_]+)\.?(\d+)?@?([a-z0-9\-_.]*)?$/);
@@ -53,7 +53,8 @@ const errorMessages = Object.freeze({
53
53
  pluginNotDefined: (pluginName, host, instance) =>
54
54
  `The plugin "${pluginName}" does not exist for ${host ? `host "${host}"` : `instance "${instance}"`}!`,
55
55
 
56
- cert: certName => `Certificate "${certName}" not found or error parsing certificate information.`
56
+ cert: certName => `Certificate "${certName}" not found or error parsing certificate information.`,
57
+ instanceAlreadyRunning: instance => `The instance "${instance}" is already running, please stop instance first.`
57
58
  });
58
59
 
59
60
  const successMessages = Object.freeze({
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@iobroker/js-controller-cli",
3
- "version": "4.0.0-alpha.42-20220108-6954bae6",
3
+ "version": "4.0.0-alpha.46-20220119-9e487e55",
4
4
  "engines": {
5
5
  "node": ">=12.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@iobroker/js-controller-common": "4.0.0-alpha.42-20220108-6954bae6",
9
- "@iobroker/js-controller-common-db": "4.0.0-alpha.42-20220108-6954bae6",
8
+ "@iobroker/js-controller-common": "4.0.0-alpha.46-20220119-9e487e55",
9
+ "@iobroker/js-controller-common-db": "4.0.0-alpha.46-20220119-9e487e55",
10
10
  "chokidar": "^3.5.2",
11
11
  "daemonize2": "^0.4.2",
12
12
  "debug": "^4.3.3",
@@ -38,5 +38,5 @@
38
38
  "lib/",
39
39
  "index.js"
40
40
  ],
41
- "gitHead": "229f20713ea9e603745acdaeb8e90841ebdbd3cf"
41
+ "gitHead": "e081e38bf6d24e767e16a0bb5a8d8202f65a9302"
42
42
  }