File: disabler.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (53 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative '../../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.puppet.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