puppet 0.13.6 → 0.16.0

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 (149) hide show
  1. data/CHANGELOG +57 -0
  2. data/Rakefile +38 -410
  3. data/bin/puppet +14 -12
  4. data/bin/puppetca +1 -3
  5. data/bin/puppetd +25 -7
  6. data/bin/puppetdoc +161 -104
  7. data/bin/puppetmasterd +4 -4
  8. data/conf/epm.list +8 -0
  9. data/conf/redhat/client.init +6 -1
  10. data/conf/redhat/no-chuser-0.15.1.patch +38 -0
  11. data/conf/redhat/puppet.spec +20 -5
  12. data/conf/redhat/puppetd.conf +1 -1
  13. data/conf/redhat/puppetmasterd.conf +1 -1
  14. data/conf/redhat/server.init +2 -4
  15. data/examples/code/snippets/{casestatement → casestatement.pp} +12 -1
  16. data/examples/code/snippets/selectorvalues.pp +15 -0
  17. data/examples/code/snippets/singleselector.pp +22 -0
  18. data/examples/code/snippets/tag.pp +9 -0
  19. data/ext/module_puppet +1 -1
  20. data/install.rb +303 -303
  21. data/lib/puppet.rb +7 -9
  22. data/lib/puppet/client.rb +18 -5
  23. data/lib/puppet/client/dipper.rb +12 -10
  24. data/lib/puppet/client/master.rb +113 -41
  25. data/lib/puppet/client/pelement.rb +20 -0
  26. data/lib/puppet/config.rb +113 -6
  27. data/lib/puppet/element.rb +1 -3
  28. data/lib/puppet/event.rb +12 -23
  29. data/lib/puppet/filetype.rb +93 -5
  30. data/lib/puppet/inifile.rb +201 -0
  31. data/lib/puppet/log.rb +18 -6
  32. data/lib/puppet/parameter.rb +80 -29
  33. data/lib/puppet/parser/ast.rb +6 -4
  34. data/lib/puppet/parser/ast/caseopt.rb +13 -4
  35. data/lib/puppet/parser/ast/casestatement.rb +2 -2
  36. data/lib/puppet/parser/ast/component.rb +4 -14
  37. data/lib/puppet/parser/ast/hostclass.rb +1 -1
  38. data/lib/puppet/parser/ast/leaf.rb +12 -0
  39. data/lib/puppet/parser/ast/node.rb +4 -4
  40. data/lib/puppet/parser/ast/objectdef.rb +5 -51
  41. data/lib/puppet/parser/ast/selector.rb +2 -0
  42. data/lib/puppet/parser/ast/tag.rb +26 -0
  43. data/lib/puppet/parser/interpreter.rb +89 -74
  44. data/lib/puppet/parser/lexer.rb +4 -3
  45. data/lib/puppet/parser/parser.rb +440 -378
  46. data/lib/puppet/parser/scope.rb +844 -887
  47. data/lib/puppet/server.rb +12 -1
  48. data/lib/puppet/server/authconfig.rb +166 -0
  49. data/lib/puppet/server/authstore.rb +8 -6
  50. data/lib/puppet/server/ca.rb +23 -26
  51. data/lib/puppet/server/filebucket.rb +24 -23
  52. data/lib/puppet/server/fileserver.rb +116 -47
  53. data/lib/puppet/server/master.rb +58 -19
  54. data/lib/puppet/server/pelement.rb +176 -0
  55. data/lib/puppet/server/rights.rb +78 -0
  56. data/lib/puppet/server/servlet.rb +19 -6
  57. data/lib/puppet/sslcertificates.rb +4 -2
  58. data/lib/puppet/sslcertificates/ca.rb +66 -34
  59. data/lib/puppet/storage.rb +20 -26
  60. data/lib/puppet/transaction.rb +49 -92
  61. data/lib/puppet/type.rb +142 -35
  62. data/lib/puppet/type/cron.rb +29 -14
  63. data/lib/puppet/type/exec.rb +92 -35
  64. data/lib/puppet/type/group.rb +29 -11
  65. data/lib/puppet/type/nameservice.rb +50 -1
  66. data/lib/puppet/type/nameservice/netinfo.rb +68 -1
  67. data/lib/puppet/type/nameservice/objectadd.rb +1 -0
  68. data/lib/puppet/type/package.rb +150 -109
  69. data/lib/puppet/type/package/apple.rb +27 -0
  70. data/lib/puppet/type/package/apt.rb +1 -0
  71. data/lib/puppet/type/package/darwinport.rb +97 -0
  72. data/lib/puppet/type/package/dpkg.rb +10 -2
  73. data/lib/puppet/type/package/freebsd.rb +19 -0
  74. data/lib/puppet/type/package/{bsd.rb → openbsd.rb} +36 -7
  75. data/lib/puppet/type/package/ports.rb +98 -0
  76. data/lib/puppet/type/package/rpm.rb +43 -7
  77. data/lib/puppet/type/package/sun.rb +53 -36
  78. data/lib/puppet/type/package/yum.rb +5 -16
  79. data/lib/puppet/type/parsedtype.rb +41 -29
  80. data/lib/puppet/type/parsedtype/host.rb +13 -5
  81. data/lib/puppet/type/parsedtype/mount.rb +250 -0
  82. data/lib/puppet/type/parsedtype/port.rb +8 -6
  83. data/lib/puppet/type/pfile.rb +284 -30
  84. data/lib/puppet/type/pfile/checksum.rb +96 -68
  85. data/lib/puppet/type/pfile/content.rb +16 -13
  86. data/lib/puppet/type/pfile/ensure.rb +64 -126
  87. data/lib/puppet/type/pfile/group.rb +12 -5
  88. data/lib/puppet/type/pfile/mode.rb +16 -4
  89. data/lib/puppet/type/pfile/source.rb +47 -73
  90. data/lib/puppet/type/pfile/target.rb +81 -0
  91. data/lib/puppet/type/pfile/uid.rb +10 -3
  92. data/lib/puppet/type/pfilebucket.rb +12 -3
  93. data/lib/puppet/type/schedule.rb +5 -1
  94. data/lib/puppet/type/service.rb +138 -66
  95. data/lib/puppet/type/service/debian.rb +9 -3
  96. data/lib/puppet/type/service/init.rb +51 -56
  97. data/lib/puppet/type/service/smf.rb +16 -6
  98. data/lib/puppet/type/state.rb +71 -32
  99. data/lib/puppet/type/symlink.rb +12 -7
  100. data/lib/puppet/type/tidy.rb +5 -1
  101. data/lib/puppet/type/user.rb +116 -20
  102. data/lib/puppet/type/yumrepo.rb +314 -0
  103. data/lib/puppet/util.rb +84 -14
  104. data/test/client/client.rb +41 -18
  105. data/test/client/master.rb +50 -4
  106. data/test/executables/puppetbin.rb +31 -4
  107. data/test/executables/puppetca.rb +18 -2
  108. data/test/language/ast.rb +201 -31
  109. data/test/language/interpreter.rb +8 -2
  110. data/test/{parser → language}/lexer.rb +1 -1
  111. data/test/language/node.rb +84 -0
  112. data/test/{parser → language}/parser.rb +1 -1
  113. data/test/language/scope.rb +101 -2
  114. data/test/language/snippets.rb +23 -2
  115. data/test/other/config.rb +99 -1
  116. data/test/other/filetype.rb +95 -0
  117. data/test/other/inifile.rb +114 -0
  118. data/test/other/log.rb +3 -2
  119. data/test/other/transactions.rb +55 -10
  120. data/test/puppet/utiltest.rb +25 -1
  121. data/test/puppettest.rb +140 -46
  122. data/test/server/authconfig.rb +56 -0
  123. data/test/server/bucket.rb +32 -18
  124. data/test/server/fileserver.rb +75 -30
  125. data/test/server/master.rb +27 -4
  126. data/test/server/pelement.rb +298 -0
  127. data/test/server/rights.rb +41 -0
  128. data/test/server/server.rb +2 -2
  129. data/test/tagging/tagging.rb +100 -1
  130. data/test/types/basic.rb +3 -3
  131. data/test/types/cron.rb +24 -1
  132. data/test/types/exec.rb +99 -1
  133. data/test/types/file.rb +298 -2
  134. data/test/types/filebucket.rb +4 -15
  135. data/test/types/filesources.rb +43 -14
  136. data/test/types/group.rb +1 -13
  137. data/test/types/mount.rb +277 -0
  138. data/test/types/package.rb +164 -33
  139. data/test/types/parameter.rb +107 -0
  140. data/test/types/port.rb +2 -1
  141. data/test/types/service.rb +37 -2
  142. data/test/types/state.rb +92 -0
  143. data/test/types/symlink.rb +30 -2
  144. data/test/types/tidy.rb +2 -14
  145. data/test/types/type.rb +35 -1
  146. data/test/types/user.rb +110 -1
  147. data/test/types/yumrepo.rb +95 -0
  148. metadata +316 -290
  149. data/test/types/filetype.rb +0 -160
