Skip to content

Commit

Permalink
🎨 fix race conditions in start and stop commands
Browse files Browse the repository at this point in the history
no issue
- there were race conditions with the spinner, this PR delays the
actual calling of the process manager stop method by wrapping it in a
function
  • Loading branch information
acburdine committed Feb 28, 2017
1 parent 6a9aa24 commit a1d25e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ module.exports.execute = function execute(options) {

this.service.setConfig(config);

let start = Promise.resolve(this.service.process.start(process.cwd(), this.environment)).then(() => {
let start = () => Promise.resolve(this.service.process.start(process.cwd(), this.environment)).then(() => {
register(config, this.environment);
cliConfig.set('running', this.environment).save();
return Promise.resolve();
});

if (options.quiet) {
return start;
return start();
}

return this.ui.run(start, 'Starting Ghost').then(() => {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ function execute(options) {

let config = Config.load(cliConfig.get('running'));
this.service.setConfig(config);
let stop = Promise.resolve(this.service.process.stop(process.cwd())).then(() => {
let stop = () => Promise.resolve(this.service.process.stop(process.cwd())).then(() => {
deregister(config);
cliConfig.set('running', null).save();
return Promise.resolve();
});

if (options.quiet) {
return stop;
return stop();
}

return this.ui.run(stop, 'Stopping Ghost');
Expand Down
6 changes: 3 additions & 3 deletions lib/services/process/systemd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class SystemdProcess extends BaseProcess {
ghost_exec_path: process.argv.slice(0,2).join(' ')
}), 'utf8');

return this.ui.noSpin(execa.shell(`sudo mv ${serviceFilename} /lib/systemd/system`, {stdio: 'inherit'}).catch(() => {
return this.ui.noSpin(() => execa.shell(`sudo mv ${serviceFilename} /lib/systemd/system`, {stdio: 'inherit'}).catch(() => {
return Promise.reject('Ghost service file could not be put in place, ensure you have proper sudo permissions and systemd is installed.');
}));
}

start() {
return this.ui.noSpin(execa.shell(`sudo systemctl start ${this.systemdName}`, {stdio: 'inherit'}));
return this.ui.noSpin(() => execa.shell(`sudo systemctl start ${this.systemdName}`, {stdio: 'inherit'}));
}

stop() {
return this.ui.noSpin(execa.shell(`sudo systemctl stop ${this.systemdName}`, {stdio: 'inherit'}));
return this.ui.noSpin(() => execa.shell(`sudo systemctl stop ${this.systemdName}`, {stdio: 'inherit'}));
}

static willRun() {
Expand Down

0 comments on commit a1d25e8

Please sign in to comment.