Sha256: 0db843765e6a3a97035d1b74665df831e96e677cf16ced6e5cad136dc0341032

Contents?: true

Size: 1.43 KB

Versions: 41

Compression:

Stored size: 1.43 KB

Contents

require 'puppet/util/pidlock'
require 'puppet/error'

# 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
module Puppet::Agent::Locker
  # Yield if we get a lock, else raise Puppet::LockError. Return
  # value of block yielded.
  def lock
    if lockfile.lock
      begin
        yield
      ensure
        lockfile.unlock
      end
    else
      fail Puppet::LockError, _('Failed to acquire lock')
    end
  end

  # @deprecated
  def running?
    Puppet.deprecation_warning _(<<-ENDHEREDOC)
Puppet::Agent::Locker.running? is deprecated as it is inherently unsafe.
The only safe way to know if the lock is locked is to try lock and perform some
action and then handle the LockError that may result.
ENDHEREDOC
    lockfile.locked?
  end

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

  def lockfile
    @lockfile ||= Puppet::Util::Pidlock.new(lockfile_path)

    @lockfile
  end
  private :lockfile


end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
bolt-0.15.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.14.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.13.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.12.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.11.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.10.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.9.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.8.0 vendored/puppet/lib/puppet/agent/locker.rb
puppet-5.3.3 lib/puppet/agent/locker.rb
puppet-5.3.3-x86-mingw32 lib/puppet/agent/locker.rb
puppet-5.3.3-x64-mingw32 lib/puppet/agent/locker.rb
puppet-5.3.3-universal-darwin lib/puppet/agent/locker.rb
bolt-0.7.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.6.1 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.6.0 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.5.1 vendored/puppet/lib/puppet/agent/locker.rb
bolt-0.5.0 vendored/puppet/lib/puppet/agent/locker.rb
puppet-5.3.2 lib/puppet/agent/locker.rb
puppet-5.3.2-x86-mingw32 lib/puppet/agent/locker.rb
puppet-5.3.2-x64-mingw32 lib/puppet/agent/locker.rb