Module: Puppet::Agent::Locker

Included in:
Puppet::Agent
Defined in:
lib/puppet/agent/locker.rb

Overview

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.puppetlabs.com/agent_lockfiles

API:

  • public

Instance Method Summary collapse

Instance Method Details

#lockObject

Yield if we get a lock, else raise Puppet::LockError. Return value of block yielded.

API:

  • public



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/agent/locker.rb', line 18

def lock
  if lockfile.lock
    begin
      yield
    ensure
      lockfile.unlock
    end
  else
    fail Puppet::LockError, 'Failed to aquire lock'
  end
end

#lockfile_pathObject

API:

  • public



40
41
42
# File 'lib/puppet/agent/locker.rb', line 40

def lockfile_path
  @lockfile_path ||= Puppet[:agent_catalog_run_lockfile]
end

#running?Boolean

Deprecated.

Returns:

API:

  • public



31
32
33
34
35
36
37
38
# File 'lib/puppet/agent/locker.rb', line 31

def running?
  Puppet.deprecation_warning "Puppet::Agent::Locker.running? is deprecated as it is inherently unsafe.\nThe only safe way to know if the lock is locked is to try lock and perform some\naction and then handle the LockError that may result.\n"
  lockfile.locked?
end