Sha256: 216296acd452a12c610000354d804e948be8f71fa12f04500ad8b079204a1761

Contents?: true

Size: 1.21 KB

Versions: 32

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_relative '../../puppet/util/pidlock'
require_relative '../../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

  def running?
    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

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/agent/locker.rb
puppet-8.10.0-x86-mingw32 lib/puppet/agent/locker.rb
puppet-8.10.0-x64-mingw32 lib/puppet/agent/locker.rb
puppet-8.10.0-universal-darwin lib/puppet/agent/locker.rb
puppet-8.9.0 lib/puppet/agent/locker.rb
puppet-8.9.0-x86-mingw32 lib/puppet/agent/locker.rb
puppet-8.9.0-x64-mingw32 lib/puppet/agent/locker.rb
puppet-8.9.0-universal-darwin lib/puppet/agent/locker.rb
puppet-8.8.1 lib/puppet/agent/locker.rb
puppet-8.8.1-x86-mingw32 lib/puppet/agent/locker.rb
puppet-8.8.1-x64-mingw32 lib/puppet/agent/locker.rb
puppet-8.8.1-universal-darwin lib/puppet/agent/locker.rb
puppet-8.7.0 lib/puppet/agent/locker.rb
puppet-8.7.0-x86-mingw32 lib/puppet/agent/locker.rb
puppet-8.7.0-x64-mingw32 lib/puppet/agent/locker.rb
puppet-8.7.0-universal-darwin lib/puppet/agent/locker.rb
puppet-8.6.0 lib/puppet/agent/locker.rb
puppet-8.6.0-x86-mingw32 lib/puppet/agent/locker.rb
puppet-8.6.0-x64-mingw32 lib/puppet/agent/locker.rb
puppet-8.6.0-universal-darwin lib/puppet/agent/locker.rb