~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to lib/puppet/agent/locker.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/util/pidlock'
 
2
 
 
3
# Break out the code related to locking the agent.  This module is just
 
4
# included into the agent, but having it here makes it easier to test.
 
5
module Puppet::Agent::Locker
 
6
    # Let the daemon run again, freely in the filesystem.
 
7
    def enable
 
8
        lockfile.unlock(:anonymous => true)
 
9
    end
 
10
 
 
11
    # Stop the daemon from making any catalog runs.
 
12
    def disable
 
13
        lockfile.lock(:anonymous => true)
 
14
    end
 
15
 
 
16
    # Yield if we get a lock, else do nothing.  Return
 
17
    # true/false depending on whether we get the lock.
 
18
    def lock
 
19
        if lockfile.lock
 
20
            begin
 
21
                yield
 
22
            ensure
 
23
                lockfile.unlock
 
24
            end
 
25
            return true
 
26
        else
 
27
            return false
 
28
        end
 
29
    end
 
30
 
 
31
    def lockfile
 
32
        unless defined?(@lockfile)
 
33
            @lockfile = Puppet::Util::Pidlock.new(lockfile_path)
 
34
        end
 
35
 
 
36
        @lockfile
 
37
    end
 
38
 
 
39
    def running?
 
40
        lockfile.locked?
 
41
    end
 
42
end