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.


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

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


37
38
39
40
41
42
43
44
# File 'lib/puppet/agent/disabler.rb', line 37

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


33
34
35
# File 'lib/puppet/agent/disabler.rb', line 33

def disabled?
  disable_lockfile.locked?
end

#enableObject

Let the daemon run again, freely in the filesystem.


18
19
20
21
# File 'lib/puppet/agent/disabler.rb', line 18

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