简体   繁体   English

使用Puppet运行Node.js应用时,执行命令超时错误

[英]Exec command time out Error when running nodejs app using puppet

I am cloning my repo and running my nodejs application using puppet. 我正在克隆存储库并使用puppet运行我的nodejs应用程序。 please find the code below: 请找到以下代码:

package { 'git':
  ensure => 'latest',
}

vcsrepo { "/nodejs-helloworld":
  ensure   => latest,
  provider => git,
  require  => [ Package["git"] ],
  source   => "git@gitlab.abc.dev.net:hello-world/nodejs-helloworld.git",
  revision => 'master',
  before   => Exec['/usr/local/bin/npm install;/usr/local/bin/npm start'],
}

exec { '/usr/local/bin/npm install;/usr/local/bin/npm start':
  cwd         => '/nodejs-helloworld',
  subscribe   => Vcsrepo['/nodejs-helloworld'],
  refreshonly => true,
}

My repository is cloned, my application is running fine, and npm test also works. 我的存储库已克隆,我的应用程序运行正常,并且npm test也有效。 Everything works fine. 一切正常。 However, I get an exec command time out error. 但是,我收到一个exec命令超时错误。

Error log: 错误日志:

[root@ip-*******/]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ip-**************
Info: Applying configuration version '1474433486'
Notice: /Stage[main]/Main/Exec[install-node-version-manager-global]/returns: executed successfully
Notice: /Stage[main]/Main/Exec[install-node-version-manager-latest]/returns: executed successfully
Notice: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]/ensure: Creating repository from latest
Notice: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]/ensure: created
Info: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]: Scheduling refresh of Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]
Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Failed to call refresh: Command exceeded timeout
Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Command exceeded timeout
Notice: Finished catalog run in 302.86 seconds

As you can see here, even though I get an exec command timeout error, my app is running and npm test works. 如您在这里看到的,即使我收到exec命令超时错误,我的应用程序npm test运行并且npm test有效。

 [root@ip-********* nodejs-helloworld]# netstat -anp 2> /dev/null | grep :3000
    tcp6       0      0 :::3000                 :::*                    LISTEN      17630/node
 [root@ip-********* nodejs-helloworld]# npm test

    > nodejs-helloworld@1.0.0 test /nodejs-helloworld
    > mocha



      Test HelloWorld
        ✓ Should have the root route (46ms)
        ✓ Should have a hello world response


      2 passing (66ms)

Can anyone please tell me how to avoid the exec command timeout error? 谁能告诉我如何避免exec命令超时错误?

If I'm not wrong what seems to be the problem is that, when you run npm start , it runs your application but it doesn't exit, and you don't want that because you want to keep your application running, however puppet expects it to exit at some point. 如果我没记错,那似乎是问题所在,当您运行npm start ,它会运行您的应用程序,但它不会退出,并且您不希望这样做,因为您想保持应用程序的运行,但是请执行puppet希望它在某个时候退出。

What you should do instead is to make the exec resource start your application in the background. 相反,您应该做的是使exec资源在后台启动您的应用程序。 You can have a look at this question where the answers describe various tools to easily achieve this. 您可以看一下这个问题 ,其中的答案描述了可以轻松实现这一目标的各种工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM