-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { | ||
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. 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); | ||
}); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
。