@@ -40,11 +40,18 @@ module Puppet
40
40
  def retrieve
41
41
  stat = @parent.stat(false)
42
42
 
43
- if stat
44
- self.is = stat.gid
45
- else
43
+ unless stat
46
44
  self.is = :absent
45
+ return
46
+ end
47
+
48
+ # Set our method appropriately, depending on links.
49
+ if stat.ftype == "link" and @parent[:links] != :follow
50
+ @method = :lchown
51
+ else
52
+ @method = :chown
47
53
  end
54
+ self.is = stat.gid
48
55
  end
49
56
 
50
57
  # Determine if the group is valid, and if so, return the UID
@@ -98,7 +105,7 @@ module Puppet
98
105
 
99
106
  begin
100
107
  # set owner to nil so it's ignored
101
- File.chown(nil,gid,@parent[:path])
108
+ File.send(@method,nil,gid,@parent[:path])
102
109
  rescue => detail
103
110
  error = Puppet::Error.new( "failed to chgrp %s to %s: %s" %
104
111
  [@parent[:path], self.should, detail.message])
@@ -109,4 +116,4 @@ module Puppet
109
116
  end
110
117
  end
111
118
 
112
- # $Id: group.rb 965 2006-03-02 07:30:14Z luke $
119
+ # $Id: group.rb 988 2006-03-06 19:54:59Z luke $
@@ -40,7 +40,8 @@ module Puppet
40
40
  value = should
41
41
  if value.is_a?(String)
42
42
  unless value =~ /^[0-9]+$/
43
- raise Puppet::Error, "File modes can only be numbers"
43
+ raise Puppet::Error, "File modes can only be numbers, not %s" %
44
+ value.inspect
44
45
  end
45
46
  unless value =~ /^0/
46
47
  value = "0" + value
@@ -74,7 +75,19 @@ module Puppet
74
75
  return value
75
76
  end
76
77
 
78
+ def insync?
79
+ if stat = @parent.stat and stat.ftype == "link" and @parent[:links] != :follow
80
+ self.debug "Not managing symlink mode"
81
+ return true
82
+ else
83
+ return super
84
+ end
85
+ end
86
+
77
87
  def retrieve
88
+ # If we're not following links and we're a link, then we just turn
89
+ # off mode management entirely.
90
+
78
91
  if stat = @parent.stat(false)
79
92
  self.is = stat.mode & 007777
80
93
  unless defined? @fixed
@@ -94,8 +107,7 @@ module Puppet
94
107
  @parent.stat(true)
95
108
  self.retrieve
96
109
  if @is == :absent
97
- self.debug "File does not exist; cannot set mode" %
98
- @parent[:path]
110
+ self.debug "File does not exist; cannot set mode"
99
111
  return nil
100
112
  end
101
113
 
@@ -124,4 +136,4 @@ module Puppet
124
136
  end
125
137
  end
126
138
 
127
- # $Id: mode.rb 965 2006-03-02 07:30:14Z luke $
139
+ # $Id: mode.rb 1056 2006-04-03 18:05:58Z luke $
@@ -4,7 +4,7 @@ module Puppet
4
4
  PINPARAMS = [:mode, :type, :owner, :group, :checksum]
5
5
 
6
6
  attr_accessor :source, :local
7
- desc "Copy a file over the current file. Uses `checksum` to
7
+ desc "Copy a file over the current file. Uses ``checksum`` to
8
8
  determine when a file should be copied. Valid values are either
9
9
  fully qualified paths to files, or URIs. Currently supported URI
10
10
  types are *puppet* and *file*.
@@ -28,13 +28,15 @@ module Puppet
28
28
 
29
29
  "
30
30
 
31
+ uncheckable
32
+
31
33
  # Ask the file server to describe our file.
32
34
  def describe(source)
33
35
  sourceobj, path = @parent.uri2obj(source)
34
36
  server = sourceobj.server
35
37
 
36
38
  begin
37
- desc = server.describe(path)
39
+ desc = server.describe(path, @parent[:links])
38
40
  rescue NetworkClientError => detail
39
41
  self.err "Could not describe %s: %s" %
40
42
  [path, detail]
