summaryrefslogtreecommitdiffstats
path: root/lib/puppet/agent.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/agent.rb')
-rw-r--r--lib/puppet/agent.rb56
1 files changed, 18 insertions, 38 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index 5cb6f0019..0046ed317 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -7,9 +7,11 @@ require 'puppet/util'
class Puppet::Agent
require 'puppet/agent/fact_handler'
require 'puppet/agent/plugin_handler'
+ require 'puppet/agent/locker'
include Puppet::Agent::FactHandler
include Puppet::Agent::PluginHandler
+ include Puppet::Agent::Locker
# For benchmarking
include Puppet::Util
@@ -52,17 +54,6 @@ class Puppet::Agent
end
end
end
-
- # Let the daemon run again, freely in the filesystem. Frolick, little
- # daemon!
- def enable
- lockfile.unlock(:anonymous => true)
- end
-
- # Stop the daemon from making any catalog runs.
- def disable
- lockfile.lock(:anonymous => true)
- end
# Just so we can specify that we are "the" instance.
def initialize
@@ -150,24 +141,25 @@ class Puppet::Agent
got_lock = false
splay
Puppet::Util.sync(:puppetrun).synchronize(Sync::EX) do
- unless lockfile.lock
- Puppet.notice "Lock file %s exists; skipping catalog run" % lockfile.lockfile
- return
- end
+ got_lock = lock do
+ unless catalog = retrieve_catalog
+ Puppet.err "Could not retrieve catalog; skipping run"
+ return
+ end
- got_lock = true
- unless catalog = retrieve_catalog
- Puppet.err "Could not retrieve catalog; skipping run"
- return
+ begin
+ benchmark(:notice, "Finished catalog run") do
+ catalog.apply(options)
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Failed to apply catalog: %s" % detail
+ end
end
- begin
- benchmark(:notice, "Finished catalog run") do
- catalog.apply(options)
- end
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Failed to apply catalog: %s" % detail
+ unless got_lock
+ Puppet.notice "Lock file %s exists; skipping catalog run" % lockfile.lockfile
+ return
end
# Now close all of our existing http connections, since there's no
@@ -180,10 +172,6 @@ class Puppet::Agent
# done with the run.
Process.kill(:HUP, $$) if self.restart?
end
- ensure
- # Just make sure we remove the lock file if we set it.
- lockfile.unlock if got_lock and lockfile.locked?
- clear()
end
def running?
@@ -253,14 +241,6 @@ class Puppet::Agent
return textobjects
end
- def lockfile
- unless defined?(@lockfile)
- @lockfile = Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile])
- end
-
- @lockfile
- end
-
def splayed?
@splayed
end