Class: PuppetX::Relay::Agent::Backend::Process

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet_x/relay/agent/backend/process.rb

Direct Known Subclasses

Bolt, SSH

Instance Attribute Summary

Attributes inherited from Base

#relay_api

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PuppetX::Relay::Agent::Backend::Base

Instance Method Details

#exec(run, state_dir, schedule) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet_x/relay/agent/backend/process.rb', line 12

def exec(run, state_dir, schedule)
  statuses = []

  format_commands(run, state_dir).each_with_index do |cmd, n|
    lock = Puppet::Util::Lockfile.new(File.join(state_dir, "proc_#{n}.pid"))
    pid =
      if lock.locked?
        Integer(lock.lock_data)
      else
        fork { exec_child(lock, cmd) }
      end

    ::Process.wait(pid, ::Process::WNOHANG | ::Process::WUNTRACED)
    statuses << $CHILD_STATUS
  end

  new_state =
    if statuses.none?(&:nil?)
      run.state.to_complete(outcome: (statuses.all? { |s| s.exitstatus.zero? }) ? 'finished' : 'failed')
    else
      run.state.to_in_progress(schedule.next_update_before)
    end

  run.with_state(new_state)
end