Sha256: 6c6d2116c7dfb8490e7a872bc93fdf372a7f21678a1fa002a687864dd1b00e15

Contents?: true

Size: 1.42 KB

Versions: 267

Compression:

Stored size: 1.42 KB

Contents

require 'puppet/util/json_lockfile'

# This module is responsible for encapsulating the logic for
#  "disabling" the puppet agent during a run; in other words,
#  keeping track of enough state to answer the question
#  "has the puppet agent been administratively disabled?"
#
# The implementation involves writing a lockfile with JSON
#  contents, and is considered part of the public Puppet API
#  because it used by external tools such as mcollective.
#
# For more information, please see docs on the website.
#  http://links.puppetlabs.com/agent_lockfiles
module Puppet::Agent::Disabler
  DISABLED_MESSAGE_JSON_KEY = "disabled_message"

  # Let the daemon run again, freely in the filesystem.
  def enable
    Puppet.notice "Enabling Puppet."
    disable_lockfile.unlock
  end

  # Stop the daemon from making any catalog runs.
  def disable(msg=nil)
    data = {}
    Puppet.notice "Disabling Puppet."
    if (! msg.nil?)
      data[DISABLED_MESSAGE_JSON_KEY] = msg
    end
    disable_lockfile.lock(data)
  end

  def disabled?
    disable_lockfile.locked?
  end

  def disable_message
    data = disable_lockfile.lock_data
    return nil if data.nil?
    if data.has_key?(DISABLED_MESSAGE_JSON_KEY)
      return data[DISABLED_MESSAGE_JSON_KEY]
    end
    nil
  end


  def disable_lockfile
    @disable_lockfile ||= Puppet::Util::JsonLockfile.new(Puppet[:agent_disabled_lockfile])

    @disable_lockfile
  end
  private :disable_lockfile
end

Version data entries

267 entries across 267 versions & 3 rubygems

Version Path
puppet-4.10.12 lib/puppet/agent/disabler.rb
puppet-4.10.12-x86-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.12-x64-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.12-universal-darwin lib/puppet/agent/disabler.rb
puppet-4.10.11 lib/puppet/agent/disabler.rb
puppet-4.10.11-x86-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.11-x64-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.11-universal-darwin lib/puppet/agent/disabler.rb
puppet-4.10.10 lib/puppet/agent/disabler.rb
puppet-4.10.10-x86-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.10-x64-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.10-universal-darwin lib/puppet/agent/disabler.rb
puppet-4.10.9 lib/puppet/agent/disabler.rb
puppet-4.10.9-x86-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.9-x64-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.9-universal-darwin lib/puppet/agent/disabler.rb
puppet-retrospec-1.5.0 vendor/gems/puppet-4.5.2/lib/puppet/agent/disabler.rb
puppet-4.10.8 lib/puppet/agent/disabler.rb
puppet-4.10.8-x86-mingw32 lib/puppet/agent/disabler.rb
puppet-4.10.8-x64-mingw32 lib/puppet/agent/disabler.rb