~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to lib/puppet/network/handler/runner.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/agent/runner'
 
2
 
1
3
class Puppet::Network::Handler
2
4
    class MissingMasterError < RuntimeError; end # Cannot find the master client
3
5
    # A simple server for triggering a new run on a Puppet client.
13
15
        # Run the client configuration right now, optionally specifying
14
16
        # tags and whether to ignore schedules
15
17
        def run(tags = nil, ignoreschedules = false, fg = true, client = nil, clientip = nil)
16
 
            # We need to retrieve the client
17
 
            master = Puppet::Network::Client.client(:Master).instance
18
 
 
19
 
            unless master
20
 
                raise MissingMasterError, "Could not find the master client"
21
 
            end
22
 
 
23
 
            if Puppet::Util::Pidlock.new(Puppet[:puppetdlockfile]).locked?
24
 
                Puppet.notice "Could not trigger run; already running"
25
 
                return "running"
26
 
            end
27
 
 
28
 
            if tags == ""
29
 
                tags = nil
30
 
            end
31
 
 
32
 
            if ignoreschedules == ""
33
 
                ignoreschedules == nil
34
 
            end
35
 
 
36
 
            msg = ""
37
 
            if client
38
 
                msg = "%s(%s) " % [client, clientip]
39
 
            end
40
 
            msg += "triggered run" %
41
 
            if tags
42
 
                msg += " with tags %s" % tags
43
 
            end
44
 
 
45
 
            if ignoreschedules
46
 
                msg += " ignoring schedules"
47
 
            end
48
 
 
49
 
            Puppet.notice msg
50
 
 
51
 
            # And then we need to tell it to run, with this extra info.
52
 
            if fg
53
 
                master.run(:tags => tags, :ignoreschedules => ignoreschedules)
54
 
            else
55
 
                Puppet.newthread do
56
 
                    master.run(:tags => tags, :ignoreschedules => ignoreschedules)
57
 
                end
58
 
            end
59
 
 
60
 
            return "success"
 
18
            options = {}
 
19
            options[:tags] = tags if tags
 
20
            options[:ignoreschedules] = ignoreschedules if ignoreschedules
 
21
            options[:background] = !fg
 
22
 
 
23
            runner = Puppet::Agent::Runner.new(options)
 
24
 
 
25
            runner.run
 
26
 
 
27
            return runner.status
61
28
        end
62
29
    end
63
30
end