Class: Taskr::Actions::Shell
Instance Attribute Summary
Attributes inherited from Base
#parameters, #task, #task_action
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Taskr::Actions::Base
Instance Method Details
#execute ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/taskr/actions.rb', line 135 def execute if parameters.kind_of? Hash user = parameters['as_user'] cmd = parameters['command'] else user = nil end unless user.blank? cmd = "sudo -u #{user} #{cmd}" end outio = StringIO.new errio = StringIO.new old_stdout, $stdout = $stdout, outio old_stderr, $stderr = $stderr, errio out = `#{cmd}` err = errio.string out = outio.string LogEntry.debug(task_action, out) unless out.blank? LogEntry.error(task_action, err) unless err.blank? $stdout = old_stdout $stderr = old_stderr unless $?.success? msg = "Shell command #{cmd.inspect} failed (returned code #{$?}): #{out}" LogEntry.error(task_action, msg) raise msg end end |