@@ -94,23 +96,6 @@ module Puppet
94
96
  return nil
95
97
  end
96
98
 
97
- # Take each of the stats and set them as states on the local file
98
- # if a value has not already been provided.
99
- @stats.each { |stat, value|
100
- next if stat == :checksum
101
- next if stat == :type
102
-
103
- # was the stat already specified, or should the value
104
- # be inherited from the source?
105
- unless @parent.argument?(stat)
106
- if state = @parent.state(stat)
107
- state.should = value
108
- else
109
- @parent[stat] = value
110
- end
111
- end
112
- }
113
-
114
99
  # If we're a normal file, then set things up to copy the file down.
115
100
  case @stats[:type]
116
101
  when "file":
@@ -143,13 +128,47 @@ module Puppet
143
128
  # we'll let the :ensure state do our work
144
129
  @should.clear
145
130
  @is = true
146
- # FIXME We should at least support symlinks, I would think...
131
+ when "link":
132
+ case @parent[:links]
133
+ when :ignore
134
+ @is = :nocopy
135
+ @should = [:nocopy]
136
+ self.info "Ignoring link %s" % @source
137
+ return
138
+ when :follow
139
+ @stats = self.describe(source, :follow)
140
+ if @stats.empty?
141
+ raise Puppet::Error, "Could not follow link %s" % @source
142
+ end
143
+ when :copy
144
+ raise Puppet::Error, "Cannot copy links yet"
145
+ end
147
146
  else
147
+ self.info @stats.inspect
148
148
  self.err "Cannot use files of type %s as sources" %
149
149
  @stats[:type]
150
- @should = nil
151
- @is = true
150
+ @should = [:nocopy]
151
+ @is = :nocopy
152
152
  end
153
+
154
+ # Take each of the stats and set them as states on the local file
155
+ # if a value has not already been provided.
156
+ @stats.each { |stat, value|
157
+ next if stat == :checksum
158
+ next if stat == :type
159
+
160
+ # was the stat already specified, or should the value
161
+ # be inherited from the source?
162
+ unless @parent.argument?(stat)
163
+ if state = @parent.state(stat)
164
+ state.should = value
165
+ else
166
+ @parent[stat] = value
167
+ end
168
+ #else
169
+ # @parent.info "Already specified %s" % stat
170
+ end
171
+ }
153
172
  end
154
173
 
155
174
  # The special thing here is that we need to make sure that 'should'
@@ -189,6 +208,9 @@ module Puppet
189
208
  end
190
209
  end
191
210
 
211
+ case @stats[:type]
212
+ when "link":
213
+ end
192
214
  unless @stats[:type] == "file"
193
215
  #if @stats[:type] == "directory"
194
216
  #[@parent.name, @is.inspect, @should.inspect]
@@ -204,7 +226,7 @@ module Puppet
204
226
  sourceobj, path = @parent.uri2obj(@source)
205
227
 
206
228
  begin
207
- contents = sourceobj.server.retrieve(path)
229
+ contents = sourceobj.server.retrieve(path, @parent[:links])
208
230
  rescue NetworkClientError => detail
209
231
  self.err "Could not retrieve %s: %s" %
210
232
  [path, detail]
@@ -221,57 +243,9 @@ module Puppet
221
243
  self.notice "Could not retrieve contents for %s" %
222
244
  @source
223
245
  end
224
-
225
- if FileTest.exists?(@parent[:path])
226
- # this makes sure we have a copy for posterity
227
- @backed = @parent.handlebackup
228
- end
229
-
230
- # create the file in a tmp location
231
- args = [@parent[:path] + ".puppettmp",
232
- File::CREAT | File::WRONLY | File::TRUNC]
233
-
234
- # try to create it with the correct modes to start
235
- # we should also be changing our effective uid/gid, but...
236
- if @parent.should(:mode) and @parent.should(:mode) != :absent
237
- args.push @parent.should(:mode)
238
- end
239
-
240
- # FIXME we should also change our effective user and group id
241
-
242
246
  exists = File.exists?(@parent[:path])
243
- begin
244
- File.open(*args) { |f|
245
- f.print contents
246
- }
247
- rescue => detail
248
- # since they said they want a backup, let's error out
249
- # if we couldn't make one
250
- raise Puppet::Error, "Could not create %s to %s: %s" %
251
- [@source, @parent[:path], detail.message]
252
- end
253
-
254
- if FileTest.exists?(@parent[:path])
255
- begin
256
- File.unlink(@parent[:path])
257
- rescue => detail
258
- self.err "Could not remove %s for replacing: %s" %
259
- [@parent[:path], detail]
260
- end
261
- end
262
247
 
