Sha256: a235c9b29bf7ddce059d80e1cc9f2acbd55d49f98f1c032386e1a96dc23c8ea3

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

module Puppet
class Server
    class MissingMasterError < RuntimeError # Cannot find the master client
    end
    # A simple server for triggering a new run on a Puppet client.
    class Runner < Handler
        @interface = XMLRPC::Service::Interface.new("puppetrunner") { |iface|
            iface.add_method("string run(string, string)")
        }

        # Run the client configuration right now, optionally specifying
        # tags and whether to ignore schedules
        def run(tags = [], ignoreschedules = false, fg = true, client = nil, clientip = nil)
            # We need to retrieve the client
            master = Puppet::Client::MasterClient.instance

            unless master
                raise MissingMasterError, "Could not find the master client"
            end

            if master.locked?
                Puppet.notice "Could not trigger run; already running"
                return "running"
            end

            if tags == ""
                tags = nil
            end

            if ignoreschedules == ""
                ignoreschedules == nil
            end

            if client
                msg = "%s(%s) triggered run" % [client, clientip]
                if tags
                    msg += " with tags %s" % tags.join(", ")
                end

                if ignoreschedules
                    msg += " without schedules"
                end

                Puppet.notice msg
            end

            # And then we need to tell it to run, with this extra info.
            if fg
                master.run(tags, ignoreschedules)
            else
                Puppet.newthread do
                    master.run(tags, ignoreschedules)
                end
            end

            return "success"
        end
    end
end
end

# $Id: runner.rb 1325 2006-06-28 15:17:56Z luke $

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-0.18.4 lib/puppet/server/runner.rb