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
19 def lock
20   if lockfile.lock
21     begin
22       yield
23     ensure
24       lockfile.unlock
25     end
26   else
27     fail Puppet::LockError, _('Failed to acquire lock')
28   end
29 end
lockfile_path() click to toggle source
   # File lib/puppet/agent/locker.rb
35 def lockfile_path
36   @lockfile_path ||= Puppet[:agent_catalog_run_lockfile]
37 end
running?() click to toggle source
   # File lib/puppet/agent/locker.rb
31 def running?
32   lockfile.locked?
33 end

Private Instance Methods

lockfile() click to toggle source
   # File lib/puppet/agent/locker.rb
39 def lockfile
40   @lockfile ||= Puppet::Util::Pidlock.new(lockfile_path)
41 
42   @lockfile
43 end