class PuppetTwitch::Puppet

Public Class Methods

is_running?() click to toggle source
# File lib/puppet_twitch/puppet.rb, line 6
def is_running?
  lock_file_path_cmd = 'puppet config print agent_catalog_run_lockfile'
  lock_file_path = `#{sudo_if_required lock_file_path_cmd}`.strip
  if $?.to_i != 0
    raise StandardError, "Failed to find puppet lock file path: #{lock_file_path}"
  end
  File.exists?(lock_file_path)
end
run_puppet(async = true) click to toggle source
# File lib/puppet_twitch/puppet.rb, line 15
def run_puppet(async = true)
  command = async ? 'puppet agent --onetime' : 'puppet agent --onetime --no-daemonize'
  output = `#{sudo_if_required command}`
  exit_code = $?
  unless [0, 2].include?(exit_code.to_i) # 2 indicates a puppet change, 3 is a failure
    raise StandardError, "Error running puppet: #{exit_code}: #{output}"
  end
end
sudo_if_required(command) click to toggle source
# File lib/puppet_twitch/puppet.rb, line 24
def sudo_if_required(command)
  "sudo #{command}" unless Gem.win_platform?
end