diff --git a/packages/embark-core/src/processes/processManager.js b/packages/embark-core/src/processes/processManager.js index 64f2a97c4..49b4ac36a 100644 --- a/packages/embark-core/src/processes/processManager.js +++ b/packages/embark-core/src/processes/processManager.js @@ -23,6 +23,7 @@ export class ProcessManager { this._registerApiCalls(); this._registerEvents(); + this.events.once("deploy:beforeAll", this._registerCommands.bind(this)); } _registerApiCalls() { @@ -67,6 +68,48 @@ export class ProcessManager { return processList; } + _registerCommands() { + // do not allow whisper service to be started/stopped as it requires a restart of embark + const availableProcesses = Object.keys(this.processes).filter((name) => !["whisper", "embark"].includes(name.toLowerCase())); + this.plugin.registerConsoleCommand({ + description: __(`Starts/stops the process. Options: ${availableProcesses.join(", ")}`), + matches: (cmd) => { + return availableProcesses.some((name) => { + name = name.toLowerCase(); + return [`service ${name} on`, `service ${name} off`].includes(cmd.toLowerCase()); + }); + }, + usage: `service [process] on/off`, + process: (cmd, callback) => { + const enable = cmd.trim().endsWith('on'); + const matches = cmd.match(/^service[\s](.*)[\s](?:on|off)$/) || []; + const name = matches[1]; + this.logger.info(`${enable ? 'Starting' : 'Stopping'} the ${name} process...`); + if(enable) { + return this.events.request("processes:launch", name, (...args) => { + const err = args[0]; + if (err) { + this.logger.error(err); // writes to embark's console + return callback(err); // passes message back to cockpit + } + const process = this.processes[name]; + if (process && process.afterLaunchFn) { + process.afterLaunchFn.apply(process.afterLaunchFn, args); + } + callback(err, `${name} process started.`); // passes a message back to cockpit console + }); + } + this.events.request("processes:stop", name, (err) => { + if (err) { + this.logger.error(err); // writes to embark's console + callback(err); // passes message back to cockpit + } + callback(err, `${name} process stopped.`); // passes a message back to cockpit console + }); + } + }); + } + _registerEvents() { const self = this; self.events.setCommandHandler('processes:register', (name, cb) => { @@ -84,31 +127,6 @@ export class ProcessManager { cb: launchFn || cb, stopFn: stopFn || function noop () {} }; - - this.plugin.registerConsoleCommand({ - description: __(`Starts/stops the ${name} process`), - matches: [`service ${name} on`, `service ${name} off`], - usage: `service ${name} on/off`, - process: (cmd, callback) => { - const enable = cmd.trim().endsWith('on'); - this.logger.info(`${enable ? 'Starting' : 'Stopping'} the ${name} process...`); - if(enable) { - return this.events.request("processes:launch", name, (...args) => { - const err = args[0]; - if (err) return this.logger.error(err); // writes to embark's console - const process = self.processes[name]; - if(process && process.afterLaunchFn) { - process.afterLaunchFn.apply(process.afterLaunchFn, args); - } - callback(err, `${name} process started.`); // passes a message back to cockpit console - }); - } - this.events.request("processes:stop", name, (err) => { - if (err) return this.logger.error(err); // writes to embark's console - callback(err, `${name} process stopped.`); // passes a message back to cockpit console - }); - } - }); }); self.events.setCommandHandler('processes:launch', (name, cb) => { diff --git a/site/source/docs/using_the_console.md b/site/source/docs/using_the_console.md index 1fe1e4b45..cf64e3ae4 100644 --- a/site/source/docs/using_the_console.md +++ b/site/source/docs/using_the_console.md @@ -36,9 +36,26 @@ Embark (development) > help This is a good time to read a bit through the available commands and familiarize yourself with them. -## Enabling and disabling process logs +## Enabling and disabling processes -There are several processes and services that Embark spins up to do its work (e.g. `geth` for blockchain process, `ipfs` as storage daemon etc). Those are the same processes that are listed as "Available Services" in the dashboard. +There are several processes and services that Embark spins up to do its work (e.g. `geth` for blockchain process, `ipfs` as storage daemon, etc). Those are the same processes that are listed as "Available Services" in the dashboard. + +These processes can be enabled and disabled using the `service` command. + +Simply specify the process and turn it `on` or `off`: + +``` +Embark (development) > service ipfs off +``` + +The "Available Services" in the dashboard as well as Cockpit's dashboard will reflect the status of the processes as they are enabled and disabled. + +NOTE: There are two processes that cannot be started and stopped via console commands: +1. **Embark** - The Embark process cannot stop and start itself. +2. **Whisper** - Whisper cannot be started and stopped via a command because the blockchain process CLI parameters need to be modified and the blockchain process itself would need to be restarted. To disable Whisper, set `enabled: false` in the communications config, then restart Embark. To enable Whisper, set `enabled: true` in the communications config, then restart Embark. + + +## Enabling and disabling process logs By default, Embark will log output from all processes into the console. Since this can get quite verbose sometimes, we can disable logging for certain processes using the `log` command.