Sha256: d3e5fc16ae5260bec8d69cc65a921d1563bc7c7b7ee116db7d240ac7b1d39ee3

Contents?: true

Size: 997 Bytes

Versions: 6

Compression:

Stored size: 997 Bytes

Contents

require 'puppet/util/pidlock'

# Break out the code related to locking the agent.  This module is just
# included into the agent, but having it here makes it easier to test.
module Puppet::Agent::Locker
    # Let the daemon run again, freely in the filesystem.
    def enable
        lockfile.unlock(:anonymous => true)
    end

    # Stop the daemon from making any catalog runs.
    def disable
        lockfile.lock(:anonymous => true)
    end

    # Yield if we get a lock, else do nothing.  Return
    # true/false depending on whether we get the lock.
    def lock
        if lockfile.lock
            begin
                yield
            ensure
                lockfile.unlock
            end
            return true
        else
            return false
        end
    end

    def lockfile
        unless defined?(@lockfile)
            @lockfile = Puppet::Util::Pidlock.new(lockfile_path)
        end

        @lockfile
    end

    def running?
        lockfile.locked?
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.25.5 lib/puppet/agent/locker.rb
puppet-0.25.4 lib/puppet/agent/locker.rb
puppet-0.25.3 lib/puppet/agent/locker.rb
puppet-0.25.2 lib/puppet/agent/locker.rb
puppet-0.25.1 lib/puppet/agent/locker.rb
puppet-0.25.0 lib/puppet/agent/locker.rb