|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const path = require('path'); |
4 | | -const mkdirp = require('mz-modules/mkdirp'); |
5 | | -const sleep = require('mz-modules/sleep'); |
6 | | -const homedir = require('node-homedir'); |
7 | | -const utils = require('egg-utils'); |
8 | | -const fs = require('mz/fs'); |
| 4 | + |
| 5 | +const Command = require('../command'); |
| 6 | +const debug = require('debug')('egg-script:start'); |
9 | 7 | const { exec } = require('mz/child_process'); |
| 8 | +const fs = require('mz/fs'); |
| 9 | +const homedir = require('node-homedir'); |
| 10 | +const mkdirp = require('mz-modules/mkdirp'); |
10 | 11 | const moment = require('moment'); |
| 12 | +const sleep = require('mz-modules/sleep'); |
11 | 13 | const spawn = require('child_process').spawn; |
12 | | -const Command = require('../command'); |
| 14 | +const utils = require('egg-utils'); |
13 | 15 |
|
14 | 16 | class StartCommand extends Command { |
15 | 17 | constructor(rawArgv) { |
@@ -161,8 +163,27 @@ class StartCommand extends Command { |
161 | 163 | // check start status |
162 | 164 | yield this.checkStatus(argv); |
163 | 165 | } else { |
164 | | - // signal event had been handler at common-bin helper |
165 | | - this.helper.spawn('node', eggArgs, options); |
| 166 | + options.stdio = options.stdio || 'inherit'; |
| 167 | + debug('Run spawn `node %s`', eggArgs.join(' ')); |
| 168 | + const child = this.child = spawn('node', eggArgs, options); |
| 169 | + child.once('exit', code => { |
| 170 | + if (code !== 0) { |
| 171 | + child.emit('error', new Error(`spawn node ${eggArgs.join(' ')} fail, exit code: ${code}`)); |
| 172 | + } |
| 173 | + }); |
| 174 | + |
| 175 | + // attach master signal to child |
| 176 | + let signal; |
| 177 | + [ 'SIGINT', 'SIGQUIT', 'SIGTERM' ].forEach(event => { |
| 178 | + process.once(event, () => { |
| 179 | + signal = event; |
| 180 | + process.exit(0); |
| 181 | + }); |
| 182 | + }); |
| 183 | + process.once('exit', () => { |
| 184 | + debug('Kill child %s with %s', child.pid, signal); |
| 185 | + child.kill(signal); |
| 186 | + }); |
166 | 187 | } |
167 | 188 | } |
168 | 189 |
|
|
0 commit comments