Module: Puppet::Agent::Disabler

Included in:
Puppet::Agent
Defined in:
lib/puppet/agent/disabler.rb

Overview

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.puppet.com/agent_lockfiles

Constant Summary collapse

DISABLED_MESSAGE_JSON_KEY =
"disabled_message"

Instance Method Summary collapse

Instance Method Details

#disable(msg = nil) ⇒ Object

Stop the daemon from making any catalog runs.



26
27
28
29
30
31
32
33
# File 'lib/puppet/agent/disabler.rb', line 26

def disable(msg = nil)
  data = {}
  Puppet.notice _("Disabling Puppet.")
  if (!msg.nil?)
    data[DISABLED_MESSAGE_JSON_KEY] = msg
  end
  disable_lockfile.lock(data)
end

#disable_messageObject



39
40
41
42
43
44
45
46
47
# File 'lib/puppet/agent/disabler.rb', line 39

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

#disabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/puppet/agent/disabler.rb', line 35

def disabled?
  disable_lockfile.locked?
end

#enableObject

Let the daemon run again, freely in the filesystem.



20
21
22
23
# File 'lib/puppet/agent/disabler.rb', line 20

def enable
  Puppet.notice _("Enabling Puppet.")
  disable_lockfile.unlock
end