|
17 | 17 | return |
18 | 18 | end |
19 | 19 |
|
20 | | - event_log = node['cluster']['scheduler_plugin']['handler_log'] |
| 20 | + event_log_out = node['cluster']['scheduler_plugin']['handler_log_out'] |
| 21 | + event_log_err = node['cluster']['scheduler_plugin']['handler_log_err'] |
21 | 22 | event_cwd = node['cluster']['scheduler_plugin']['home'] |
22 | 23 | event_user = node['cluster']['scheduler_plugin']['user'] |
23 | 24 | event_timeout = 3600 |
24 | 25 | event_env = build_env |
25 | 26 | event_log_prefix_error = "%Y-%m-%d %H:%M:%S,000 - [#{new_resource.event_name}] - ERROR:" |
26 | 27 | event_log_prefix_info = "%Y-%m-%d %H:%M:%S,000 - [#{new_resource.event_name}] - INFO:" |
27 | | - Chef::Log.info("Executing Event #{new_resource.event_name}, with user (#{event_user}), cwd (#{event_cwd}), command (#{new_resource.event_command}), log (#{event_log})") |
| 28 | + Chef::Log.info("Executing Event #{new_resource.event_name}, with user (#{event_user}), cwd (#{event_cwd}), command (#{new_resource.event_command}), log out (#{event_log_out}), log err (#{event_log_err})") |
28 | 29 | # shellout https://github.com/chef/mixlib-shellout |
29 | 30 | # switch stderr/stdout with (2>&1 1>&3-), process error (now on stdout), switch back stdout/stderr with (3>&1 1>&2) and then process output |
30 | | - event_command = Shellwords.escape("set -o pipefail; { (#{new_resource.event_command}) 2>&1 1>&3- | ts '#{event_log_prefix_error}' | tee -a #{event_log}; } " \ |
31 | | - "3>&1 1>&2 | ts '#{event_log_prefix_info}' | tee -a #{event_log}") |
| 31 | + event_command = Shellwords.escape("set -o pipefail; { (#{new_resource.event_command}) 2>&1 1>&3- | ts '#{event_log_prefix_error}' | tee -a #{event_log_err}; } " \ |
| 32 | + "3>&1 1>&2 | ts '#{event_log_prefix_info}' | tee -a #{event_log_out}") |
32 | 33 | cmd = Mixlib::ShellOut.new("/bin/bash -c #{event_command}", user: event_user, group: event_user, login: true, env: event_env, cwd: event_cwd, timeout: event_timeout) |
33 | 34 | cmd.run_command |
34 | 35 |
|
35 | 36 | if cmd.error? |
36 | 37 | raise "Expected Event #{new_resource.event_name} to exit with #{cmd.valid_exit_codes.inspect}," \ |
37 | | - " but received '#{cmd.exitstatus}', complete log in #{event_log}\n #{format_stderr(cmd)}" |
| 38 | + " but received '#{cmd.exitstatus}', complete log info in #{event_log_out} and error in #{event_log_err}\n #{format_stderr(cmd)}" |
38 | 39 | end |
39 | 40 | end |
40 | 41 |
|
|
0 commit comments