Closed Xoph closed 9 years ago
Hey @Xoph ,
The line you were looking for in shell out code is here: https://github.com/chef/mixlib-shellout/blob/b4eb2472cbb0b18e498881c9443e26b95dd4e62f/lib/mixlib/shellout/windows.rb#L113
Regarding your request. Lets rule out the obvious pieces first. How are you converging your node? Locally? Through WINRM? Push Jobs?
The code you posted looks right. Just created this quick test myself.
script= <<-EOF
write-host $pwd
sleep -seconds 60
EOF
procobj = Mixlibrary::Core::Shell.windows_script_out(:powershell,script, {:timeout => 10})
It died how I expected in about 10 seconds. With that said the answer to how you are executing could help.
I have a hunch you are using winrm. And you might have hit this timeout instead: https://github.com/chef/knife-windows/blob/75ba16e25c79f89c916f8f8ec80709cc2206d7c3/lib/chef/knife/winrm.rb#L187
We have hit the same timeout. We had a private fix and were going to do a PR. But we hit a WinRM timeout of a hard coded 60 minutes here. https://github.com/WinRb/WinRM/pull/101
So I am working the WinRM 1.3 change into Winrm-s and then finally knife-windows before we can go over 60 minute converges. https://github.com/chef/winrm-s/issues/21
We are running chef-client locally. I saw this winrm timeout, and made note of it, but I don't think it's what's affecting things, since we are running it locally.
@Xoph ,
Can you try my sample powershell script in your environment and validate you get a timeout exception?
script= <<-EOF
write-host $pwd
sleep -seconds 60
EOF
procobj = Mixlibrary::Core::Shell.windows_script_out(:powershell,script, {:timeout => 10})
Just about to do that now..
I do not get a timeout
Nevermind, it did work, I just had something incorrect in my code.
So it's something incorrect in my implementation
I logged the timeout that my PowershellScriptEx resource uses on a run, and I am seeing it is always using the default, whether I specify a timeout attribute or not.
Load current resource looks like its not setting the timeout: def load_current_resource @current_resource = Chef::Resource::RstCommonPowershellscriptex.new(new_resource.name) @current_resource.name(new_resource.name) encapsulatedcode = <<-EOH
EOH
@current_resource.code(encapsulatedcode)
if new_resource.cwd.empty?
@current_resource.cwd(Dir.pwd)
else
@current_resource.cwd(new_resource.cwd)
end
@current_resource.returns(new_resource.returns)
@current_resource.exitcode = -99999
enddef load_current_resource @current_resource = Chef::Resource::RstCommonPowershellscriptex.new(new_resource.name) @current_resource.name(new_resource.name) encapsulatedcode = <<-EOH
EOH
@current_resource.code(encapsulatedcode)
if new_resource.cwd.empty?
@current_resource.cwd(Dir.pwd)
else
@current_resource.cwd(new_resource.cwd)
end
@current_resource.returns(new_resource.returns)
@current_resource.exitcode = -99999
end
HA! That's it. Thank you for your help. First time working on creating LWRPs.
I'm working with @ericrlarson to implement our custom powershell_script resource. I'm now trying to set a timeout for our scripts, because one of them installs SQL, and you probably know, this can be a long-winded process. Chef hits a timeout on our resource ~30 minutes, and we are seeing SQL take longer than that sometimes.
I'm hoping you can help us figure out how to pass in the timeout from the LWRP. Here's what we ended up implementing. I think we've got the timeout being passed in correctly, but I'm not entirely convinced. Please let me know if there's anything else you need.
I've also done significant research around what might be going on here, including diving too deep for my own good into the Chef code. There was a bug in Chef 11 around the kill signal being sent for a process timeout not working, that have been fixed for Chef 12. I've tried Chef 12 (we've yet to upgrade to 12) but had no luck.
I'm also inclined to think that there could be another bug in the ShellOut code that Chef wrote. I'm not seeing how the timeout is being passed to Process.Create. The relevant code for that is also below.
Thanks in advance, Christoph GE Healthcare
providers\PowershellScriptEx.rb:
resources\PowershellScriptEx.rb:
Create process code from ShellOut (https://github.com/chef/mixlib-shellout/blob/master/lib/mixlib/shellout/windows.rb)