263
- begin
264
- File.rename(@parent[:path] + ".puppettmp", @parent[:path])
265
- rescue => detail
266
- self.err "Could not rename tmp %s for replacing: %s" %
267
- [@parent[:path], detail]
268
- end
269
-
270
- if @stats.include? :checksum
271
- @parent.setchecksum @stats[:checksum]
272
- else
273
- raise Puppet::DevError, "We're somehow missing the remote checksum"
274
- end
248
+ @parent.write { |f| f.print contents }
275
249
 
276
250
  if exists
277
251
  return :file_changed
@@ -282,4 +256,4 @@ module Puppet
282
256
  end
283
257
  end
284
258
 
285
- # $Id: source.rb 944 2006-02-24 22:50:23Z luke $
259
+ # $Id: source.rb 1123 2006-04-20 05:14:13Z luke $
@@ -0,0 +1,81 @@
1
+ module Puppet
2
+ Puppet.type(:file).newstate(:target) do
3
+ attr_accessor :linkmaker
4
+
5
+ desc "The target for creating a link. Currently, symlinks are the
6
+ only type supported."
7
+
8
+ newvalue(:notlink) do
9
+ # We do nothing if the value is absent
10
+ return :nochange
11
+ end
12
+
13
+ # Anything else, basically
14
+ newvalue(/./) do
15
+ target = self.should
16
+
17
+ if stat = @parent.stat
18
+ unless stat.ftype == "link"
19
+ self.fail "Not replacing non-symlink"
20
+ end
21
+ File.unlink(@parent[:path])
22
+ end
23
+ Dir.chdir(File.dirname(@parent[:path])) do
24
+ unless FileTest.exists?(target)
25
+ self.debug "Not linking to non-existent '%s'" % target
26
+ :nochange # Grrr, can't return
27
+ else
28
+ Puppet::Util.asuser(@parent.asuser()) do
29
+ mode = @parent.should(:mode)
30
+ if mode
31
+ Puppet::Util.withumask(000) do
32
+ File.symlink(target, @parent[:path])
33
+ end
34
+ else
35
+ File.symlink(target, @parent[:path])
36
+ end
37
+ end
38
+
39
+ :link_created
40
+ end
41
+ end
42
+ end
43
+
44
+ def retrieve
45
+ if @parent.state(:ensure).should == :directory
46
+ @is = self.should
47
+ @linkmaker = true
48
+ else
49
+ if stat = @parent.stat
50
+ # If we're just checking the value
51
+ if (should = self.should) and
52
+ (should != :notlink) and
53
+ File.exists?(should) and
54
+ (tstat = File.lstat(should)) and
55
+ (tstat.ftype == "directory") and
56
+ @parent.recurse?
57
+ unless @parent.recurse?
58
+ raise "wtf?"
59
+ end
60
+ warning "Changing ensure to directory; recurse is %s but %s" %
61
+ [@parent[:recurse].inspect, @parent.recurse?]
62
+ @parent[:ensure] = :directory
63
+ @is = should
64
+ @linkmaker = true
65
+ else
66
+ if stat.ftype == "link"
67
+ @is = File.readlink(@parent[:path])
68
+ @linkmaker = false
69
+ else
70
+ @is = :notlink
71
+ end
72
+ end
73
+ else
74
+ @is = :absent
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ # $Id: target.rb 1125 2006-04-20 19:38:48Z luke $
@@ -85,6 +85,13 @@ module Puppet
85
85
  return
86
86
  end
87
87
 
88
+ # Set our method appropriately, depending on links.
89
+ if stat.ftype == "link" and @parent[:links] != :follow
90
+ @method = :lchown
91
+ else
92
+ @method = :chown
93
+ end
94
+
88
95
  self.is = stat.uid
89
96
 
90
97
  # On OS X, files that are owned by -2 get returned as really
@@ -139,7 +146,7 @@ module Puppet
139
146
  @parent.stat(true)
140
147
  self.retrieve
141
148
  if @is == :absent
142
- self.info "File does not exist; cannot set owner"
149
+ self.debug "File does not exist; cannot set owner"
143
150
  return nil
144
151
  end
145
152
  if self.insync?
@@ -149,7 +156,7 @@ module Puppet
149
156
  end
