【问题标题】:Chef immediately throws Mixlib::ShellOut::CommandTimeout on powershell_scriptChef 立即在 powershell_script 上抛出 Mixlib::ShellOut::CommandTimeout
【发布时间】:2018-10-13 12:23:36
【问题描述】:

我遇到了一个反复出现但随机的错误。有时这可行,但我经常在一个非常简单的powershell_script 资源上超时。 Chef 似乎没有等待默认超时(3600 秒),而是立即抛出此异常。我在这里缺少什么吗?我该如何调试 Mixlib::ShellOut::CommandTimeout?

 ================================================================================
 Error executing action `run` on resource 'powershell_script[uninstall]'
 ================================================================================

 Mixlib::ShellOut::CommandTimeout
 --------------------------------
 command timed out:
 ---- Begin output of "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20180924-2936-1r1bagl.ps1" ----                                                                     
 STDOUT: 
 STDERR: 
 ---- End output of "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20180924-2936-1r1bagl.ps1" ----                                                                       

 ProcessId: 1664
 app_name: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
 command_line: "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File "C:/Users/vagrant/AppData/Local/Temp/chef-script20180924-2936-1r1bagl.ps1"                                                                                 
 timeout: 3600

 Resource Declaration:
 ---------------------
 # In C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/documents/recipes/service.rb

   7: powershell_script "uninstall" do
   8:   only_if { ::File.exist?('C:\Documents\scripts\Uninstall.ps1') }
   9:   code <<-SCRIPT
  10:   "Trying to uninstall...."
  11:   . C:\\Documents\\scripts\\Uninstall.ps1 > C:\\Documents\\Uninstall.log
  12:   SCRIPT
  13: end
  14: 

【问题讨论】:

    标签: powershell chef-infra


    【解决方案1】:

    您具体使用的是哪个 Chef 版本?

    不过,如果您想调试,我想尝试将您的命令直接传递到 Mixlib::ShellOut.new(cmd, :timeout =&gt; 3600) 是一个很好的起点。

    但是,在我google了一下之后,我发现powershell资源曾经有一些问题,比如https://github.com/chef/mixlib-shellout/issues/86https://github.com/chef/chef/issues/2348,所以不确定它们是否已经在较新的版本中得到修复等。

    因此,要考虑的替代解决方案是在 Chef 中使用 dsc 脚本 (即 https://docs.chef.io/resource_dsc_script.htmlhttps://docs.microsoft.com/en-us/powershell/dsc/scriptresource )我认为可能更可靠。

    【讨论】:

    • 我发现在powershell_script 之前添加一个带有sleep 1 的r​​uby 块似乎可以缓解这个问题。
    • @ReedG.Law 好的,如果可行的话。但这很有趣,因为它似乎与我的 powershell_script 资源无关。你有时间弄清楚ruby_block 是如何影响powershell_script 的吗?
    猜你喜欢
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    相关资源
    最近更新 更多