17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/runner.rb', line 17
def shell cmd, opts={}
cmd = cmd.strip
environment = opts[:environment] ||= {}
environment['RUBYOPT'] = ''
environment['BUNDLE_GEMFILE'] = ''
environment['RAILS_ENV'] = 'production'
environment['RACK_ENV'] = 'production'
debug "Executing '#{cmd}'."
command = shell_out(cmd, opts)
command.run_command
command.error!
return command.stdout
rescue Mixlib::ShellOut::ShellCommandFailed => error
warn "Failed command (exit #{command.exitstatus}): #{cmd} "
lines = command.stderr.lines.to_a
warn "STDERR: #{lines.size} lines of output:" unless lines.empty?
lines.each_with_index do |line, idx|
symbol = idx == lines.size-1 ? '`-' : '|-'
debug " #{symbol} #{line.chomp}"
end
lines = command.stdout.lines.to_a
warn "STDOUT: #{lines.size} lines of output:" unless lines.empty?
lines.each_with_index do |line, idx|
symbol = idx == lines.size-1 ? '`-' : '|-'
debug " #{symbol} #{line.chomp}"
end
raise CommandFailed, "'#{cmd}' exited with #{command.exitstatus}. (see log for details)"
end
|