150
157
 
151
158
  begin
152
- File.chown(user, nil, @parent[:path])
159
+ File.send(@method, user, nil, @parent[:path])
153
160
  rescue => detail
154
161
  raise Puppet::Error, "Failed to set owner to '%s': %s" %
155
162
  [user, detail]
@@ -160,4 +167,4 @@ module Puppet
160
167
  end
161
168
  end
162
169
 
163
- # $Id: uid.rb 862 2006-01-31 02:07:56Z luke $
170
+ # $Id: uid.rb 994 2006-03-08 22:57:21Z luke $
@@ -46,8 +46,15 @@ module Puppet
46
46
 
47
47
  # get the actual filebucket object
48
48
  def self.bucket(name)
49
- oname, object = @objects.find { |oname, o| oname == name }
50
- return object.bucket
49
+ if object = self[name]
50
+ return object.bucket
51
+ else
52
+ return nil
53
+ end
54
+ end
55
+
56
+ def self.list
57
+ self.collect do |obj| obj.name end
51
58
  end
52
59
 
53
60
  def initialize(hash)
@@ -78,8 +85,10 @@ module Puppet
78
85
  )
79
86
  end
80
87
  end
88
+
89
+ @bucket.name = self.name
81
90
  end
82
91
  end
83
92
  end
84
93
 
85
- # $Id: pfilebucket.rb 841 2006-01-18 17:24:15Z luke $
94
+ # $Id: pfilebucket.rb 1124 2006-04-20 07:00:10Z luke $
@@ -295,6 +295,10 @@ module Puppet
295
295
  end
296
296
  end
297
297
 
298
+ def self.list
299
+ self.collect do |obj| obj end
300
+ end
301
+
298
302
  def self.mkdefaultschedules
299
303
  Puppet.debug "Creating default schedules"
300
304
  # Create our default schedule
@@ -338,4 +342,4 @@ module Puppet
338
342
  end
339
343
  end
340
344
 
341
- # $Id: schedule.rb 922 2006-02-16 19:10:34Z luke $
345
+ # $Id: schedule.rb 1125 2006-04-20 19:38:48Z luke $
@@ -28,21 +28,24 @@ module Puppet
28
28
 
29
29
  newvalue(:true) do
30
30
  unless @parent.respond_to?(:enable)
31
- raise Puppet::Error, "Service %s does not support enabling"
31
+ raise Puppet::Error, "Service %s does not support enabling" %
32
+ self.name
32
33
  end
33
34
  @parent.enable
34
35
  end
35
36
 
36
37
  newvalue(:false) do
37
38
  unless @parent.respond_to?(:disable)
38
- raise Puppet::Error, "Service %s does not support enabling"
39
+ raise Puppet::Error, "Service %s does not support enabling" %
40
+ self.name
39
41
  end
40
42
  @parent.disable
41
43
  end
42
44
 
43
45
  def retrieve
44
46
  unless @parent.respond_to?(:enabled?)
45
- raise Puppet::Error, "Service %s does not support enabling"
47
+ raise Puppet::Error, "Service %s does not support enabling" %
48
+ self.name
46
49
  end
47
50
  @is = @parent.enabled?
48
51
  end
@@ -104,23 +107,8 @@ module Puppet
104
107
  aliasvalue(:false, :stopped)
105
108
  aliasvalue(:true, :running)
106
109
 
107
- # munge do |should|
108
- # case should
109
- # when false,0,"0", "stopped", :stopped:
110
- # should = :stopped
111
- # when true,1,"1", :running, "running":
112
- # should = :running
113
- # else
114
- # self.warning "%s: interpreting '%s' as false" %
115
- # [self.class,should.inspect]
116
- # should = 0
117
- # end
118
- # return should
119
- # end
120
-
121
110
  def retrieve
122
111
  self.is = @parent.status
123
- self.debug "Running value is '%s'" % self.is
124
112
  end
125
113
 
126
114
  def sync
@@ -128,16 +116,23 @@ module Puppet
128
116
  case self.should
129
117
  when :running
130
118
  @parent.start
131
- self.info "started"
132
- return :service_started
119
+ event = :service_started
133
120
  when :stopped
134
- self.info "stopped"
135
121
  @parent.stop
136
- return :service_stopped
122
+ event = :service_stopped
137
123
  else
138
124
  self.debug "Not running '%s' and shouldn't be running" %
139
125
  self
140
126
  end
