puppet 0.16.0 → 0.18.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (185) hide show
  1. data/CHANGELOG +98 -0
  2. data/Rakefile +5 -1
  3. data/bin/puppet +1 -1
  4. data/bin/puppetca +25 -11
  5. data/bin/puppetd +189 -66
  6. data/bin/puppetdoc +79 -62
  7. data/bin/puppetmasterd +93 -49
  8. data/bin/puppetrun +385 -0
  9. data/conf/redhat/client.init +5 -2
  10. data/conf/redhat/fileserver.conf +1 -1
  11. data/conf/redhat/lsb-config.patch +51 -0
  12. data/conf/redhat/puppet.spec +45 -18
  13. data/conf/redhat/puppetd.conf +32 -4
  14. data/conf/redhat/server.init +5 -2
  15. data/conf/solaris/pkginfo +7 -0
  16. data/conf/solaris/smf/puppetd.xml +77 -0
  17. data/conf/solaris/smf/puppetmasterd.xml +77 -0
  18. data/conf/solaris/smf/svc-puppetd +66 -0
  19. data/conf/solaris/smf/svc-puppetmasterd +62 -0
  20. data/examples/code/failers/noobjectrvalue +1 -0
  21. data/examples/code/snippets/deepclassheirarchy.pp +23 -0
  22. data/examples/code/snippets/defineoverrides.pp +17 -0
  23. data/examples/code/snippets/emptyexec.pp +3 -0
  24. data/examples/code/snippets/selectorvalues.pp +6 -1
  25. data/examples/code/snippets/tagged.pp +35 -0
  26. data/ext/ldap/puppet.schema +2 -2
  27. data/install.rb +4 -2
  28. data/lib/puppet.rb +206 -15
  29. data/lib/puppet/client.rb +30 -20
  30. data/lib/puppet/client/ca.rb +2 -2
  31. data/lib/puppet/client/dipper.rb +5 -9
  32. data/lib/puppet/client/master.rb +224 -44
  33. data/lib/puppet/client/pelement.rb +54 -9
  34. data/lib/puppet/client/proxy.rb +3 -2
  35. data/lib/puppet/client/reporter.rb +34 -0
  36. data/lib/puppet/client/runner.rb +17 -0
  37. data/lib/puppet/config.rb +136 -55
  38. data/lib/puppet/daemon.rb +59 -37
  39. data/lib/puppet/element.rb +2 -1
  40. data/lib/puppet/event.rb +14 -3
  41. data/lib/puppet/filetype.rb +28 -19
  42. data/lib/puppet/log.rb +297 -132
  43. data/lib/puppet/metric.rb +31 -131
  44. data/lib/puppet/networkclient.rb +73 -46
  45. data/lib/puppet/parameter.rb +49 -1
  46. data/lib/puppet/parsedfile.rb +32 -12
  47. data/lib/puppet/parser/ast.rb +6 -1
  48. data/lib/puppet/parser/ast/astarray.rb +32 -6
  49. data/lib/puppet/parser/ast/collection.rb +91 -0
  50. data/lib/puppet/parser/ast/compdef.rb +2 -2
  51. data/lib/puppet/parser/ast/component.rb +24 -11
  52. data/lib/puppet/parser/ast/function.rb +50 -0
  53. data/lib/puppet/parser/ast/hostclass.rb +70 -22
  54. data/lib/puppet/parser/ast/node.rb +17 -8
  55. data/lib/puppet/parser/ast/nodedef.rb +1 -1
  56. data/lib/puppet/parser/ast/objectdef.rb +28 -10
  57. data/lib/puppet/parser/ast/selector.rb +4 -1
  58. data/lib/puppet/parser/functions.rb +145 -0
  59. data/lib/puppet/parser/interpreter.rb +243 -86
  60. data/lib/puppet/parser/lexer.rb +5 -4
  61. data/lib/puppet/parser/parser.rb +586 -505
  62. data/lib/puppet/parser/scope.rb +337 -187
  63. data/lib/puppet/rails.rb +115 -0
  64. data/lib/puppet/rails/database.rb +40 -0
  65. data/lib/puppet/rails/host.rb +83 -0
  66. data/lib/puppet/rails/rails_object.rb +42 -0
  67. data/lib/puppet/rails/rails_parameter.rb +5 -0
  68. data/lib/puppet/reports/rrdgraph.rb +20 -0
  69. data/lib/puppet/reports/tagmail.rb +94 -0
  70. data/lib/puppet/server.rb +20 -4
  71. data/lib/puppet/server/authconfig.rb +14 -3
  72. data/lib/puppet/server/authstore.rb +2 -2
  73. data/lib/puppet/server/ca.rb +23 -11
  74. data/lib/puppet/server/filebucket.rb +10 -10
  75. data/lib/puppet/server/fileserver.rb +4 -8
  76. data/lib/puppet/server/master.rb +19 -22
  77. data/lib/puppet/server/pelement.rb +28 -16
  78. data/lib/puppet/server/report.rb +184 -0
  79. data/lib/puppet/server/runner.rb +62 -0
  80. data/lib/puppet/server/servlet.rb +23 -9
  81. data/lib/puppet/sslcertificates/ca.rb +25 -1
  82. data/lib/puppet/statechange.rb +34 -53
  83. data/lib/puppet/storage.rb +1 -2
  84. data/lib/puppet/transaction.rb +305 -133
  85. data/lib/puppet/transaction/report.rb +42 -0
  86. data/lib/puppet/transportable.rb +57 -33
  87. data/lib/puppet/type.rb +260 -127
  88. data/lib/puppet/type/component.rb +9 -21
  89. data/lib/puppet/type/cron.rb +367 -116
  90. data/lib/puppet/type/exec.rb +15 -16
  91. data/lib/puppet/type/group.rb +9 -1
  92. data/lib/puppet/type/nameservice.rb +2 -5
  93. data/lib/puppet/type/nameservice/netinfo.rb +3 -0
  94. data/lib/puppet/type/nameservice/objectadd.rb +23 -10
  95. data/lib/puppet/type/nameservice/pw.rb +16 -3
  96. data/lib/puppet/type/package.rb +25 -75
  97. data/lib/puppet/type/package/apple.rb +15 -1
  98. data/lib/puppet/type/package/apt.rb +37 -2
  99. data/lib/puppet/type/package/blastwave.rb +136 -0
  100. data/lib/puppet/type/package/dpkg.rb +4 -4
  101. data/lib/puppet/type/package/gem.rb +119 -0
  102. data/lib/puppet/type/package/openbsd.rb +7 -6
  103. data/lib/puppet/type/package/ports.rb +7 -2
  104. data/lib/puppet/type/package/rpm.rb +1 -1
  105. data/lib/puppet/type/package/sun.rb +23 -9
  106. data/lib/puppet/type/package/sunfreeware.rb +7 -0
  107. data/lib/puppet/type/package/yum.rb +16 -9
  108. data/lib/puppet/type/parsedtype.rb +7 -5
  109. data/lib/puppet/type/parsedtype/mount.rb +55 -34
  110. data/lib/puppet/type/parsedtype/port.rb +7 -1
  111. data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
  112. data/lib/puppet/type/pfile.rb +115 -23
  113. data/lib/puppet/type/pfile/checksum.rb +18 -5
  114. data/lib/puppet/type/pfile/content.rb +2 -2
  115. data/lib/puppet/type/pfile/ensure.rb +3 -3
  116. data/lib/puppet/type/pfile/group.rb +2 -2
  117. data/lib/puppet/type/pfile/source.rb +28 -17
  118. data/lib/puppet/type/pfile/target.rb +25 -17
  119. data/lib/puppet/type/pfilebucket.rb +25 -6
  120. data/lib/puppet/type/schedule.rb +6 -6
  121. data/lib/puppet/type/service.rb +24 -14
  122. data/lib/puppet/type/service/debian.rb +1 -1
  123. data/lib/puppet/type/service/redhat.rb +13 -10
  124. data/lib/puppet/type/service/smf.rb +3 -3
  125. data/lib/puppet/type/state.rb +1 -2
  126. data/lib/puppet/type/symlink.rb +3 -4
  127. data/lib/puppet/type/user.rb +22 -10
  128. data/lib/puppet/type/yumrepo.rb +6 -1
  129. data/lib/puppet/type/zone.rb +595 -0
  130. data/lib/puppet/util.rb +58 -12
  131. data/test/client/client.rb +2 -2
  132. data/test/client/master.rb +92 -3
  133. data/test/client/pelement.rb +99 -0
  134. data/test/executables/puppetbin.rb +3 -4
  135. data/test/executables/puppetca.rb +3 -3
  136. data/test/executables/puppetd.rb +3 -3
  137. data/test/executables/puppetmasterd.rb +1 -5
  138. data/test/executables/puppetmodule.rb +2 -2
  139. data/test/language/ast.rb +200 -11
  140. data/test/language/functions.rb +245 -0
  141. data/test/language/interpreter.rb +155 -6
  142. data/test/language/lexer.rb +35 -2
  143. data/test/language/node.rb +48 -1
  144. data/test/language/parser.rb +250 -1
  145. data/test/language/rails.rb +105 -0
  146. data/test/language/scope.rb +304 -10
  147. data/test/language/snippets.rb +54 -5
  148. data/test/language/transportable.rb +60 -28
  149. data/test/other/config.rb +214 -1
  150. data/test/other/events.rb +67 -9
  151. data/test/other/log.rb +31 -5
  152. data/test/other/metrics.rb +23 -21
  153. data/test/other/parsedfile.rb +29 -2
  154. data/test/other/puppet.rb +79 -0
  155. data/test/other/report.rb +106 -0
  156. data/test/other/storage.rb +2 -2
  157. data/test/other/transactions.rb +128 -2
  158. data/test/puppet/utiltest.rb +10 -5
  159. data/test/puppettest.rb +193 -21
  160. data/test/server/authstore.rb +13 -4
  161. data/test/server/bucket.rb +33 -8
  162. data/test/server/ca.rb +44 -6
  163. data/test/server/master.rb +6 -7
  164. data/test/server/pelement.rb +15 -5
  165. data/test/server/report.rb +93 -0
  166. data/test/server/runner.rb +107 -0
  167. data/test/server/server.rb +28 -1
  168. data/test/types/cron.rb +339 -31
  169. data/test/types/file.rb +256 -24
  170. data/test/types/filebucket.rb +6 -2
  171. data/test/types/filesources.rb +41 -92
  172. data/test/types/group.rb +31 -1
  173. data/test/types/host.rb +2 -1
  174. data/test/types/mount.rb +18 -1
  175. data/test/types/package.rb +200 -18
  176. data/test/types/service.rb +5 -1
  177. data/test/types/sshkey.rb +2 -1
  178. data/test/types/symlink.rb +3 -2
  179. data/test/types/type.rb +180 -1
  180. data/test/types/user.rb +65 -27
  181. data/test/types/yumrepo.rb +15 -0
  182. data/test/types/zone.rb +437 -0
  183. metadata +43 -4
  184. data/bin/cf2puppet +0 -186
  185. data/conf/redhat/puppetmasterd.conf +0 -5
