Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 37
refactor: raw spawn call to instead of helper.spawn in start non-daemon mode#23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,17 @@ | ||
| 'use strict'; | ||
| const path = require('path'); | ||
| const mkdirp = require('mz-modules/mkdirp'); | ||
| const sleep = require('mz-modules/sleep'); | ||
| const homedir = require('node-homedir'); | ||
| const utils = require('egg-utils'); | ||
| const fs = require('mz/fs'); | ||
| const Command = require('../command'); | ||
| const debug = require('debug')('egg-script:start'); | ||
| const { exec } = require('mz/child_process'); | ||
| const fs = require('mz/fs'); | ||
| const homedir = require('node-homedir'); | ||
| const mkdirp = require('mz-modules/mkdirp'); | ||
| const moment = require('moment'); | ||
| const sleep = require('mz-modules/sleep'); | ||
| const spawn = require('child_process').spawn; | ||
| const Command = require('../command'); | ||
| const utils = require('egg-utils'); | ||
| class StartCommand extends Command { | ||
| constructor(rawArgv) { | ||
| @@ -161,8 +163,27 @@ class StartCommand extends Command { | ||
| // check start status | ||
| yield this.checkStatus(argv); | ||
| } else { | ||
| // signal event had been handler at common-bin helper | ||
| this.helper.spawn('node', eggArgs, options); | ||
| options.stdio = options.stdio || 'inherit'; | ||
| debug('Run spawn `node %s`', eggArgs.join(' ')); | ||
| const child = this.child = spawn('node', eggArgs, options); | ||
| child.once('exit', code => { | ||
| if (code !== 0) { | ||
| child.emit('error', new Error(`spawn node ${eggArgs.join(' ')} fail, exit code: ${code}`)); | ||
| } | ||
| }); | ||
| // attach master signal to child | ||
| let signal; | ||
| [ 'SIGINT', 'SIGQUIT', 'SIGTERM' ].forEach(event => { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看起来好像这个库不支持 | ||
| process.once(event, () => { | ||
| signal = event; | ||
| process.exit(0); | ||
| }); | ||
| }); | ||
| process.once('exit', () => { | ||
| debug('Kill child %s with %s', child.pid, signal); | ||
| child.kill(signal); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是不是不需要这个配置了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原来的有什么问题?为什么不在 helper.spawn 加参数实现,而又在这里实现重复的逻辑代码?
背景问题是什么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fengmk2 要暴露出
child对象供上层监听使用。我跟天猪讨论后的方案有:helper里面的childs;helper里面年久失修,重构估计会变成 break,所以直接这一块逻辑替换。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helper 返回 child 不行?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helper里面是一个 Promise,要等子进程结束后才会被resolve。