Class: PuppetTwitch::Puppet
- Inherits:
-
Object
- Object
- PuppetTwitch::Puppet
- Defined in:
- lib/puppet_twitch/puppet.rb
Class Method Summary collapse
Class Method Details
.is_running? ⇒ Boolean
6 7 8 9 10 11 12 13 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/puppet_twitch/puppet.rb', line 24 def sudo_if_required(command) "sudo #{command}" unless Gem.win_platform? end |