127
+
128
+ if state = @parent.state(:enable)
129
+ state.retrieve
130
+ unless state.insync?
131
+ state.sync
132
+ end
133
+ end
134
+
135
+ return event
141
136
  end
142
137
  end
143
138
 
@@ -148,9 +143,9 @@ module Puppet
148
143
  of this, but using this will still work, albeit with a
149
144
  warning."
150
145
 
151
- def should=(values)
146
+ munge do |value|
152
147
  @parent.warning "'running' is deprecated; please use 'ensure'"
153
- @parent[:ensure] = values
148
+ @parent[:ensure] = value
154
149
  end
155
150
  end
156
151
 
@@ -172,11 +167,14 @@ module Puppet
172
167
  # representing the module.
173
168
  munge do |type|
174
169
  if type.is_a?(String)
175
- type = @parent.class.svctype(type.intern)
170
+ type = type.intern
176
171
  end
177
- Puppet.debug "Service type is %s" % type.name
178
- @parent.extend(type)
172
+ if type.is_a?(Symbol)
173
+ typeklass = @parent.class.svctype(type)
174
+ end
175
+ @parent.extend(typeklass)
179
176
 
177
+ # Return the name, not the object
180
178
  return type
181
179
  end
182
180
  end
@@ -258,7 +256,7 @@ module Puppet
258
256
  newparam(:status) do
259
257
  desc "Specify a *status* command manually. If left
260
258
  unspecified, the status method will be determined
261
- automatically, usually by looking for the service int he
259
+ automatically, usually by looking for the service in the
262
260
  process table."
263
261
  end
264
262
 
@@ -266,6 +264,79 @@ module Puppet
266
264
  desc "Specify a *stop* command manually."
267
265
  end
268
266
 
267
+ # Retrieve the default type for the current platform.
268
+ def self.defaulttype
269
+ unless defined? @defsvctype
270
+ @defsvctype = nil
271
+ os = Facter["operatingsystem"].value
272
+ case os
273
+ when "Debian":
274
+ @defsvctype = self.svctype(:debian)
275
+ when "Solaris":
276
+ release = Facter["operatingsystemrelease"].value
277
+ if release.sub(/5\./,'').to_i < 10
278
+ @defsvctype = self.svctype(:init)
279
+ else
280
+ @defsvctype = self.svctype(:smf)
281
+ end
282
+ when "CentOS", "RedHat", "Fedora":
283
+ @defsvctype = self.svctype(:redhat)
284
+ else
285
+ if Facter["kernel"] == "Linux"
286
+ Puppet.notice "Using service type %s for %s" %
287
+ ["init", Facter["operatingsystem"].value]
288
+ @defsvctype = self.svctype(:init)
289
+ end
290
+ end
291
+
292
+ unless @defsvctype
293
+ Puppet.info "Defaulting to base service type"
294
+ @defsvctype = self.svctype(:base)
295
+ end
296
+ end
297
+
298
+ unless defined? @notifieddefault
299
+ Puppet.debug "Default service type is %s" % @defsvctype.name
300
+ @notifieddefault = true
301
+ end
302
+
303
+ return @defsvctype.name
304
+ end
305
+
306
+ # List all available services
307
+ def self.list
308
+ # First see if the default service type can list services for us
309
+ deftype = svctype(defaulttype())
310
+
311
+ names = []
312
+ if deftype.respond_to? :list
313
+ deftype.list(deftype.name)
314
+ else
315
+ Puppet.debug "Type %s does not respond to list" % deftype.name
316
+ end
317
+
318
+ self.collect { |s| s }
319
+ end
320
+
321
+ # Add a new path to our list of paths that services could be in.
322
+ def self.newpath(type, path)
323
+ type = type.intern if type.is_a? String
324
+ @paths ||= {}
325
+ @paths[type] ||= []
326
+
327
+ unless @paths[type].include? path
328
+ @paths[type] << path
329
+ end
330
+ end
331
+
332
+ def self.paths(type)
333
+ type = type.intern if type.is_a? String
334
+ @paths ||= {}
335
+ @paths[type] ||= []
336
+
337
+ @paths[type].dup
338
+ end
339
+
269
340
  # Create new subtypes of service management.
270
341
  def self.newsvctype(name, parent = nil, &block)
271
342
  if parent
@@ -303,6 +374,27 @@ module Puppet
303
374
 
304
375
  mod.module_eval(&block)
305
376
 
377
+ #unless mod.respond_to? :list
378
+ # Puppet.debug "Service type %s has no list method" % name
379
+ #end
380
+
381
+ # "module_function" makes the :list method private, so if the parent
382
+ # method also called module_function, then it's already private
383
+ if mod.public_method_defined? :list or mod.private_method_defined? :list
384
+ mod.send(:module_function, :list)
385
+ end
386
+
387
+ # mark it as a valid type
388
+ unless defined? @typeparam
389
+ @typeparam = @parameters.find { |p| p.name == :type }
390
+
391
+ unless @typeparam
392
+ raise Puppet::DevError, "Could not package type parameter"
393
+ end
394
+ end
395
+ @typeparam.newvalues(name)
396
+
397
+ # And add it to our list of types
306
398
  @modules ||= Hash.new do |hash, key|
307
399
  if key.is_a?(String)
308
400
  key = key.intern
@@ -319,49 +411,29 @@ module Puppet
319
411
 
320
412
  # Retrieve a service type.
321
413
  def self.svctype(name)
322
- @modules[name]
323
- end
324
-
325
- # Retrieve the default type for the current platform.
326
- def self.defaulttype
327
- unless defined? @defsvctype
328
- @defsvctype = nil
329
- os = Facter["operatingsystem"].value
330
- case os
331
- when "Debian":
332
- @defsvctype = self.svctype(:debian)
333
- when "Solaris":
334
- release = Facter["operatingsystemrelease"].value
335
- if release.sub(/5\./,'').to_i < 10
336
- @defsvctype = self.svctype(:init)
337
- else
338
- @defsvctype = self.svctype(:smf)
339
- end
340
- when "CentOS", "RedHat", "Fedora":
341
- @defsvctype = self.svctype(:redhat)
342
- else
343
- if Facter["kernel"] == "Linux"
344
- Puppet.notice "Using service type %s for %s" %
345
- ["init", Facter["operatingsystem"].value]
346
- @defsvctype = self.svctype(:init)
414
+ name = name.intern if name.is_a? String
415
+
416
+ # Try autoloading lacking service types.
417
+ unless @modules.include? name
418
+ begin
419
+ require "puppet/type/service/#{name}"
420
+ unless @modules.include? name
421
+ Puppet.warning(
422
+ "Loaded puppet/type/service/#{name} but " +
423
+ "service type was not created"
424
+ )
347
425
  end
348
- end
349
-
350
- unless @defsvctype
351
- Puppet.notice "Defaulting to base service type"
352
- @defsvctype = self.svctype(:base)
426
+ rescue LoadError
427
+ # nothing
353
428
  end
354
429
  end
355
-
356
- Puppet.debug "Default service type is %s" % @defsvctype.name
357
-
358
- return @defsvctype
430
+ @modules[name]
359
431
  end
360
432
 
361
433
  # Execute a command. Basically just makes sure it exits with a 0
362
434
  # code.
363
435
  def execute(type, cmd)
364
- self.info "Executing %s" % cmd.inspect
436
+ self.debug "Executing %s" % cmd.inspect
365
437
  output = %x(#{cmd} 2>&1)
366
438
  unless $? == 0
367
439
  self.fail "Could not %s %s: %s" %
@@ -437,7 +509,7 @@ module Puppet
437
509
  self.respond_to?(:statuscmd) and self.statuscmd
438
510
  )
439
511
  cmd = self[:status] || self.statuscmd
440
- self.info "Executing %s" % cmd.inspect
512
+ self.debug "Executing %s" % cmd.inspect
441
513
  output = %x(#{cmd} 2>&1)
442
514
  self.debug "%s status returned %s" %
443
515
  [self.name, output.inspect]
@@ -475,7 +547,7 @@ module Puppet
475
547
  self.info "%s is not running" % self.name
476
548
  return false
477
549
  end
478
- output = %x("kill #{pid} 2>&1")
550
+ output = %x(kill #{pid} 2>&1)
479
551
  if $? != 0
480
552
  self.fail "Could not kill %s, PID %s: %s" %
481
553
  [self.name, pid, output]
@@ -494,4 +566,4 @@ require 'puppet/type/service/debian'
494
566
  require 'puppet/type/service/redhat'
495
567
  require 'puppet/type/service/smf'
496
568
 
497
- # $Id: service.rb 938 2006-02-24 20:01:01Z luke $
569
+ # $Id: service.rb 1125 2006-04-20 19:38:48Z luke $