2
require 'puppet/application'
4
require 'puppet/daemon'
5
require 'puppet/configurer'
6
require 'puppet/network/client'
8
Puppet::Application.new(:puppetd) do
12
attr_accessor :explicit_waitforcert, :args, :agent, :daemon
15
# Do an initial trap, so that cancels don't get a stack trace.
17
$stderr.puts "Cancelling startup"
22
:waitforcert => 120, # Default to checking for certs every 5 minutes
26
:centrallogs => false,
37
@explicit_waitforcert = false
39
@daemon = Puppet::Daemon.new
40
@daemon.argv = ARGV.dup
43
option("--centrallogging")
46
option("--debug","-d")
47
option("--fqdn FQDN","-f")
49
option("--verbose","-v")
51
option("--serve HANDLER", "-s") do |arg|
52
if Puppet::Network::Handler.handler(arg)
53
options[:serve] << arg.to_sym
55
raise "Could not find handler for %s" % arg
59
option("--no-client") do |arg|
60
options[:client] = false
63
option("--onetime", "-o") do |arg|
64
options[:onetime] = true
65
options[:waitforcert] = 0 unless @explicit_waitforcert
68
option("--logdest DEST", "-l DEST") do |arg|
70
Puppet::Util::Log.newdestination(arg)
71
options[:setdest] = true
76
$stderr.puts detail.to_s
80
option("--waitforcert WAITFORCERT", "-w") do |arg|
81
options[:waitforcert] = arg.to_i
82
@explicit_waitforcert = true
85
option("--port PORT","-p") do |arg|
90
return :onetime if options[:onetime]
95
unless options[:client]
96
$stderr.puts "onetime is specified but there is no client"
100
@daemon.set_signal_traps
106
puts detail.backtrace
108
Puppet.err detail.to_s
114
Puppet.notice "Starting Puppet client version %s" % [Puppet.version]
119
# Enable all of the most common test options.
121
Puppet.settings.handlearg("--ignorecache")
122
Puppet.settings.handlearg("--no-usecacheonfailure")
123
Puppet.settings.handlearg("--no-splay")
124
Puppet.settings.handlearg("--show_diff")
125
Puppet.settings.handlearg("--no-daemonize")
126
options[:verbose] = true
127
options[:onetime] = true
128
options[:waitforcert] = 0
131
# Handle the logging settings.
133
if options[:debug] or options[:verbose]
134
Puppet::Util::Log.newdestination(:console)
136
Puppet::Util::Log.level = :debug
138
Puppet::Util::Log.level = :info
142
unless options[:setdest]
143
Puppet::Util::Log.newdestination(:syslog)
147
def enable_disable_client(agent)
150
elsif options[:disable]
157
unless FileTest.exists?(Puppet[:authconfig])
158
Puppet.err "Will not start without authorization file %s" %
165
if options[:serve].empty?
168
handlers = options[:serve]
171
require 'puppet/network/server'
172
# No REST handlers yet.
173
server = Puppet::Network::Server.new(:xmlrpc_handlers => handlers, :port => Puppet[:puppetport])
175
@daemon.server = server
179
setup_test if options[:test]
183
if Puppet.settings.print_configs?
184
exit(Puppet.settings.print_configs ? 0 : 1)
187
# If noop is set, then also enable diffs
189
Puppet[:show_diff] = true
192
args[:Server] = Puppet[:server]
194
args[:FQDN] = options[:fqdn]
195
Puppet[:certname] = options[:fqdn]
198
if options[:centrallogs]
199
logdest = args[:Server]
201
if args.include?(:Port)
202
logdest += ":" + args[:Port]
204
Puppet::Util::Log.newdestination(logdest)
207
Puppet.settings.use :main, :puppetd, :ssl
209
# We need to specify a ca location for things to work, but
210
# until the REST cert transfers are working, it needs to
212
Puppet::SSL::Host.ca_location = :remote
214
Puppet::Transaction::Report.terminus_class = :rest
216
Puppet::Resource::Catalog.terminus_class = :rest
217
Puppet::Resource::Catalog.cache_class = :yaml
219
Puppet::Node::Facts.terminus_class = :facter
221
# We need tomake the client either way, we just don't start it
222
# if --no-client is set.
223
@agent = Puppet::Agent.new(Puppet::Configurer)
225
enable_disable_client(@agent) if options[:enable] or options[:disable]
227
@daemon.agent = agent if options[:client]
229
# It'd be nice to daemonize later, but we have to daemonize before the
230
# waitforcert happens.
231
if Puppet[:daemonize]
235
host = Puppet::SSL::Host.new
236
cert = host.wait_for_cert(options[:waitforcert])
240
# This has to go after the certs are dealt with.
242
unless options[:onetime]
245
Puppet.notice "Ignoring --listen on onetime run"