feat(@embark/whisper): Remove support for `service whisper on/off`

Remove support for `service whisper on/off` because Whisper cannot be started without first disabling it in the communications config, then restarting Embark.

Add documentation for the `service [process] on/off` command

This command was only added a few commits back so it is not considered a breaking change.

Refactor the `service [process] on/off` commands so that there is only one command. Previously we had a command registered for each process, ie:
```
service blockchain on/off
service ipfs on/off
…
```

Now, we only have one command with many options:
```
service [process] on/off - Starts/stops the process. Options: blockchain, embark, ipfs, api
```

Whisper is deliberately not included in the available options for the aforementioned reasons.
This commit is contained in:
emizzle 2019-05-06 15:30:21 +10:00 committed by Pascal Precht
parent e3ecf68fbc
commit fc01daf3e9
2 changed files with 62 additions and 27 deletions

View File

@ -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) => {

View File

@ -36,9 +36,26 @@ Embark (development) > help<ENTER>
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.