Skip to content

Commit 21c120b

Browse files
committed
refactor: raw spawn to instead of helper.spawn in start nondaemon mode
1 parent 22faa4c commit 21c120b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/cmd/start.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,27 @@ class StartCommand extends Command {
161161
// check start status
162162
yield this.checkStatus(argv);
163163
} else {
164-
// signal event had been handler at common-bin helper
165-
this.helper.spawn('node', eggArgs, options);
164+
options.stdio = options.stdio || 'inherit';
165+
this.logger.debug('Run spawn `node %s`', eggArgs.join(' '));
166+
const child = this.child = spawn('node', eggArgs, options);
167+
child.once('exit', code => {
168+
if (code !== 0) {
169+
child.emit('error', new Error(`spawn node ${eggArgs.join(' ')} fail, exit code: ${code}`));
170+
}
171+
});
172+
173+
// attach master signal to child
174+
let signal;
175+
[ 'SIGINT', 'SIGQUIT', 'SIGTERM' ].forEach(event => {
176+
process.once(event, () => {
177+
signal = event;
178+
process.exit(0);
179+
});
180+
});
181+
process.once('exit', () => {
182+
this.logger.debug('Kill child %s with %s', child.pid, signal);
183+
child.kill(signal);
184+
});
166185
}
167186
}
168187

0 commit comments

Comments
 (0)