Skip to content

Commit

Permalink
🐛 fix local installation
Browse files Browse the repository at this point in the history
closes TryGhost#368

- if you run `ghost start`, the CLI will spawn a detached process
- this detached process will spawn another process
- the `cp.pid` was wrong in any case
- forward the pid from the spawned process back to parent process
  • Loading branch information
kirrg001 committed Jul 20, 2017
1 parent 991e7e9 commit 678dd66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RunCommand extends Command {

this.child.on('message', (message) => {
if (message.started) {
instance.process.success();
instance.process.success({pid: this.child.pid});
return;
}

Expand Down
14 changes: 6 additions & 8 deletions lib/utils/local-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs-extra');
const path = require('path');
const fkill = require('fkill');
const extend = require('lodash/extend');
const spawn = require('child_process').spawn;
const assign = require('lodash/assign');
const isRunning = require('is-running');
Expand Down Expand Up @@ -40,13 +41,9 @@ class LocalProcess extends ProcessManager {
env: assign({}, process.env, {NODE_ENV: environment})
});

// Stick the pid into the pidfile so we can stop the process later
fs.writeFileSync(path.join(cwd, PID_FILE), cp.pid);

cp.on('error', reject);

cp.on('exit', (code) => {
fs.removeSync(path.join(cwd, PID_FILE));
reject(new errors.GhostError(`Ghost process exited with code: ${code}`));
});

Expand All @@ -59,11 +56,11 @@ class LocalProcess extends ProcessManager {
// Wait until Ghost tells us that it's started correctly, then resolve
cp.on('message', (msg) => {
if (msg.error) {
fs.removeSync(path.join(cwd, PID_FILE));

return reject(new errors.GhostError(msg));
}

fs.writeFileSync(path.join(cwd, PID_FILE), msg && msg.pid ? msg.pid : cp.pid);

if (msg.started) {
cp.disconnect();
cp.unref();
Expand Down Expand Up @@ -113,8 +110,9 @@ class LocalProcess extends ProcessManager {
* @method success
* @public
*/
success() {
if (process.send) {process.send({started: true});}
success(options) {
options = options || {};
if (process.send) {process.send(extend({started: true}, options));}
}

/**
Expand Down

0 comments on commit 678dd66

Please sign in to comment.