Skip to content
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

feat: stop command support windows #22

Merged
merged 5 commits into from
Jul 11, 2018
Merged

Conversation

BaffinLee
Copy link
Contributor

@BaffinLee BaffinLee commented Jul 6, 2018

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

stop command supports windows now.

Description of change

Adjust find process command and filter logic to support windows, done simple than other pr.

Tested on Windows 7 and Windows 10, works fine.

By the way, the npm run test wouldn't pass even if I don't change anything, which I didn't dig in.

@codecov
Copy link

codecov bot commented Jul 6, 2018

Codecov Report

Merging #22 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #22   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           6      6           
  Lines         187    190    +3     
=====================================
+ Hits          187    190    +3
Impacted Files Coverage Δ
lib/cmd/stop.js 100% <100%> (ø) ⬆️
lib/helper.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82f4125...908efbe. Read the comment docs.


exports.findNodeProcess = function* (filterFn) {
const command = 'ps -eo "pid,command"';
const command = isWin ?
'wmic Path win32_process Where "Name = \'node.exe\'" Get CommandLine,ProcessId' :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not familiar with Windows, is wmic a buildin command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from Microsoft offical docs, but I am not sure about Windows XP.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems good

Copy link
Member

@atian25 atian25 Jul 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had try https://www.npmjs.com/package/find-process long long ago.
but got some trouble:

  • XML invalid at some win10.
  • backslash convert confuse me at appveyor

so I give up.

@BaffinLee maybe you could help us try again ?

and you need to config package.json for egg-ci to gen appveyor.yml, so this feature could be test.

my commit: https://github.com/eggjs/egg-scripts/pull/1/commits

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atian25 It seems some people have the same issue about Invalid XML content. I can't figure out why, I have tested the script on 3 windows pc, works fine.

what about wmic Path win32_process Where "Name = 'node.exe'" Get CommandLine,ProcessId, output the same error ?

I am going to test it on appveyor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worker for most of the window user is better than nothing~

@BaffinLee
Copy link
Contributor Author

BaffinLee commented Jul 7, 2018

Passed every test case on appveyor, and travis-ci.

image

TODO:

  • find a replacement for tail command on windows. (not absolutly necessary)

By the way, I konw why I couldn't run test locally before, you guys use npminstall (cnpm) , but I use npm or yarn. I will fire a PR latter with detail.

@BaffinLee
Copy link
Contributor Author

@atian25 @popomore Got time to review?

const stdio = yield runScript(command, { stdio: 'pipe' });
const processList = stdio.stdout.toString().split('\n')
.reduce((arr, line) => {
if (!!line && !line.includes('/bin/sh') && line.includes('node')) {
const m = line.match(REGEX);
/* istanbul ignore else */
if (m) {
const item = { pid: m[1], cmd: m[2] };
const item = isWin ? { pid: m[2], cmd: m[1] } : { pid: m[1], cmd: m[2] };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just change Get CommandLine,ProcessId to Get ProcessId,CommandLine ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 after fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my test, ProcessId always show behind CommandLine, despite how you run the command.

So I just put ProcessId behind CommandLine, more clear, less confuse.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about change the ps of linux to make they the same order ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still confusing, Get CommandLine,ProcessId and Get ProcessId,CommandLine actually output the same thing, maybe I should add a comment in the code ? Got better idea? @atian25

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something wrong with the REGEXP in my final commit, I will switch to linux to test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird:

ps -eo pid,command works fine

fake@ubuntu$ ps -eo pid,command
  PID COMMAND
    1 /init ro
   24 ssh-agent
  205 /init ro
  206 -bash
 2956 /init ro
 2957 -bash
 5274 npm
 5284 sh -c npm run lint -- --fix && npm run pkgfiles && npm run test-local
 5325 npm
 5335 sh -c egg-bin test
 5336 node /mnt/c/Users/fake/code/egg-scripts/node_modules/.bin/egg-bin test
 5342 /usr/local/lib/nodejs/node/bin/node /mnt/c/Users/fake/code/egg-scripts/node_modules/egg-bin/node_modules/mocha/bin/_mocha --require=/mnt/c/Users/fake/code/egg-scripts/node_modules/egg-bin/lib/mocha-clean.js --require=/mnt/c/U...
 5595 node /mnt/c/Users/fake/code/egg-scripts/lib/start-cluster {"framework":"/mnt/c/Users/fake/code/egg-scripts/test/fixtures/example/node_modules/yadan","workers":2,"title":"egg-server-example","baseDir":"/mnt/c/Users/fake/cod...
 5680 /usr/local/lib/nodejs/node/bin/node /mnt/c/Users/fake/code/egg-scripts/bin/egg-scripts.js start --workers=2 --title=egg-test /mnt/c/Users/fake/code/egg-scripts/test/fixtures/example
 5690 node /mnt/c/Users/fake/code/egg-scripts/lib/start-cluster {"workers":2,"title":"egg-test","framework":"/mnt/c/Users/fake/code/egg-scripts/test/fixtures/example/node_modules/custom-framework","baseDir":"/mnt/c/Users/fake/co...
 5696 /usr/local/lib/nodejs/node/bin/node /mnt/c/Users/fake/code/egg-scripts/node_modules/egg-cluster/lib/agent_worker.js {"framework":"/mnt/c/Users/fake/code/egg-scripts/test/fixtures/example/node_modules/custom-framework","baseDi...
 5706 /usr/local/lib/nodejs/node/bin/node /mnt/c/Users/fake/code/egg-scripts/node_modules/egg-cluster/lib/app_worker.js {"framework":"/mnt/c/Users/fake/code/egg-scripts/test/fixtures/example/node_modules/custom-framework","baseDir"...
 5707 /usr/local/lib/nodejs/node/bin/node /mnt/c/Users/fake/code/egg-scripts/node_modules/egg-cluster/lib/app_worker.js {"framework":"/mnt/c/Users/fake/code/egg-scripts/test/fixtures/example/node_modules/custom-framework","baseDir"...

ps -eo command,pid faild: command was truncated

fake@ubuntu$ ps -eo command,pid
COMMAND                       PID
/init ro                        1
ssh-agent                      24
/init ro                      205
-bash                         206
/init ro                     2956
-bash                        2957
npm                          5274
sh -c npm run lint -- --fix  5284
npm                          5325
sh -c egg-bin test           5335
node /mnt/c/Users/fake/c     5336
/usr/local/lib/nodejs/node/  5342
node /mnt/c/Users/fake/c     5595
/usr/local/lib/nodejs/node/  5680
node /mnt/c/Users/fake/c     5690
/usr/local/lib/nodejs/node/  5696
/usr/local/lib/nodejs/node/  5706
/usr/local/lib/nodejs/node/  5707
ps -eo command,pid           5741

refer to how-to-prevent-ps-from-truncating-the-process-name, I think I should rollback :) ? or set column width like: ps -eo command:1000,pid ?

I'd like to rollback, any idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just rollback to last review, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atian25 done. Test on appveyor passed too.

@fengmk2
Copy link
Member

fengmk2 commented Jul 10, 2018

@BaffinLee
Copy link
Contributor Author

@fengmk2 done.

@atian25 atian25 merged commit 22faa4c into eggjs:master Jul 11, 2018
@@ -2,7 +2,7 @@

deploy tool for egg project.

**Note: Windows is not supported**
**Note: Windows is partially supported, see [#22](https://github.com/eggjs/egg-scripts/pull/22)**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • egg guide docs of deploy is also need to updated.
  • could raise anthoer PR to support start for win (if not tail instead, just ignore the checker at win)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR for egg's docs, #2788

@popomore
Copy link
Member

  • egg-scripts@2.7.0

@popomore popomore mentioned this pull request Aug 10, 2018
4 tasks
@waitingsong
Copy link

waitingsong commented Sep 4, 2018

有个现象, vscode 调试 egg 中,wmic 持续出现在系统任务列表中。大概3秒执行一次,每次0.3秒左右。
.vscode/launch.json:

    {
      "name": "Egg Debug",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run",
        "debug",
        "--",
        "--inspect-brk"
      ],
      "console": "integratedTerminal",
      "restart": true,
      "protocol": "auto",
      "port": 9229,
      "autoAttachChildProcesses": true
    },

单独运行 npm run debug 没发现有这状况。 这和 vscode 有关?

@BaffinLee
Copy link
Contributor Author

是吧,调试应该没用到 egg-scripts stop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants