summaryrefslogtreecommitdiffstats
path: root/bin/puppetdoc
blob: ff4e8f4ec73a6922aa902e7333c915a2900ce8bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/usr/bin/env ruby

#
# = Synopsis
#
# Generate a reference for all Puppet types.  Largely meant for internal Reductive
# Labs use.
#
# = Usage
#
#   puppetdoc [-h|--help] [-a|--arguments] [-t|--types]
#
# = Description
#
# This command generates a restructured-text document describing all installed
# Puppet types or all allowable arguments to puppet executables.  It is largely
# meant for internal use and is used to generate the reference document
# available on the Reductive Labs web site.
#
# = Options
#
# arguments::
#   Print the documentation for arguments.
#
# help::
#   Print this help message
#
# types::
#   Print the argumenst for Puppet types.  This is the default.
#
# = Example
#
#   $ puppetdoc > /tmp/reference.rst
#
# = Author
#
# Luke Kanies
#
# = Copyright
#
# Copyright (c) 2005 Reductive Labs, LLC
# Licensed under the GNU Public License

require 'puppet'
require 'getoptlong'

result = GetoptLong.new(
	[ "--mode",	"-m",			GetoptLong::REQUIRED_ARGUMENT ],
	[ "--help",		"-h",			GetoptLong::NO_ARGUMENT ]
)

debug = false

$tab = "    "

mode = :types

begin
    result.each { |opt,arg|
        case opt
            when "--mode"
                mode = arg.intern
            when "--help"
                if Puppet.feature.usage?
                    RDoc::usage && exit
                else
                    puts "No help available unless you have RDoc::usage installed"
                    exit
                end
        end
    }
rescue GetoptLong::InvalidOption => detail
    $stderr.puts "Try '#{$0} --help'"
    exit(1)
end

include Puppet::Util::Docs

# Indent every line in the chunk except those which begin with '..'.
def indent(text, tab)
    return text.gsub(/(^|\A)/, tab).gsub(/^ +\.\./, "..")
end

def paramwrap(name, text, namevar = false)
    if namevar
        name = name.to_s + " (*namevar*)"
    end

    puts "#### %s" % name
    puts text

    puts ""
end

