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

How can i run server in daemon mode in Windows ? #2738

Closed
skyfore opened this issue Jun 27, 2018 · 9 comments
Closed

How can i run server in daemon mode in Windows ? #2738

skyfore opened this issue Jun 27, 2018 · 9 comments

Comments

@skyfore
Copy link

skyfore commented Jun 27, 2018

  • Node Version: v8.1.4
  • Egg Version: v2.2.1
  • Plugin Name:
  • Plugin Version:
  • Platform: Windows 10
  • Mini Showcase Repository:

你好,我在 Windows 下直接使用 egg-init 生成的一个 Egg 项目,然后使用 npm start 跑,会弹出很多个 CMD 界面。

但是,我期望的结果是,npm start 然后,控制台提示创建服务器成功后就可以关闭这个 cmd 窗口,而不是还会自动创建很多个 cmd 窗口。

望解答,感谢!

@atian25
Copy link
Member

atian25 commented Jun 27, 2018

跟 egg 关系不大,找下对应的 window service 相关资料,或者 docker

@atian25 atian25 closed this as completed Jun 27, 2018
@skyfore
Copy link
Author

skyfore commented Jun 27, 2018

@atian25 我网上搜索发现这个应该需要增加一个 windowsHide 的参数,然而 npm script 是由 egg-bin 来进行控制的, 所以我才会认为这个与 egg 有关联.

相关资料:
Unitech/pm2#1749
nodejs/node#15380

@atian25
Copy link
Member

atian25 commented Jun 27, 2018

居然还有这个参数。

不过 egg-scripts 不支持 windows,你可以自己写个 index.js 然后配置下 cluster.settings 看看。

其实在 win 上,应该去找如何把一个命令行注册为 Service 后台服务,全部不可见。要找下文档。

@skyfore
Copy link
Author

skyfore commented Jun 27, 2018

@atian25 意思是 egg 的脚手架并不支持在 windows 下部署,并且也没有后续的计划吗?

假如是这样我确实应该考虑其他的方案, 应该直接把服务注册成为 Service 后台服务去完成这件事.

但是我还是希望能够有针对 windows 的支持.

@atian25
Copy link
Member

atian25 commented Jun 27, 2018

  1. egg-scripts 目前没有计划支持 Windows,有需要的话自己写个 index.js 调用 startCluster 几行代码就搞定了,不过要自己配置下环境变量,具体看下 egg-scripts 源码,就几十行。
  2. win 上推荐用 docker 来部署
  3. 不推荐用 win 来做服务器

@skyfore
Copy link
Author

skyfore commented Jun 27, 2018

@atian25 OK,十分感谢!

@ghost
Copy link

ghost commented May 27, 2019

使用这个参数可以解决这个问题windowsHide
分别在下面两个位置添加上这个参数:
1.

//egg-cluster\lib\master.js
......
forkAgentWorker() {
    this.agentStartTime = Date.now();

    const args = [ JSON.stringify(this.options) ];
    const opt = {
      windowsHide: true 
    };
.......
//cfork\index.js
....
  /**
   * fork worker with certain settings
   */
  function forkWorker(settings) {
    if (settings) {
      settings.windowsHide = true;
      cluster.settings = settings;
      cluster.setupMaster();
    } else {
      cluster.setupMaster({ windowsHide: true });
    }
    return cluster.fork(attachedEnv);
  }
....

@skyfore
@atian25

@qingdengyue
Copy link
Contributor

qingdengyue commented May 28, 2019

v9.4.0 : The windowsHide option is supported now.

Node 上已经有这个问题了。这个参数不起作用。windowsHide

#3728

@qingdengyue
Copy link
Contributor

qingdengyue commented May 28, 2019

child_process 也有这个参数
image
也是不起作用。

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

No branches or pull requests

3 participants