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
|
# File 'lib/bosh_agent/message/run_errand.rb', line 19
def start
state = Bosh::Agent::Config.state.to_hash
job_templates = state.fetch('job', {}).fetch('templates', [])
if job_templates.empty?
raise Bosh::Agent::MessageHandlerError,
"At least one job template is required to run an errand"
end
job_template_name = job_templates.first.fetch('name')
env = { 'PATH' => '/usr/sbin:/usr/bin:/sbin:/bin' }
cmd = "#{@base_dir}/jobs/#{job_template_name}/bin/run"
opts = { :unsetenv_others => true }
unless File.executable?(cmd)
raise Bosh::Agent::MessageHandlerError,
"Job template #{job_template_name} does not have executable bin/run"
end
begin
stdout, stderr, status = Open3.capture3(env, cmd, opts)
{
'exit_code' => status.exitstatus,
'stdout' => stdout,
'stderr' => stderr,
}
rescue Exception => e
@logger.warn("%s\n%s" % [e.inspect, e.backtrace.join("\n")])
raise Bosh::Agent::MessageHandlerError, e.inspect
end
end
|