module Puppet::Agent::Locker
This module is responsible for encapsulating the logic for “locking” the puppet agent during a catalog run; in other words, keeping track of enough state to answer the question “is there a puppet agent currently applying a catalog?”
The implementation involves writing a lockfile whose contents are simply the PID of the running agent process. This 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
Public Instance Methods
lock() { || ... }
click to toggle source
Yield if we get a lock, else raise Puppet::LockError
. Return value of block yielded.
# File lib/puppet/agent/locker.rb 18 def lock 19 if lockfile.lock 20 begin 21 yield 22 ensure 23 lockfile.unlock 24 end 25 else 26 fail Puppet::LockError, _('Failed to acquire lock') 27 end 28 end
lockfile_path()
click to toggle source
# File lib/puppet/agent/locker.rb 34 def lockfile_path 35 @lockfile_path ||= Puppet[:agent_catalog_run_lockfile] 36 end
running?()
click to toggle source
# File lib/puppet/agent/locker.rb 30 def running? 31 lockfile.locked? 32 end
Private Instance Methods
lockfile()
click to toggle source
# File lib/puppet/agent/locker.rb 38 def lockfile 39 @lockfile ||= Puppet::Util::Pidlock.new(lockfile_path) 40 41 @lockfile 42 end