diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-05 17:17:39 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-07-05 17:17:39 +0000 |
| commit | eff8d6ef0312b7f26e35b103e0dff9b148f54bd5 (patch) | |
| tree | 62055027780d2f6f8a514f19553ecf8cd91ab250 | |
| parent | 6b281eda564c4108f1955deb724e8beebb1e39cb (diff) | |
| download | puppet-eff8d6ef0312b7f26e35b103e0dff9b148f54bd5.tar.gz puppet-eff8d6ef0312b7f26e35b103e0dff9b148f54bd5.tar.xz puppet-eff8d6ef0312b7f26e35b103e0dff9b148f54bd5.zip | |
Accepting the patch from #190.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1368 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/client/master.rb | 33 | ||||
| -rw-r--r-- | test/client/master.rb | 8 |
2 files changed, 28 insertions, 13 deletions
diff --git a/lib/puppet/client/master.rb b/lib/puppet/client/master.rb index 0a3419ea4..1c4c57c9c 100644 --- a/lib/puppet/client/master.rb +++ b/lib/puppet/client/master.rb @@ -352,15 +352,19 @@ class Puppet::Client::MasterClient < Puppet::Client end def locked? + return(FileTest.exists? Puppet[:puppetdlockfile]) + end + + def lockpid if FileTest.exists? Puppet[:puppetdlockfile] text = File.read(Puppet[:puppetdlockfile]).chomp if text =~ /\d+/ - return text + return text.to_i else - return true + return 0 end else - return false + return 0 end end @@ -392,11 +396,26 @@ class Puppet::Client::MasterClient < Puppet::Client # The code that actually runs the configuration. def run(tags = nil, ignoreschedules = false) - if pid = locked? - t = "" - if pid != true - Puppet.notice "Locked by process %s" % pid + # Check if the lock is stale, so we can clear it + if locked? + pid = lockpid + + if pid != 0 + begin + Process.kill(0, pid) + rescue Errno::ESRCH + # No process with the given PID exists; stale lockfile + File.unlink(Puppet[:puppetdlockfile]) + Puppet.notice("Stale lockfile %s left by process %i; removing" % + [Puppet[:puppetdlockfile], pid]) + lockpid = false + else + Puppet.notice "Locked by process %s" % pid + end end + end + + if locked? Puppet.notice "Lock file %s exists; skipping configuration run" % Puppet[:puppetdlockfile] else diff --git a/test/client/master.rb b/test/client/master.rb index 7e447b095..89873791d 100644 --- a/test/client/master.rb +++ b/test/client/master.rb @@ -98,8 +98,8 @@ class TestMasterClient < Test::Unit::TestCase assert_nothing_raised do client.lock do pid = nil - assert(pid = client.locked?, "Client is not locked") - assert(pid =~ /^\d+$/, "PID is, um, not a pid") + assert(client.locked?, "Client is not locked") + assert(client.lockpid.is_a?(Integer), "PID #{client.lockpid} is, um, not a pid") end end assert(! client.locked?) @@ -118,24 +118,20 @@ class TestMasterClient < Test::Unit::TestCase # Make sure non-string facts don't make things go kablooie def test_nonstring_facts - Puppet.err :a # Add a nonstring fact Facter.add("nonstring") do setcode { 1 } end - Puppet.err :b assert_equal(1, Facter.nonstring, "Fact was a string from facter") client = mkclient() assert(! FileTest.exists?(@createdfile)) - Puppet.err :c assert_nothing_raised { client.run } - Puppet.err :d end def test_getplugins |