data/CHANGELOG CHANGED
@@ -1,3 +1,101 @@
1
+ 0.18.4
2
+ Another bug-fix release. The most import bug fixed is that
3
+ cronjobs again work even with initially empty crontabs.
4
+
5
+ 0.18.3
6
+ Mostly a bug-fix release; fixed small bugs in the functionality added in
7
+ 0.18.2.
8
+
9
+ 0.18.2
10
+ Added templating support.
11
+
12
+ Added reporting.
13
+
14
+ Added gem and blastwave packaging support.
15
+
16
+ 0.18.1
17
+ Added signal handlers for HUP, so both client and server deal correctly with it.
18
+
19
+ Added signal handler for USR1, which triggers a run on the client.
20
+
21
+ As usual, fixed many bugs.
22
+
23
+ Significant fixes to puppetrun -- it should behave much more correctly now.
24
+
25
+ Added "fail" function which throws a syntax error if it's encountered.
26
+
27
+ Added plugin downloading from the central server to the client. It must be
28
+ enabled with --pluginsync.
29
+
30
+ Added support for FreeBSD's special "@daily" cron schedules.
31
+
32
+ Correctly handling spaces in file sources.
33
+
34
+ Moved documentation into svn tree.
35
+
36
+ 0.18.0
37
+ Added support for a "default" node.
38
+
39
+ When multiple nodes are specified, they must now be comma-separated (this
40
+ introduces a language incompatibility).
41
+
42
+ Failed dependencies cause dependent objects within the same transaction
43
+ not to run.
44
+
45
+ Many updates to puppetrun
46
+
47
+ Many bug fixes
48
+
49
+ Function names are no longer reserved words.
50
+
51
+ Links can now replace files.
52
+
53
+ 0.17.2
54
+ Added "puppetrun" application and associated runner server and client classes.
55
+
56
+ Fixed cron support so it better supports valid values and environment settings.
57
+
58
+ 0.17.1
59
+ Fixing a bug requiring rails on all Debian boxes
60
+
61
+ Fixing a couple of other small bugs
62
+
63
+ 0.17.0
64
+ Adding ActiveRecord integration on the server
65
+
66
+ Adding export/collect functionality
67
+
68
+ Fixing many bugs
69
+
70
+ 0.16.5
71
+ Fixing a critical bug in importing classes from other files
72
+
73
+ Fixing nodename handling to actually allow dashes
74
+
75
+ 0.16.4
76
+ Fixing a critical bug in puppetd when acquiring a certificate for the first
77
+ time
78
+
79
+ 0.16.3
80
+ Some significant bug fixes
81
+
82
+ Modified puppetd so that it can now function as an agent independent
83
+ of a puppetmasterd process, e.g., using the PuppetShow web application.
84
+
85
+ 0.16.2
86
+ Modified some of the AST classes so that class names, definition names, and
87
+ node names are all set within the code being evaluated, so 'tagged(name)' returns
88
+ true while evaluating 'name', for instance.
89
+
90
+ Added '--clean' argument to puppetca to remove all traces of a given
91
+ client.
92
+
93
+ 0.16.1
94
+ Added 'tagged' and 'defined' functions.
95
+
96
+ Moved all functions to a general framework that makes it very easy to add new
97
+ functions.
98
+
1
99
  0.16.0
