1module MCollective
2  module Util
3    class PuppetAgentMgr
4      class MgrV2 < PuppetAgentMgr
5
6        def initialize(configfile   = nil,
7                       service_name = nil,
8                       testing      = false)
9          unless testing
10            $puppet_application_mode = Puppet::Util::RunMode[:agent]
11            Puppet.settings.use :main, :agent
12            Puppet.settings.set_value(:config, configfile, :cli) if configfile
13            Puppet.parse_config
14          end
15        end
16
17        # enables the puppet agent, it can now start applying catalogs again
18        def enable!
19          raise "Already enabled" if enabled?
20          File.unlink(Puppet[:puppetdlockfile])
21        end
22
23        # disable the puppet agent, the message is ignored
24        def disable!(msg=nil)
25          raise "Already disabled" unless enabled?
26          File.open(Puppet[:puppetdlockfile], "w") { }
27          ""
28        end
29
30        # the current lock message, always "" on 2.0
31        def lock_message
32          ""
33        end
34
35        # is the agent disabled
36        def disabled?
37          if File.exist?(Puppet[:puppetdlockfile])
38            if File::Stat.new(Puppet[:puppetdlockfile]).zero?
39              return true
40            end
41          end
42          return false
43        end
44
45        private
46
47        def platform_applying?
48          return false unless File.exist?(Puppet[:puppetdlockfile])
49          if File::Stat.new(Puppet[:puppetdlockfile]).size > 0
50            return has_process_for_pid?(File.read(Puppet[:puppetdlockfile]))
51          end
52          return false
53        end
54      end
55    end
56  end
57end
58