summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-02-06 17:27:44 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:43 -0600
commit08a5d492dd3545366a2850d568d87aad0ba884e6 (patch)
treed3e174eb3297ed1f0091b63809763c7f56cdfb00 /lib
parentc7d178d04f324c010de1552083a954bb4b02217d (diff)
downloadpuppet-08a5d492dd3545366a2850d568d87aad0ba884e6.tar.gz
puppet-08a5d492dd3545366a2850d568d87aad0ba884e6.tar.xz
puppet-08a5d492dd3545366a2850d568d87aad0ba884e6.zip
Adding an Agent::Runner class.
This will eventually be used by puppetrun, but for now is just called by the old-school Runner handler. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/agent.rb2
-rw-r--r--lib/puppet/agent/runner.rb65
-rw-r--r--lib/puppet/configurer/downloader.rb2
-rw-r--r--lib/puppet/indirector/runner/rest.rb7
-rwxr-xr-xlib/puppet/network/handler/runner.rb51
5 files changed, 84 insertions, 43 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index 438b668a6..3add43ec1 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -7,6 +7,8 @@ class Puppet::Agent
require 'puppet/agent/locker'
include Puppet::Agent::Locker
+ require 'puppet/agent/runner'
+
attr_reader :client_class, :client, :needing_restart, :splayed
attr_accessor :stopping
diff --git a/lib/puppet/agent/runner.rb b/lib/puppet/agent/runner.rb
new file mode 100644
index 000000000..705b6c269
--- /dev/null
+++ b/lib/puppet/agent/runner.rb
@@ -0,0 +1,65 @@
+require 'puppet/agent'
+require 'puppet/configurer'
+require 'puppet/indirector'
+
+# A basic class for running the agent. Used by
+# puppetrun to kick off agents remotely.
+class Puppet::Agent::Runner
+ extend Puppet::Indirector
+ indirects :runner, :terminus_class => :rest
+
+ attr_reader :status, :background, :options
+
+ def agent
+ Puppet::Agent.new(Puppet::Configurer)
+ end
+
+ def background?
+ background
+ end
+
+ def initialize(options = {})
+ if options.include?(:background)
+ @background = options[:background]
+ options.delete(:background)
+ end
+
+ valid_options = [:tags, :ignoreschedules]
+ options.each do |key, value|
+ raise ArgumentError, "Runner does not accept %s" % key unless valid_options.include?(key)
+ end
+
+ @options = options
+ end
+
+ def log_run
+ msg = ""
+ msg += "triggered run" %
+ if options[:tags]
+ msg += " with tags %s" % options[:tags]
+ end
+
+ if options[:ignoreschedules]
+ msg += " ignoring schedules"
+ end
+
+ Puppet.notice msg
+ end
+
+ def run
+ if agent.running?
+ @status = "running"
+ return
+ end
+
+ log_run()
+
+ if background?
+ Thread.new { agent.run(options) }
+ else
+ agent.run(options)
+ end
+
+ @status = "success"
+ end
+end
diff --git a/lib/puppet/configurer/downloader.rb b/lib/puppet/configurer/downloader.rb
index f1c4c03b1..89af0233e 100644
--- a/lib/puppet/configurer/downloader.rb
+++ b/lib/puppet/configurer/downloader.rb
@@ -1,4 +1,4 @@
-require 'puppet/agent'
+require 'puppet/configurer'
require 'puppet/resource/catalog'
class Puppet::Configurer::Downloader
diff --git a/lib/puppet/indirector/runner/rest.rb b/lib/puppet/indirector/runner/rest.rb
new file mode 100644
index 000000000..25d3def3f
--- /dev/null
+++ b/lib/puppet/indirector/runner/rest.rb
@@ -0,0 +1,7 @@
+require 'puppet/agent'
+require 'puppet/agent/runner'
+require 'puppet/indirector/rest'
+
+class Puppet::Agent::Runner::Rest < Puppet::Indirector::REST
+ desc "Trigger Agent runs via REST."
+end
diff --git a/lib/puppet/network/handler/runner.rb b/lib/puppet/network/handler/runner.rb
index c97e4791a..070cae114 100755
--- a/lib/puppet/network/handler/runner.rb
+++ b/lib/puppet/network/handler/runner.rb
@@ -1,3 +1,5 @@
+require 'puppet/agent/runner'
+
class Puppet::Network::Handler
class MissingMasterError < RuntimeError; end # Cannot find the master client
# A simple server for triggering a new run on a Puppet client.
@@ -13,51 +15,16 @@ class Puppet::Network::Handler
# Run the client configuration right now, optionally specifying
# tags and whether to ignore schedules
def run(tags = nil, ignoreschedules = false, fg = true, client = nil, clientip = nil)
- # We need to retrieve the client
- master = Puppet::Network::Client.client(:Master).instance
-
- unless master
- raise MissingMasterError, "Could not find the master client"
- end
-
- if Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]).locked?
- Puppet.notice "Could not trigger run; already running"
- return "running"
- end
-
- if tags == ""
- tags = nil
- end
-
- if ignoreschedules == ""
- ignoreschedules == nil
- end
-
- msg = ""
- if client
- msg = "%s(%s) " % [client, clientip]
- end
- msg += "triggered run" %
- if tags
- msg += " with tags %s" % tags
- end
-
- if ignoreschedules
- msg += " ignoring schedules"
- end
+ options = {}
+ options[:tags] = tags if tags
+ options[:ignoreschedules] = ignoreschedules if ignoreschedules
+ options[:background] = !fg
- Puppet.notice msg
+ runner = Puppet::Agent::Runner.new(options)
- # And then we need to tell it to run, with this extra info.
- if fg
- master.run(:tags => tags, :ignoreschedules => ignoreschedules)
- else
- Puppet.newthread do
- master.run(:tags => tags, :ignoreschedules => ignoreschedules)
- end
- end
+ runner.run
- return "success"
+ return runner.status
end
end
end