我正在克隆我的repo并使用puppet运行我的nodejs应用程序。请找到以下代码:
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,
}
克隆了我的存储库,我的应用程序运行正常,npm test
也可以运行。一切正常。但是,我得到一个exec命令超时错误。
错误日志:
[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
正如您在此处所见,即使我收到exec命令超时错误,我的应用程序仍在运行且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)
有谁能告诉我如何避免exec命令超时错误?
答案 0 :(得分:0)
如果我没错,那么问题就在于,当您运行npm start
时,它会运行您的应用程序,但它不会退出,并且您不想要因为你想保持你的应用程序运行,但是木偶希望它在某个时候退出。
您应该做的是让exec
资源在后台启动您的应用程序。您可以查看this question,其中的答案描述了可轻松实现此目的的各种工具。