class Runpuppet::Client
Attributes
agent[RW]
config[RW]
logger[RW]
run_options[RW]
Public Class Methods
new(context)
click to toggle source
# File lib/runpuppet/client.rb, line 7 def initialize(context) @config = context.config @run_options = context.run_options @agent = context.agent @logger = context.logger end
Public Instance Methods
calculate_run_params()
click to toggle source
# File lib/runpuppet/client.rb, line 33 def calculate_run_params (local_run_params || remote_run_params) end
local_run_params()
click to toggle source
# File lib/runpuppet/client.rb, line 37 def local_run_params return nil if run_options[:try] return 'run', (run_options[:branch] ||config.default_branch) end
log(msg)
click to toggle source
# File lib/runpuppet/client.rb, line 81 def log(msg) logger.log(msg) end
remote_run_params()
click to toggle source
# File lib/runpuppet/client.rb, line 42 def remote_run_params agent.check_status end
run()
click to toggle source
# File lib/runpuppet/client.rb, line 14 def run with_lock(config.lock_file) do action, branch = calculate_run_params if action == 'run' agent.report_start log "run #{branch}" if sh(run_command(branch)) agent.report_success else agent.report_failure exit 2 end else log "nothing to do" end end end
run_command(branch)
click to toggle source
# File lib/runpuppet/client.rb, line 46 def run_command(branch) cmd = if run_options[:verbose] config.verbose_command else config.command end cmd.gsub('@@branch@@', branch) end
sh(cmd)
click to toggle source
simplified copy of rake`s sh
# File lib/runpuppet/client.rb, line 71 def sh(cmd) puts cmd IO.popen(cmd) do |pipe| while str = pipe.gets puts str end end $?.success? end
with_lock(lock_file) { || ... }
click to toggle source
# File lib/runpuppet/client.rb, line 55 def with_lock(lock_file) recently_locked = (File.exists?(lock_file) and File.mtime(lock_file) > Time.now - 15*60) if recently_locked log "can not run, lockfile #{lock_file} exists" else begin `touch #{lock_file}` yield ensure `rm #{lock_file}` end end end