2
100
  Added 'tag' keyword/function.
3
101
 
data/Rakefile CHANGED
@@ -27,6 +27,10 @@ project = Rake::RedLabProject.new("puppet") do |p|
27
27
  ]
28
28
 
29
29
  p.add_dependency('facter', '1.1.0')
30
+
31
+ p.epmhosts = %w{culain}
32
+ p.sunpkghost = "sol10b"
33
+ p.rpmhost = "fedora1"
30
34
  end
31
35
 
32
36
  if project.has?(:gem)
@@ -61,4 +65,4 @@ if project.has?(:epm)
61
65
  end
62
66
  end
63
67
 
64
- # $Id: Rakefile 1079 2006-04-05 06:54:13Z luke $
68
+ # $Id: Rakefile 1249 2006-06-09 18:42:08Z luke $
data/bin/puppet CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # = Synopsis
data/bin/puppetca CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # = Synopsis
@@ -10,6 +10,7 @@
10
10
  #
11
11
  # puppetca [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
12
12
  # [-g|--generate] [-l|--list] [-s|--sign]
13
+ # [-c|--clean] [host]
13
14
  #
14
15
  # = Description
15
16
  #
@@ -29,6 +30,9 @@
29
30
  # all::
30
31
  # Operate on all outstanding requests. Only makes sense with '--sign'.
