forked from choria-legacy/mcollective-puppet-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgr_v3.rb
74 lines (64 loc) · 2.36 KB
/
mgr_v3.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module MCollective
module Util
class PuppetAgentMgr
class MgrV3 < PuppetAgentMgr
def initialize(configfile = nil,
service_name = 'puppet',
testing = false)
@puppet_service = service_name
unless testing || Puppet.settings.app_defaults_initialized?
require 'puppet/util/run_mode'
Puppet.settings.preferred_run_mode = :agent
args = []
(args << "--config=%s" % configfile) if configfile
Puppet.settings.initialize_global_settings(args)
Puppet.settings.initialize_app_defaults(
Puppet::Settings.app_defaults_for_run_mode(Puppet.run_mode))
# This check is to keep backwards compatibility
# with Puppet versions < 3.5.0
if Puppet.respond_to?(:base_context) \
&& Puppet.respond_to?(:push_context)
Puppet.push_context(Puppet.base_context(Puppet.settings))
end
end
end
# enables the puppet agent, it can now start applying catalogs again
def enable!
raise "Already enabled" if enabled?
File.unlink(Puppet[:agent_disabled_lockfile])
end
# disable the puppet agent
def disable!(msg=nil)
raise "Already disabled" unless enabled?
msg ||= "Disabled using the Ruby API at %s" % Time.now.strftime("%c")
atomic_file(Puppet[:agent_disabled_lockfile]) do |f|
f.print(JSON.dump(:disabled_message => msg))
end
msg
end
# the current lock message, always "" on 2.0
def lock_message
if disabled?
lock_data = JSON.parse(File.read(Puppet[:agent_disabled_lockfile]))
return lock_data["disabled_message"]
else
return ""
end
end
# is the agent disabled
def disabled?
File.exist?(Puppet[:agent_disabled_lockfile])
end
private
def platform_applying?
return false unless File.exist?(Puppet[:agent_catalog_run_lockfile])
if File::Stat.new(Puppet[:agent_catalog_run_lockfile]).size > 0
return has_process_for_pid?(
File.read(Puppet[:agent_catalog_run_lockfile]))
end
return false
end
end
end
end
end