Module: Ohai::Mixin::ShellOut

Includes:
Mixlib::ShellOut::Helper, ChefUtilsWiring
Included in:
DSL::Plugin
Defined in:
lib/ohai/mixin/shell_out.rb

Instance Method Summary collapse

Instance Method Details

#shell_out(cmd, **options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ohai/mixin/shell_out.rb', line 33

def shell_out(cmd, **options)
  options = options.dup
  # unless specified by the caller timeout after configured timeout (default 30 seconds)
  options[:timeout] ||= Ohai::Config.ohai[:shellout_timeout]
  begin
    so = super(cmd, **options)
    logger.trace("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
    so
  rescue Errno::ENOENT => e
    logger.trace("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
    raise Ohai::Exceptions::Exec, e
  rescue Mixlib::ShellOut::CommandTimeout => e
    logger.trace("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
    raise Ohai::Exceptions::Exec, e
  end
end