blob: 03736b27888c4d7325fbf16eddca50f9497cd321 (
plain)
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
|
require 'puppet/util/pidlock'
# Break out the code related to locking the agent. This module is just
# included into the agent, but having it here makes it easier to test.
module Puppet::Agent::Locker
# Let the daemon run again, freely in the filesystem.
def enable
lockfile.unlock(:anonymous => true)
end
# Stop the daemon from making any catalog runs.
def disable
lockfile.lock(:anonymous => true)
end
# Yield if we get a lock, else do nothing. Return
# true/false depending on whether we get the lock.
def lock
if lockfile.lock
begin
yield
ensure
lockfile.unlock
end
return true
else
return false
end
end
def lockfile
unless defined?(@lockfile)
@lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile])
end
@lockfile
end
end
|