2013-02-22 57 views
2

我需要检查与厨师的联系。检查与厨师的联系

我在努力。

execute "check_sayc" do 
command "$comprobacionPuerto='nc -zw3 server port && echo 'opened' 
|| echo 'closed'|grep 'opened' if [[ -z $comprobacionPuerto ]] 
then Chef::Log.fatal 'connections refuse' else Chef::Log.info 'connections open' fi'" 
end 

Mixlib::ShellOut::ShellCommandFailed: execute[check_sayc] 
(cb_prueba_frontal_deploy_databag::default line 7) had an error:  
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received 
'127' 

什么这是错的?

回答

4

您在execute中混合使用shell代码和Ruby代码来执行无法以此方式工作的事情。另外,您在command中混合了您的报价。

我真的不知道,如果是有意义的执行你nc尝试那里的行动,但它可能更容易使用纯Ruby:

ruby_block "check sayc" do 
    block do 
    server = "www.google.com" 
    port = 80 

    begin 
     Timeout.timeout(5) do 
     Socket.tcp(server, port){} 
     end 
     Chef::Log.info 'connections open' 
    rescue 
     Chef::Log.fatal 'connections refused' 
    end 
    end 
end 

这应该做的尝试同样的事情实现但避免了订单问题以及如何将你的shellout的输出转换回ruby以在Chef中处理的问题。

编辑:我将连接尝试封装到超时模块中。这可能会泄露半开放的套接字,直到他们稍后收集垃圾。但我认为这在厨师的情况下是安全的。

+0

我怎么能超时? – 2013-02-22 13:37:10

+0

请参阅我的编辑。请注意,您将体验与'nc'一样的长时间默认超时。 – 2013-02-22 13:58:01

+0

完美,谢谢。 – 2013-02-25 06:57:01