-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
stop.js
69 lines (56 loc) · 1.97 KB
/
stop.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Command = require('../command');
class StopCommand extends Command {
static configureOptions(commandName, yargs, extensions) {
const get = require('lodash/get');
const omit = require('lodash/omit');
extensions.forEach((extension) => {
const options = get(extension, 'config.options.stop', false);
if (!options) {
return;
}
Object.assign(this.options, omit(options, Object.keys(this.options)));
});
yargs = super.configureOptions(commandName, yargs, extensions);
return yargs;
}
async run(argv) {
const getInstance = require('../utils/get-instance');
const runOptions = {quiet: argv.quiet};
if (argv.all) {
return this.stopAll();
}
const instance = getInstance({
name: argv.name,
system: this.system,
command: 'stop',
recurse: !argv.dir
});
const isRunning = await instance.isRunning();
if (!isRunning) {
this.ui.log('Ghost is already stopped! For more information, run', 'ghost ls', 'green', 'cmd', true);
return;
}
await this.ui.run(() => instance.stop(argv.disable), `Stopping Ghost: ${instance.name}`, runOptions);
}
async stopAll() {
const instances = this.system.getAllInstances(true);
for (const {name} of instances) {
await this.ui.run(() => this.run({quiet: true, name}), `Stopping Ghost: ${name}`);
}
}
}
StopCommand.description = 'Stops an instance of Ghost';
StopCommand.params = '[name]';
StopCommand.options = {
all: {
alias: 'a',
description: 'option to stop all running Ghost blogs',
type: 'boolean'
},
disable: {
description: 'Disable restarting Ghost on server reboot (if the process manager supports it)',
type: 'boolean'
}
};
StopCommand.global = true;
module.exports = StopCommand;