Class: Puppet::Application::Master

Inherits:
Puppet::Application show all
Defined in:
lib/vendor/puppet/application/master.rb

Constant Summary

Constants inherited from Puppet::Application

DOCPATTERN

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Instance Attribute Summary

Attributes inherited from Puppet::Application

#command_line, #options

Instance Method Summary collapse

Methods inherited from Puppet::Application

[], banner, clear!, clear?, #configure_indirector_routes, controlled_run, exit, find, #handlearg, #initialize, interrupted?, #name, option, option_parser_commands, #parse_options, restart!, restart_requested?, #run, run_mode, #set_run_mode, should_not_parse_config, should_parse_config, should_parse_config?, #should_parse_config?, stop!, stop_requested?

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Constructor Details

This class inherits a constructor from Puppet::Application

Instance Method Details

#compileObject

Raises:

  • (ArgumentError)


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/vendor/puppet/application/master.rb', line 150

def compile
  Puppet::Util::Log.newdestination :console
  raise ArgumentError, "Cannot render compiled catalogs without pson support" unless Puppet.features.pson?
  begin
    unless catalog = Puppet::Resource::Catalog.indirection.find(options[:node])
      raise "Could not compile catalog for #{options[:node]}"
    end

    jj catalog.to_resource
  rescue => detail
    $stderr.puts detail
    exit(30)
  end
  exit(0)
end

#helpObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vendor/puppet/application/master.rb', line 33

def help
  <<-'HELP'

puppet-master(8) -- The puppet master daemon
========

SYNOPSIS
--------
The central puppet server. Functions as a certificate authority by
default.


USAGE
-----
puppet master [-D|--daemonize|--no-daemonize] [-d|--debug] [-h|--help]
[-l|--logdest <file>|console|syslog] [-v|--verbose] [-V|--version]
[--compile <node-name>]


DESCRIPTION
-----------
This command starts an instance of puppet master, running as a daemon
and using Ruby's built-in Webrick webserver. Puppet master can also be
managed by other application servers; when this is the case, this
executable is not used.


OPTIONS
-------
Note that any configuration parameter that's valid in the configuration
file is also a valid long argument. For example, 'ssldir' is a valid
configuration parameter, so you can specify '--ssldir <directory>' as an
argument.

See the configuration file documentation at
http://docs.puppetlabs.com/references/stable/configuration.html for the
full list of acceptable parameters. A commented list of all
configuration options can also be generated by running puppet master
with '--genconfig'.

* --daemonize:
Send the process into the background. This is the default.

* --no-daemonize:
Do not send the process into the background.

* --debug:
Enable full debugging.

* --help:
Print this help message.

* --logdest:
Where to send messages. Choose between syslog, the console, and a log
file. Defaults to sending messages to syslog, or the console if
debugging or verbosity is enabled.

* --verbose:
Enable verbosity.

* --version:
Print the puppet version number and exit.

* --compile:
Compile a catalogue and output it in JSON from the puppet master. Uses
facts contained in the $vardir/yaml/ directory to compile the catalog.


EXAMPLE
-------
puppet master

DIAGNOSTICS
-----------

When running as a standalone daemon, puppet master accepts the
following signals:

* SIGHUP:
Restart the puppet master server.
* SIGINT and SIGTERM:
Shut down the puppet master server.
* SIGUSR2:
Close file descriptors for log files and reopen them. Used with logrotate.

AUTHOR
------
Luke Kanies


COPYRIGHT
---------
Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License

  HELP
end

#mainObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/vendor/puppet/application/master.rb', line 166

def main
  require 'etc'

  xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]

  xmlrpc_handlers << :CA if Puppet[:ca]

  # Make sure we've got a localhost ssl cert
  Puppet::SSL::Host.localhost

  # And now configure our server to *only* hit the CA for data, because that's
  # all it will have write access to.
  Puppet::SSL::Host.ca_location = :only if Puppet::SSL::CertificateAuthority.ca?

  if Puppet.features.root?
    begin
      Puppet::Util.chuser
    rescue => detail
      puts detail.backtrace if Puppet[:trace]
      $stderr.puts "Could not change user to #{Puppet[:user]}: #{detail}"
      exit(39)
    end
  end

  unless options[:rack]
    require 'puppet/network/server'
    @daemon.server = Puppet::Network::Server.new(:xmlrpc_handlers => xmlrpc_handlers)
    @daemon.daemonize if Puppet[:daemonize]
  else
    require 'puppet/network/http/rack'
    @app = Puppet::Network::HTTP::Rack.new(:xmlrpc_handlers => xmlrpc_handlers, :protocols => [:rest, :xmlrpc])
  end

  Puppet.notice "Starting Puppet master version #{Puppet.version}"

  unless options[:rack]
    @daemon.start
  else
    return @app
  end
end

#preinitObject



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/vendor/puppet/application/master.rb', line 130

def preinit
  Signal.trap(:INT) do
    $stderr.puts "Cancelling startup"
    exit(0)
  end

  # Create this first-off, so we have ARGV
  require 'puppet/daemon'
  @daemon = Puppet::Daemon.new
  @daemon.argv = ARGV.dup
end

#run_commandObject



142
143
144
145
146
147
148
# File 'lib/vendor/puppet/application/master.rb', line 142

def run_command
  if options[:node]
    compile
  else
    main
  end
end

#setupObject

Raises:



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/vendor/puppet/application/master.rb', line 250

def setup
  raise Puppet::Error.new("Puppet master is not supported on Microsoft Windows") if Puppet.features.microsoft_windows?

  setup_logs

  exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?

  Puppet.settings.use :main, :master, :ssl, :metrics

  setup_terminuses

  setup_ssl
end

#setup_logsObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/vendor/puppet/application/master.rb', line 208

def setup_logs
  # Handle the logging settings.
  if options[:debug] or options[:verbose]
    if options[:debug]
      Puppet::Util::Log.level = :debug
    else
      Puppet::Util::Log.level = :info
    end

    unless Puppet[:daemonize] or options[:rack]
      Puppet::Util::Log.newdestination(:console)
      options[:setdest] = true
    end
  end

  Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
end

#setup_sslObject



239
240
241
242
243
244
245
246
247
248
# File 'lib/vendor/puppet/application/master.rb', line 239

def setup_ssl
  # Configure all of the SSL stuff.
  if Puppet::SSL::CertificateAuthority.ca?
    Puppet::SSL::Host.ca_location = :local
    Puppet.settings.use :ca
    Puppet::SSL::CertificateAuthority.instance
  else
    Puppet::SSL::Host.ca_location = :none
  end
end

#setup_terminusesObject



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/vendor/puppet/application/master.rb', line 226

def setup_terminuses
  require 'puppet/file_serving/content'
  require 'puppet/file_serving/metadata'

  # Cache our nodes in yaml.  Currently not configurable.
  Puppet::Node.indirection.cache_class = :yaml

  Puppet::FileServing::Content.indirection.terminus_class = :file_server
  Puppet::FileServing::Metadata.indirection.terminus_class = :file_server

  Puppet::FileBucket::File.indirection.terminus_class = :file
end