31
32
  #
33
+ # clean::
34
+ # Remove all traces of a host. This is useful when rebuilding hosts.
35
+ #
32
36
  # debug::
33
37
  # Enable full debugging.
34
38
  #
@@ -78,6 +82,7 @@ end
78
82
 
79
83
  options = [
80
84
  [ "--all", "-a", GetoptLong::NO_ARGUMENT ],
85
+ [ "--clean", "-c", GetoptLong::NO_ARGUMENT ],
81
86
  [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
82
87
  [ "--generate", "-g", GetoptLong::NO_ARGUMENT ],
83
88
  [ "--help", "-h", GetoptLong::NO_ARGUMENT ],
@@ -100,6 +105,8 @@ begin
100
105
  case opt
101
106
  when "--all"
102
107
  all = true
108
+ when "--clean"
109
+ mode = :clean
103
110
  when "--debug"
104
111
  Puppet::Log.level = :debug
105
112
  when "--generate"
@@ -141,6 +148,9 @@ Puppet.genmanifest
141
148
  begin
142
149
  ca = Puppet::SSLCertificates::CA.new()
143
150
  rescue => detail
151
+ if Puppet[:debug]
152
+ puts detail.backtrace
153
+ end
144
154
  puts detail.to_s
145
155
  exit(23)
146
156
  end
@@ -150,15 +160,23 @@ unless mode
150
160
  exit(12)
151
161
  end
152
162
 
153
- hosts = ca.list
154
- unless hosts.length > 0 or mode == :generate
155
- Puppet.info "No waiting requests"
156
- exit(0)
163
+ if mode == :generate or mode == :clean
164
+ hosts = ARGV
165
+ else
166
+ hosts = ca.list
167
+ unless hosts.length > 0
168
+ puts "No certificates to sign"
169
+ exit(0)
170
+ end
157
171
  end
158
172
 
159
173
  case mode
160
174
  when :list
161
175
  puts hosts.join("\n")
176
+ when :clean
177
+ hosts.each do |host|
178
+ ca.clean(host)
179
+ end
162
180
  when :sign
163
181
  unless ARGV.length > 0 or all
164
182
  $stderr.puts(
@@ -200,11 +218,7 @@ when :sign
200
218
  }
201
219
  when :generate
202
220
  # we need to generate a certificate for a host
203
- unless ARGV.length > 0
204
- $stderr.puts "You must specify hosts to generate certs for"
205
- exit(84)
206
- end
207
- ARGV.each { |host|
221
+ hosts.each { |host|
208
222
  puts "Generating certificate for %s" % host
209
223
  cert = Puppet::SSLCertificates::Certificate.new(
210
224
  :name => host
@@ -221,4 +235,4 @@ else
221
235
  exit(42)
222
236
  end
223
237
 
224
- # $Id: puppetca 1111 2006-04-12 17:36:14Z luke $
238
+ # $Id: puppetca 1338 2006-06-29 19:29:05Z luke $
data/bin/puppetd CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # == Synopsis
3
3
  #
4
4
  # Retrieve the client configuration from the central puppet server and apply
@@ -8,10 +8,10 @@
8
8
  #
9
9
  # = Usage
10
10
  #
11
- # puppetd [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose]
12
- # [-l|--logdest <syslog|<file>|console>] [--fqdn <host name>]
13
- # [-o|--onetime] [-w|--waitforcert <seconds>] [-t|--test]
14
- # [--disable] [--enable]
11
+ # puppetd [-D|--daemonize] [-d|--debug] [--disable] [--enable]
12
+ # [-h|--help] [--fqdn <host name>] [-l|--logdest syslog|<file>|console]
13
+ # [-o|--onetime] [--serve <handler>] [-t|--test]
14
+ # [-V|--version] [-v|--verbose] [-w|--waitforcert <seconds>]
15
15
  #
16
16
  # = Description
17
17
  #
@@ -26,9 +26,29 @@
26
26
  # Once the client has a signed certificate, it will retrieve its configuration
27
27
  # and apply it.
28
28
  #
29
- # The vast majority of options are shared between all Puppet executables and
30
- # are documented completely at
31
- # http://reductivelabs.com/projects/puppet/documentation.
29
+ # = Usage Notes
30
+ #
31
+ # +puppetd+ does its best to find a compromise between interactive use and
32
+ # daemon use. Run with no arguments and no configuration, it will go into the
33
+ # backgroun, attempt to get a signed certificate, and retrieve and apply its
34
+ # configuration every 30 minutes.
35
+ #
36
+ # Some flags are meant specifically for interactive use -- in particular,
37
+ # +test+ and +tag+ are useful. +test+ enables verobse logging, causes
38
+ # the daemon to stay in the foreground, exits if the server's configuration is
39
+ # invalid (this happens if, for instance, you've left a syntax error on the
40
+ # server), and exits after running the configuration once (rather than hanging
41
+ # around as a long-running process).
42
+ #
43
+ # +tag+ allows you to specify what portions of a configuration you want to apply.
44
+ # Puppet elements are tagged with all of the class or definition names that
45
+ # contain them, and you can use the +tag+ flag to specify one of these names,
46
+ # causing only configuration elements contained within that class or definition
47
+ # to be applied. This is very useful when you are testing new configurations --
48
+ # for instance, if you are just starting to manage +ntpd+, you would put all of
49
+ # the new elements into an +ntpd+ class, and call puppet with +--tag ntpd+,
50
+ # which would only apply that small portion of the configuration during your
51
+ # testing, rather than applying the whole thing.
32
52
  #
33
53
  # = Options
34
54
  #
@@ -36,7 +56,16 @@
36
56
  # is also a valid long argument. For example, 'server' is a valid configuration
37
57
  # parameter, so you can specify '--server <servername>' as an argument.
38
58
  #
39
- # See the configuration file for the full list of acceptable parameters.
59
+ # See the configuration file documentation at
60
+ # http://reductivelabs.com/projects/puppet/documentation/puppet-executable-reference
61
+ # for the full list of acceptable parameters.
62
+ #
63
+ # daemonize::
64
+ # Send the process into the background. This is the default unless
65
+ # +verbose+ or +debug+ is enabled.
66
+ #
67
+ # debug::
68
+ # Enable full debugging.
40
69
  #
41
70
  # disable::
42
71
  # Disable working on the local system. This puts a lock file in place,
@@ -50,9 +79,6 @@
50
79
  #
51
80
  # +puppetd+ exits after executing this.
52
81
  #
53
- # debug::
54
- # Enable full debugging.
55
- #
56
82
  # enable::
57
83
  # Enable working on the local system. This removes any lock file, causing
58
84
  # +puppetd+ to start managing the local system again (although it will continue
@@ -77,6 +103,13 @@
77
103
  # Run the configuration once, rather than as a long-running daemon. This is
78
104
  # useful for interactively running puppetd.
79
105
  #
106
+ # serve::
107
+ # Start another type of server. By default default, +puppetd+ will start
108
+ # a server that allows authenticated and authorized remote nodes to trigger
109
+ # the configuration to be pulled down and applied. You can specify
110
+ # any other type of service here that does not require configuration,
111
+ # e.g., filebucket, ca, or pelement.
112
+ #
80
113
  # test::
81
114
  # Enable the most common options used for testing. These are +onetime+,
82
115
  # +verbose+, and +no-usecacheonfailure+.
@@ -88,8 +121,12 @@
88
121
  # Print the puppet version number and exit.
89
122
  #
90
123
  # waitforcert::
91
- # Have the process wait around, continuously retrying for the certificate
92
- # each <argument> seconds.
124
+ # This option only matters for daemons that do not yet have certificates
125
+ # and it is enabled by default, with a value of 120 (seconds). This causes
126
+ # +puppetd+ to connect to the server every 2 minutes and ask it to sign a
127
+ # certificate request. This is useful for the initial setup of a puppet
128
+ # client. You can turn off waiting for certificates by specifying a time
129
+ # of 0.
93
130
  #
94
131
  # = Example
95
132
  #
@@ -104,6 +141,11 @@
104
141
  # Copyright (c) 2005, 2006 Reductive Labs, LLC
105
142
  # Licensed under the GNU Public License
106
143
 
144
+ # Do an initial trap, so that cancels don't get a stack trace.
145
+ trap(:INT) do
146
+ $stderr.puts "Cancelling startup"
147
+ exit(0)
148
+ end
107
149
 
108
150
  require 'puppet'
109
151
  require 'puppet/server'
@@ -119,6 +161,7 @@ end
119
161
 
120
162
  options = [
121
163
  [ "--centrallogging", GetoptLong::NO_ARGUMENT ],
164
+ [ "--daemonize", "-D", GetoptLong::NO_ARGUMENT ],
122
165
  [ "--disable", GetoptLong::NO_ARGUMENT ],
123
166
  [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
124
167
  [ "--enable", GetoptLong::NO_ARGUMENT ],
@@ -127,6 +170,7 @@ options = [
127
170
  [ "--logdest", "-l", GetoptLong::REQUIRED_ARGUMENT ],
128
171
  [ "--onetime", "-o", GetoptLong::NO_ARGUMENT ],
129
172
  [ "--test", "-t", GetoptLong::NO_ARGUMENT ],
173
+ [ "--no-client", GetoptLong::NO_ARGUMENT ],
130
174
  [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
131
175
  [ "--version", "-V", GetoptLong::NO_ARGUMENT ],
132
176
  [ "--waitforcert", "-w", GetoptLong::REQUIRED_ARGUMENT ]
@@ -137,40 +181,45 @@ Puppet.config.addargs(options)
137
181
 
138
182
  result = GetoptLong.new(*options)
139
183
 
140
- server = "puppet"
141
- fqdn = nil
142
184
  args = {}
143
185
 
144
- waitforcert = false
145
-
146
- onetime = false
147
-
148
- centrallogs = false
149
-
150
- setdest = false
151
-
152
- enable = false
153
- disable = false
186
+ options = {
187
+ :waitforcert => 120, # Default to checking for certs every 5 minutes
188
+ :onetime => false,
189
+ :centrallogs => false,
190
+ :setdest => false,
191
+ :enable => false,
192
+ :disable => false,
193
+ :client => true,
194
+ :fqdn => nil,
195
+ :serve => {}
196
+ }
154
197
 
155
198
  begin
156
199
  result.each { |opt,arg|
157
200
  case opt
158
201
  # First check to see if the argument is a valid configuration parameter;
159
202
  # if so, set it.
203
+ when "--daemonize"
204
+ options[:daemonize] = true
160
205
  when "--disable"
161
- disable = true
206
+ options[:disable] = true
207
+ when "--serve"
208
+ if klass = Puppet::Server::Handler.handler(arg)
209
+ options[:serve][klass.name] = klass
210
+ end
162
211
  when "--enable"
163
- enable = true
212
+ options[:enable] = true
164
213
  when "--test"
165
214
  # Enable all of the most common test options.
166
215
  Puppet.config.handlearg("--no-usecacheonfailure")
167
- onetime = true
216
+ options[:onetime] = true
168
217
  unless Puppet::Log.level == :debug
169
218
  Puppet::Log.level = :info
170
219
  end
171
220
  Puppet::Log.newdestination(:console)
172
221
  when "--centrallogging"
173
- centrallogs = true
222
+ options[:centrallogs] = true
174
223
  when "--help"
175
224
  if $haveusage
176
225
  RDoc::usage && exit
@@ -188,20 +237,22 @@ begin
188
237
  Puppet::Log.level = :debug
189
238
  Puppet::Log.newdestination(:console)
190
239
  when "--fqdn"
191
- fqdn = arg
240
+ options[:fqdn] = arg
241
+ when "--no-client"
242
+ options[:client] = false
192
243
  when "--onetime"
193
- onetime = true
244
+ options[:onetime] = true
194
245
  when "--port"
195
246
  args[:Port] = arg
196
247
  when "--logdest"
197
248
  begin
198
249
  Puppet::Log.newdestination(arg)
199
- setdest = true
250
+ options[:setdest] = true
200
251
  rescue => detail
201
252
  $stderr.puts detail.to_s
202
253
  end
203
254
  when "--waitforcert"
204
- waitforcert = arg.to_i
255
+ options[:waitforcert] = arg.to_i
205
256
  else
206
257
  Puppet.config.handlearg(opt, arg)
207
258
  end
@@ -224,22 +275,26 @@ if Puppet[:config] and File.exists? Puppet[:config]
224
275
  Puppet.config.parse(Puppet[:config])
225
276
  end
226
277
 
227
- if Puppet::Log.level == :debug or Puppet::Log.level == :info
228
- args[:Daemonize] = false
229
- else
230
- args[:Daemonize] = true
278
+ # Default to daemonizing, but if verbose or debug is specified,
279
+ # default to staying in the foreground.
280
+ unless options.include?(:daemonize)
281
+ if Puppet::Log.level == :debug or Puppet::Log.level == :info
282
+ options[:daemonize] = false
283
+ else
284
+ options[:daemonize] = true
285
+ end
231
286
  end
232
287
 
233
- unless setdest
288
+ unless options[:setdest]
234
289
  Puppet::Log.newdestination(:syslog)
235
290
  end
236
291
 
237
292
  args[:Server] = Puppet[:server]
238
- if fqdn
293
+ if options[:fqdn]
239
294
  args[:FQDN] = fqdn
240
295
  end
241
296
 
242
- if centrallogs
297
+ if options[:centrallogs]
243
298
  logdest = args[:Server]
244
299
 
245
300
  if args.include?(:Port)
@@ -248,62 +303,120 @@ if centrallogs
248
303
  Puppet::Log.newdestination(logdest)
249
304
  end
250
305
 
251
- Puppet.notice "Starting Puppet client version %s" % [Puppet.version]
252
- client = Puppet::Client::MasterClient.new(args)
306
+ if options[:onetime]
307
+ Puppet[:setpidfile] = false
308
+ end
253
309
 
254
- if enable
310
+ # We need tomake the client either way, we just don't start it
311
+ # if --no-client is set.
312
+ client = Puppet::Client::MasterClient.new(args)
313
+ if options[:enable]
255
314
  client.enable
256
- elsif disable
315
+ elsif options[:disable]
257
316
  client.disable
258
317
  end
259
318
 
260
- if enable or disable
319
+ if options[:enable] or options[:disable]
261
320
  exit(0)
262
321
  end
263
322
 
323
+ server = nil
324
+
325
+ # It'd be nice to daemonize later, but we have to daemonize before the
326
+ # waitforcert happens.
327
+ if options[:daemonize]
328
+ client.daemonize
329
+ end
330
+
264
331
  unless client.readcert
265
- if waitforcert
332
+ # If we don't already have the certificate, then create a client to
333
+ # request one.
334
+ caclient = Puppet::Client::CA.new(args)
335
+ if options[:waitforcert] > 0
266
336
  begin
267
- while ! client.requestcert do
337
+ while ! caclient.requestcert do
268
338
  Puppet.notice "Did not receive certificate"
269
- sleep waitforcert
339
+ sleep options[:waitforcert]
270
340
  end
271
341
  rescue => detail
272
342
  Puppet.err "Could not request certificate: %s" % detail.to_s
273
343
  exit(23)
274
344
  end
275
345
  else
276
- unless client.requestcert
346
+ unless caclient.requestcert
277
347
  Puppet.notice "No certificates; exiting"
278
348
  exit(1)
279
349
  end
280
350
  end
281
351
 
282
- # Now, because the Net::HTTP object cannot be modified once we've connected,
283
- # we need to recreate the client with the certs intact
284
- client = Puppet::Client::MasterClient.new(args)
352
+ # Now read the new cert in.
285
353
  unless client.readcert
286
- PUppet.err "Could not read certificates after retrieving them"
354
+ Puppet.err "Could not read certificates after retrieving them"
287
355
  exit(34)
288
356
  end
289
357
  end
290
358
 
291
- if args[:Daemonize]
292
- #exit(13)
293
- client.daemonize
359
+ objects = []
360
+
361
+ # This has to go after the certs are dealt with.
362
+ if Puppet[:listen]
363
+ unless FileTest.exists?(Puppet[:authconfig])
364
+ $stderr.puts "Will not start without authorization file %s" %
365
+ Puppet[:authconfig]
366
+ exit(14)
367
+ end
368
+
369
+ handlers = nil
370
+
371
+ if options[:serve].empty?
372
+ handlers = {:Runner => {}}
373
+ else
374
+ handlers = options[:serve].inject({}) do |hash, name, klass|
375
+ hash[name] = {}
376
+ end
377
+ end
378
+
379
+ handlers.each do |name, hash|
380
+ Puppet.info "Starting handler for %s" % name
381
+ end
382
+
383
+ args[:Handlers] = handlers
384
+ args[:Port] = Puppet[:puppetport]
385
+
386
+ begin
387
+ server = Puppet::Server.new(args)
388
+ rescue => detail
389
+ $stderr.puts detail
390
+ puts detail.backtrace
391
+ exit(1)
392
+ end
393
+
394
+ objects << server
294
395
  end
295
396
 
296
397
  # now set up the network client with the certs, now that we have them
297
398
  client.setcerts
298
399
 
299
- [:INT, :TERM].each do |signal|
300
- trap(signal) do
301
- Puppet.notice "Caught #{signal}; shutting down"
302
- client.shutdown
303
- end
400
+ if options[:client]
401
+ objects << client
304
402
  end
305
403
 
306
- if onetime
404
+ # Set traps for INT and TERM
405
+ Puppet.settraps
406
+
407
+ if options[:onetime]
408
+ unless options[:client]
409
+ $stderr.puts "onetime is specified but there is no client"
410
+ exit(43)
411
+ end
412
+
413
+ if server
414
+ Puppet.notice "Ignoring --listen on onetime run"
415
+ end
416
+
417
+ # Add the service, so the traps work correctly.
418
+ Puppet.newservice(client)
419
+
307
420
  begin
308
421
  client.run
309
422
  rescue => detail
@@ -312,11 +425,21 @@ if onetime
312
425
  puts detail.backtrace
313
426
  end
314
427
  end
428
+ exit(0)
315
429
  else
316
- client.start
430
+ if server
431
+ Puppet.newservice(server)
432
+ end
433
+
434
+ if options[:client]
435
+ Puppet.notice "Starting Puppet client version %s" % [Puppet.version]
436
+ Puppet.newservice(client)
437
+ end
438
+
439
+ Puppet.settraps
317
440
 
318
- # Mmm, hackish
319
441
  Puppet.start
320
442
  end
321
443
 
322
- # $Id: puppetd 1108 2006-04-11 23:08:48Z luke $
444
+
445
+ # $Id: puppetd 1415 2006-07-21 15:37:15Z luke $