# Print the docs for arguments
def self.configref
    puts %{---
inMenu: true
title: Configuration Reference
orderInfo: 40
---
# Puppet Configuration Reference

## Specifying Configuration Parameters

Every Puppet executable (with the exception of ``puppetdoc``) accepts all of
the arguments below, but not all of the arguments make sense for every executable.
Each argument has a section listed with it in parentheses; often, that section
will map to an executable (e.g., ``puppetd``), in which case it probably only
makes sense for that one executable.  If ``puppet`` is listed as the section,
it is most likely an option that is valid for everyone.

This will not always be the case.  I have tried to be as thorough as possible
in the descriptions of the arguments, so it should be obvious whether an
argument is appropriate or not.

These arguments can be supplied to the executables either as command-line 
arugments or in the configuration file for the appropriate executable.  For 
instance, the command-line invocation below would set the configuration directory
to /private/puppet
  
    $ puppetd --confdir=/private/puppet
  
Note that boolean options are turned on and off with a slightly different syntax
on the command line:

    $ puppetd --storeconfigs
      
    $ puppetd --no-storeconfigs

The invocations above will enable and disable, respectively, the storage of 
the client configuration.

As mentioned above, the configuration parameters can also be stored in a 
configuration file located in the configuration directory (`/etc/puppet` 
by default).  The file is named for the executable it is intended for, for
example `/etc/puppetd.conf` is the configuration file for `puppetd`.

The file, which follows INI-style formatting, should contain a bracketed
heading named for the executable, followed by pairs of parameters with their
values.  Here is an example of a very simple `puppetd.conf` file:

    [puppetd]
        confdir = /private/puppet
        storeconfigs = true
    
Note that boolean parameters must be explicitly specified as `true` or
`false` as seen above.

If you're starting out with a fresh configuration, you may wish to let
the executable generate a template configuration file for you by invoking
the executable in question with the `--genconfig` command.  The executable
will print a template configuration to standard output, which can be
redirected to a file like so:

    $ puppetd --genconfig > /etc/puppet/puppetd.conf
  
Note that this invocation will "clobber" (throw away) the contents of any
pre-existing `puppetd.conf` file, so make a backup of your present config
if it contains valuable information.
  
Like the `--genconfig` argument, the executables also accept a `--genmanifest`
argument, which will generate a manifest that can be used to manage all of 
Puppet's directories and files and prints it to standard output.  This can
likewise be redirected to a file:

    $ puppetd --genmanifest > /etc/puppet/manifests/site.pp

Puppet can also create user and group accounts for itself (one `puppet` group
and one `puppet` user) if it is invoked as `root` with the `--mkusers` argument:

    $ puppetd --mkusers
  
## Signals

The `puppetd` and `puppetmasterd` executables catch some signals for special 
handling.  Both daemons catch (`SIGHUP`), which forces the server to restart 
tself.  Predictably, interrupt and terminate (`SIGINT` and `SIGHUP`) will shut 
down the server, whether it be an instance of `puppetd` or `puppetmasterd`.

Sending the `SIGUSR1` signal to an instance of `puppetd` will cause it to 
immediately begin a new configuration transaction with the server.  This 
signal has no effect on `puppetmasterd`.


## Configuration Parameter Reference

Below is a list of all documented parameters.  Any default values are in ``block type`` at the end of the description.

}

    docs = {}
    Puppet.config.each do |name, object|
        docs[name] = object
    end

    docs.sort { |a, b|
        a[0].to_s <=> b[0].to_s
    }.each do |name, object|
        # Make each name an anchor
        puts %{#### <a name="#{name.to_s}">#{name.to_s}</a> (<em>#{object.section.to_s}</em>)}

        puts ""
        default = ""
        if val = object.value and val != ""
            default = "  ``%s``" % val
        end
        begin
            puts object.desc.gsub(/\n/, " ") + default
        rescue => detail
            puts detail.backtrace
            puts detail
        end
        puts ""
    end

end

# Print the docs for types
def self.typedocs
    puts %{---
inMenu: true
title: Type Reference
orderInfo: 40
---
# Type Reference


    }

    types = {}
    Puppet::Type.loadall

    Puppet::Type.eachtype { |type|
        next if type.name == :puppet
        next if type.name == :component
        types[type.name] = type
    }

    # Build a simple TOC
    puts "## Table of Contents"
    puts "1. <a href='#meta-parameters'>Meta-Parameters</a>"
    types.sort { |a, b| a[0].to_s <=> b[0].to_s }.each do |name, type|
        puts "1. <a href='#%s'>%s</a>" % [type.name, type.name.to_s.capitalize]
    end

    puts %{
<h2><a name="meta-parameters">Meta-Parameters</a></h2>

Metaparameters are parameters that work with any element; they are part of the
Puppet framework itself rather than being part of the implementation of any
given instance.  Thus, any defined metaparameter can be used with any instance
in your manifest, including defined components.

    }
    begin
        params = []
        Puppet::Type.eachmetaparam { |param|
            params << param
        }

        params.sort { |a,b|
            a.to_s <=> b.to_s
        }.each { |param|
            paramwrap(param.to_s, scrub(Puppet::Type.metaparamdoc(param)))
            #puts "<dt>" + param.to_s + "</dt>"
            #puts tab(1) + Puppet::Type.metaparamdoc(param).scrub.indent($tab)gsub(/\n\s*/,' ')
            #puts "<dd>"
            #puts indent(scrub(Puppet::Type.metaparamdoc(param)), $tab)
            #puts scrub(Puppet::Type.metaparamdoc(param))
            #puts "</dd>"

            #puts ""
        }
    rescue => detail
        puts detail.backtrace
        puts "incorrect metaparams: %s" % detail
        exit(1)
    end

    puts %{
## Types

- *namevar* is the parameter used to uniquely identify a type instance.
  This is the parameter that gets assigned when a string is provided before
  the colon in a type declaration.  In general, only developers will need to
  worry about which parameter is the ``namevar``.
  
  In the following code:

      file { "/etc/passwd":
          owner => root,
          group => root,
          mode => 644
      }

  "/etc/passwd" is considered the name of the file object (used for things like
  dependency handling), and because ``path`` is the namevar for ``file``, that
  string is assigned to the ``path`` parameter.

- *parameters* determine the specific configuration of the instance.  They either
  directly modify the system (internally, these are called states) or they affect
  how the instance behaves (e.g., adding a search path for ``exec`` instances
  or determining recursion on ``file`` instances).

When required binaries are specified for providers, fully qualifed paths
indicate that the binary must exist at that specific path and unqualified
binaries indicate that Puppet will search for the binary using the shell
path.

    }

    types.sort { |a,b|
        a.to_s <=> b.to_s
    }.each { |name,type|

        puts "

----------------

"

        puts "
<h2><a name='%s'>%s</a></h2>" % [name, name]
        puts scrub(type.doc) + "\n\n"

        docs = {}
        type.validstates.sort { |a,b|
            a.to_s <=> b.to_s
        }.reject { |sname|
            state = type.statebyname(sname)
            state.nodoc
        }.each { |sname|
            state = type.statebyname(sname)

            unless state
                raise "Could not retrieve state %s on type %s" % [sname, type.name]
            end

            doc = nil
            str = nil
            unless doc = state.doc
                $stderr.puts "No docs for %s[%s]" % [type, sname]
                next
            end
            doc = doc.dup
            str = doc
            str = scrub(str)

            #str = indent(str, $tab)
            docs[sname]  = str
        }

        puts "\n### %s Parameters\n" % name.to_s.capitalize
        type.parameters.sort { |a,b|
            a.to_s <=> b.to_s
        }.each { |name,param|
            #docs[name] = indent(scrub(type.paramdoc(name)), $tab)
            docs[name] = scrub(type.paramdoc(name))
        }

        docs.sort { |a, b|
            a[0].to_s <=> b[0].to_s
        }.each { |name, doc|
            namevar = type.namevar == name and name != :name
            paramwrap(name, doc, namevar)
        }
        puts "\n"
    }
end

def self.reports
    puts Puppet::Server::Report.reportdocs
end

def self.functions
    puts Puppet::Parser::Functions.functiondocs
end

unless respond_to?(mode)
    raise "Invalid mode %s" % mode
end

send(mode)

puts "

----------------

"
puts "\n*This page autogenerated on %s*" % Time.now

# $Id$