puppet 0.9.2

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 (182) hide show
  1. data/CHANGELOG +0 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +17 -0
  4. data/README +24 -0
  5. data/Rakefile +294 -0
  6. data/TODO +4 -0
  7. data/bin/cf2puppet +186 -0
  8. data/bin/puppet +176 -0
  9. data/bin/puppetca +213 -0
  10. data/bin/puppetd +246 -0
  11. data/bin/puppetdoc +184 -0
  12. data/bin/puppetmasterd +258 -0
  13. data/examples/code/allatonce +13 -0
  14. data/examples/code/assignments +11 -0
  15. data/examples/code/classing +35 -0
  16. data/examples/code/components +73 -0
  17. data/examples/code/execs +16 -0
  18. data/examples/code/failers/badclassnoparam +10 -0
  19. data/examples/code/failers/badclassparam +10 -0
  20. data/examples/code/failers/badcompnoparam +9 -0
  21. data/examples/code/failers/badcompparam +9 -0
  22. data/examples/code/failers/badtypeparam +3 -0
  23. data/examples/code/file.bl +11 -0
  24. data/examples/code/filedefaults +10 -0
  25. data/examples/code/fileparsing +116 -0
  26. data/examples/code/filerecursion +15 -0
  27. data/examples/code/functions +3 -0
  28. data/examples/code/groups +7 -0
  29. data/examples/code/head +30 -0
  30. data/examples/code/importing +8 -0
  31. data/examples/code/nodes +20 -0
  32. data/examples/code/one +8 -0
  33. data/examples/code/relationships +34 -0
  34. data/examples/code/selectors +28 -0
  35. data/examples/code/simpletests +11 -0
  36. data/examples/code/snippets/argumentdefaults +14 -0
  37. data/examples/code/snippets/casestatement +39 -0
  38. data/examples/code/snippets/classheirarchy.pp +15 -0
  39. data/examples/code/snippets/classincludes.pp +17 -0
  40. data/examples/code/snippets/classpathtest +11 -0
  41. data/examples/code/snippets/dirchmod +19 -0
  42. data/examples/code/snippets/failmissingexecpath.pp +13 -0
  43. data/examples/code/snippets/falsevalues.pp +3 -0
  44. data/examples/code/snippets/filecreate +11 -0
  45. data/examples/code/snippets/implicititeration +15 -0
  46. data/examples/code/snippets/multipleinstances +7 -0
  47. data/examples/code/snippets/namevartest +9 -0
  48. data/examples/code/snippets/scopetest +13 -0
  49. data/examples/code/snippets/selectorvalues.pp +22 -0
  50. data/examples/code/snippets/simpledefaults +5 -0
  51. data/examples/code/snippets/simpleselector +38 -0
  52. data/examples/code/svncommit +13 -0
  53. data/examples/root/bin/sleeper +69 -0
  54. data/examples/root/etc/configfile +0 -0
  55. data/examples/root/etc/debian-passwd +29 -0
  56. data/examples/root/etc/debian-syslog.conf +71 -0
  57. data/examples/root/etc/init.d/sleeper +65 -0
  58. data/examples/root/etc/otherfile +0 -0
  59. data/examples/root/etc/puppet/fileserver.conf +3 -0
  60. data/examples/root/etc/puppet/puppetmasterd.conf +10 -0
  61. data/ext/module:puppet +195 -0
  62. data/install.rb +270 -0
  63. data/lib/puppet.rb +249 -0
  64. data/lib/puppet/base64.rb +19 -0
  65. data/lib/puppet/client.rb +519 -0
  66. data/lib/puppet/config.rb +49 -0
  67. data/lib/puppet/daemon.rb +208 -0
  68. data/lib/puppet/element.rb +71 -0
  69. data/lib/puppet/event.rb +259 -0
  70. data/lib/puppet/log.rb +321 -0
  71. data/lib/puppet/metric.rb +250 -0
  72. data/lib/puppet/parsedfile.rb +38 -0
  73. data/lib/puppet/parser/ast.rb +1560 -0
  74. data/lib/puppet/parser/interpreter.rb +150 -0
  75. data/lib/puppet/parser/lexer.rb +226 -0
  76. data/lib/puppet/parser/parser.rb +1354 -0
  77. data/lib/puppet/parser/scope.rb +755 -0
  78. data/lib/puppet/server.rb +170 -0
  79. data/lib/puppet/server/authstore.rb +227 -0
  80. data/lib/puppet/server/ca.rb +140 -0
  81. data/lib/puppet/server/filebucket.rb +147 -0
  82. data/lib/puppet/server/fileserver.rb +477 -0
  83. data/lib/puppet/server/logger.rb +43 -0
  84. data/lib/puppet/server/master.rb +103 -0
  85. data/lib/puppet/server/servlet.rb +247 -0
  86. data/lib/puppet/sslcertificates.rb +737 -0
  87. data/lib/puppet/statechange.rb +150 -0
  88. data/lib/puppet/storage.rb +95 -0
  89. data/lib/puppet/transaction.rb +179 -0
  90. data/lib/puppet/transportable.rb +151 -0
  91. data/lib/puppet/type.rb +1354 -0
  92. data/lib/puppet/type/component.rb +141 -0
  93. data/lib/puppet/type/cron.rb +543 -0
  94. data/lib/puppet/type/exec.rb +316 -0
  95. data/lib/puppet/type/group.rb +152 -0
  96. data/lib/puppet/type/nameservice.rb +3 -0
  97. data/lib/puppet/type/nameservice/netinfo.rb +173 -0
  98. data/lib/puppet/type/nameservice/objectadd.rb +146 -0
  99. data/lib/puppet/type/nameservice/posix.rb +200 -0
  100. data/lib/puppet/type/package.rb +420 -0
  101. data/lib/puppet/type/package/apt.rb +70 -0
  102. data/lib/puppet/type/package/dpkg.rb +108 -0
  103. data/lib/puppet/type/package/rpm.rb +81 -0
  104. data/lib/puppet/type/package/sun.rb +117 -0
  105. data/lib/puppet/type/package/yum.rb +58 -0
  106. data/lib/puppet/type/pfile.rb +569 -0
  107. data/lib/puppet/type/pfile/checksum.rb +219 -0
  108. data/lib/puppet/type/pfile/create.rb +108 -0
  109. data/lib/puppet/type/pfile/group.rb +129 -0
  110. data/lib/puppet/type/pfile/mode.rb +131 -0
  111. data/lib/puppet/type/pfile/source.rb +264 -0
  112. data/lib/puppet/type/pfile/type.rb +31 -0
  113. data/lib/puppet/type/pfile/uid.rb +166 -0
  114. data/lib/puppet/type/pfilebucket.rb +80 -0
  115. data/lib/puppet/type/pprocess.rb +97 -0
  116. data/lib/puppet/type/service.rb +347 -0
  117. data/lib/puppet/type/service/base.rb +17 -0
  118. data/lib/puppet/type/service/debian.rb +50 -0
  119. data/lib/puppet/type/service/init.rb +145 -0
  120. data/lib/puppet/type/service/smf.rb +29 -0
  121. data/lib/puppet/type/state.rb +182 -0
  122. data/lib/puppet/type/symlink.rb +183 -0
  123. data/lib/puppet/type/tidy.rb +183 -0
  124. data/lib/puppet/type/typegen.rb +149 -0
  125. data/lib/puppet/type/typegen/filerecord.rb +243 -0
  126. data/lib/puppet/type/typegen/filetype.rb +316 -0
  127. data/lib/puppet/type/user.rb +290 -0
  128. data/lib/puppet/util.rb +138 -0
  129. data/test/certmgr/certmgr.rb +265 -0
  130. data/test/client/client.rb +203 -0
  131. data/test/executables/puppetbin.rb +53 -0
  132. data/test/executables/puppetca.rb +79 -0
  133. data/test/executables/puppetd.rb +71 -0
  134. data/test/executables/puppetmasterd.rb +153 -0
  135. data/test/executables/puppetmodule.rb +60 -0
  136. data/test/language/ast.rb +412 -0
  137. data/test/language/interpreter.rb +71 -0
  138. data/test/language/scope.rb +412 -0
  139. data/test/language/snippets.rb +445 -0
  140. data/test/other/events.rb +111 -0
  141. data/test/other/log.rb +195 -0
  142. data/test/other/metrics.rb +92 -0
  143. data/test/other/overrides.rb +115 -0
  144. data/test/other/parsedfile.rb +31 -0
  145. data/test/other/relationships.rb +113 -0
  146. data/test/other/state.rb +106 -0
  147. data/test/other/storage.rb +39 -0
  148. data/test/other/transactions.rb +235 -0
  149. data/test/parser/lexer.rb +120 -0
  150. data/test/parser/parser.rb +180 -0
  151. data/test/puppet/conffiles.rb +104 -0
  152. data/test/puppet/defaults.rb +100 -0
  153. data/test/puppet/error.rb +23 -0
  154. data/test/puppet/utiltest.rb +120 -0
  155. data/test/puppettest.rb +774 -0
  156. data/test/server/authstore.rb +209 -0
  157. data/test/server/bucket.rb +227 -0
  158. data/test/server/ca.rb +201 -0
  159. data/test/server/fileserver.rb +710 -0
  160. data/test/server/logger.rb +175 -0
  161. data/test/server/master.rb +150 -0
  162. data/test/server/server.rb +130 -0
  163. data/test/tagging/tagging.rb +80 -0
  164. data/test/test +51 -0
  165. data/test/types/basic.rb +119 -0
  166. data/test/types/component.rb +272 -0
  167. data/test/types/cron.rb +261 -0
  168. data/test/types/exec.rb +273 -0
  169. data/test/types/file.rb +616 -0
  170. data/test/types/filebucket.rb +167 -0
  171. data/test/types/fileignoresource.rb +287 -0
  172. data/test/types/filesources.rb +587 -0
  173. data/test/types/filetype.rb +162 -0
  174. data/test/types/group.rb +271 -0
  175. data/test/types/package.rb +205 -0
  176. data/test/types/query.rb +101 -0
  177. data/test/types/service.rb +100 -0
  178. data/test/types/symlink.rb +93 -0
  179. data/test/types/tidy.rb +124 -0
  180. data/test/types/type.rb +135 -0
  181. data/test/types/user.rb +371 -0
  182. metadata +243 -0
@@ -0,0 +1,80 @@
1
+ # An interface for managing filebuckets from puppet
2
+
3
+ # $Id: pfilebucket.rb 632 2005-09-07 05:28:28Z luke $
4
+
5
+ require 'puppet/server/filebucket'
6
+
7
+ module Puppet
8
+ class Type
9
+ class PFileBucket < Type
10
+ attr_reader :bucket
11
+
12
+ @states = []
13
+
14
+ @parameters = [
15
+ :name,
16
+ :server,
17
+ :path,
18
+ :port
19
+ ]
20
+
21
+ @doc = "A repository for backing up files. If no filebucket is
22
+ defined, then files will be backed up in their current directory,
23
+ but the filebucket can be either a host- or site-global repository
24
+ for backing up. It stores files and returns the MD5 sum, which
25
+ can later be used to retrieve the file if restoration becomes
26
+ necessary. A filebucket does not do any work itself; instead,
27
+ it can be specified as the value of *backup* in a **file** object."
28
+
29
+ @paramdoc[:name] = "The name of the filebucket."
30
+ @paramdoc[:server] = "The server providing the filebucket. If this is
31
+ not specified, then the bucket is local and *path* must be specified."
32
+ @paramdoc[:port] = "The port on which the remote server is listening.
33
+ Defaults to the normal Puppet port, %s." % Puppet[:masterport]
34
+ @paramdoc[:path] = "The path to the local filebucket. If this is
35
+ not specified, then the bucket is remote and *server* must be
36
+ specified."
37
+
38
+ @name = :filebucket
39
+ @namevar = :name
40
+
41
+ # get the actual filebucket object
42
+ def self.bucket(name)
43
+ oname, object = @objects.find { |oname, o| oname == name }
44
+ return object.bucket
45
+ end
46
+
47
+ def initialize(hash)
48
+ super
49
+
50
+ if @parameters.include?(:server)
51
+ @parameters[:port] ||= FileBucket::DEFAULTPORT
52
+ begin
53
+ @bucket = Puppet::Client::Dipper.new(
54
+ :Server => @parameters[:server],
55
+ :Port => @parameters[:port]
56
+ )
57
+ rescue => detail
58
+ raise Puppet::Error.new(
59
+ "Could not create remote filebucket: %s" % detail
60
+ )
61
+ end
62
+ else
63
+ @parameters[:path] ||= Puppet[:bucketdir]
64
+ begin
65
+ @bucket = Puppet::Client::Dipper.new(
66
+ :Path => @parameters[:path]
67
+ )
68
+ rescue => detail
69
+ raise Puppet::Error.new(
70
+ "Could not create local filebucket: %s" % detail
71
+ )
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+
80
+ # $Id: pfilebucket.rb 632 2005-09-07 05:28:28Z luke $
@@ -0,0 +1,97 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # DISABLED
4
+ # I'm only working on services, not processes, right now
5
+
6
+ module Puppet
7
+ class State
8
+ class PProcessRunning < State
9
+ @doc = "Whether a process should be running. **true**/*false*"
10
+ def retrieve
11
+ running = 0
12
+ regex = Regexp.new(@params[:pattern])
13
+ begin
14
+ # this ps is only tested on Solaris
15
+ # XXX yeah, this definitely needs to be fixed...
16
+ %x{ps -ef -U #{@params[:user]}}.split("\n").each { |process|
17
+ if regex.match(process)
18
+ running += 1
19
+ end
20
+ }
21
+ rescue
22
+ # this isn't correct, but what the hell
23
+ Puppet::Message.new(
24
+ :level => :error,
25
+ :source => self.parent,
26
+ :message => "Failed to run ps"
27
+ )
28
+ end
29
+
30
+ self.state = running
31
+ debug "there are #{running} #{self.parent} processes for start"
32
+ end
33
+
34
+ def <=>(other)
35
+ self.state < 1
36
+ end
37
+
38
+ def fix
39
+ require 'etc'
40
+ # ruby is really cool
41
+ uid = 0
42
+ if @params[:user].is_a? Integer
43
+ uid = @params[:user]
44
+ else
45
+ uid = Etc.getpwnam(@params[:user]).uid
46
+ end
47
+ Kernel.fork {
48
+ PProcess.uid = uid
49
+ PProcess.euid = uid
50
+ string = @params[:binary] + (@params[:arguments] || "")
51
+ Puppet::Message.new(
52
+ :level => :notice,
53
+ :source => self.parent,
54
+ :message => "starting"
55
+ )
56
+ Kernel.exec(string)
57
+ }
58
+ end
59
+ end
60
+ end
61
+ class Type
62
+ class PProcess < Type
63
+ attr_reader :stat, :path
64
+ @parameters = [:start, :stop, :user, :pattern, :binary, :arguments]
65
+ @name = :process
66
+
67
+ @paramdoc[:start] = "How to start the process. Must be a fully
68
+ qualified path."
69
+ @paramdoc[:stop] = "How to stop the process. Must be a fully
70
+ qualified path."
71
+ @paramdoc[:user] = "Which user to run the proces as."
72
+ @paramdoc[:pattern] = "The search pattern to use to determine
73
+ whether the process is currently running."
74
+ @paramdoc[:binary] = "The binary to actually execute."
75
+ @paramdoc[:arguments] = "The arguments to pass the binary."
76
+
77
+ @doc = "**Disabled. Use `service` instead.** Manage running
78
+ processes."
79
+
80
+ @namevar = :pattern
81
+
82
+ Puppet::Relation.new(self, Puppet::Operation::Start, {
83
+ :user => :user,
84
+ :pattern => :pattern,
85
+ :binary => :binary,
86
+ :arguments => :arguments
87
+ })
88
+
89
+ Puppet::Relation.new(self, Puppet::Operation::Stop, {
90
+ :user => :user,
91
+ :pattern => :pattern
92
+ })
93
+
94
+ end # Puppet::Type::PProcess
95
+ end # Puppet::Type
96
+
97
+ end
@@ -0,0 +1,347 @@
1
+ # This is our main way of managing processes right now.
2
+ #
3
+ # a service is distinct from a process in that services
4
+ # can only be managed through the interface of an init script
5
+ # which is why they have a search path for initscripts and such
6
+
7
+ module Puppet
8
+ class State
9
+ # Handle whether the service is started at boot time.
10
+ class ServiceEnabled < State
11
+ @doc = "Whether a service should be enabled to start at boot.
12
+ **true**/*false*/*runlevel*"
13
+ @name = :enabled
14
+
15
+ def retrieve
16
+ unless @parent.respond_to?(:enabled?)
17
+ raise Puppet::Error, "Service %s does not support enabling"
18
+ end
19
+ @is = @parent.enabled?
20
+ end
21
+
22
+ def shouldprocess(should)
23
+ @runlevel = nil
24
+ case should
25
+ when true: return :enabled
26
+ when false: return :disabled
27
+ when /^\d+$/:
28
+ @runlevel = should
29
+ return :enabled
30
+ else
31
+ raise Puppet::Error, "Invalid 'enabled' value %s" % should
32
+ end
33
+ end
34
+
35
+ def sync
36
+ case self.should
37
+ when :enabled
38
+ unless @parent.respond_to?(:enable)
39
+ raise Puppet::Error, "Service %s does not support enabling"
40
+ end
41
+ @parent.enable(@runlevel)
42
+ return :service_enabled
43
+ when :disabled
44
+ unless @parent.respond_to?(:disable)
45
+ raise Puppet::Error,
46
+ "Service %s does not support disabling"
47
+ end
48
+ @parent.disable
49
+ return :service_disabled
50
+ end
51
+ end
52
+ end
53
+
54
+ # Handle whether the service should actually be running right now.
55
+ class ServiceRunning < State
56
+ @doc = "Whether a service should be running. **true**/*false*"
57
+ @name = :running
58
+
59
+ def shouldprocess(should)
60
+ case should
61
+ when false,0,"0", "stopped", :stopped:
62
+ should = :stopped
63
+ when true,1,"1", :running, "running":
64
+ should = :running
65
+ else
66
+ self.warning "%s: interpreting '%s' as false" %
67
+ [self.class,should]
68
+ should = 0
69
+ end
70
+ self.debug "Service should is %s" % should
71
+ return should
72
+ end
73
+
74
+ def retrieve
75
+ self.is = @parent.status
76
+ self.debug "Running value is '%s'" % self.is
77
+ end
78
+
79
+ def sync
80
+ event = nil
81
+ case self.should
82
+ when :running
83
+ @parent.start
84
+ event = :service_started
85
+ when :stopped
86
+ @parent.stop
87
+ event = :service_stopped
88
+ else
89
+ self.debug "Not running '%s' and shouldn't be running" %
90
+ self
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ class Type
97
+ class Service < Type
98
+ attr_reader :stat
99
+ @states = [
100
+ Puppet::State::ServiceRunning
101
+ ]
102
+ @parameters = [
103
+ :binary,
104
+ :hasstatus,
105
+ :name,
106
+ :path,
107
+ :pattern,
108
+ :restart,
109
+ :start,
110
+ :status,
111
+ :stop,
112
+ :type
113
+ ]
114
+
115
+ @paramdoc[:binary] = "The path to the daemon. This is only used for
116
+ systems that do not support init scripts."
117
+ @paramdoc[:hasstatus] = "Declare the the service's init script has a
118
+ functional status command. This is assumed to be default for
119
+ most systems, although there might be platforms on which this is
120
+ assumed to be true."
121
+ @paramdoc[:name] = "The name of the service to run. This name
122
+ is used to find the init script in the search path."
123
+ @paramdoc[:path] = "The search path for finding init scripts.
124
+ There is currently no default, but hopefully soon there will
125
+ be a reasonable default for all platforms."
126
+ @paramdoc[:pattern] = "The pattern to search for in the process table.
127
+ This is used for stopping services on platforms that do not
128
+ support init scripts, and is also used for determining service
129
+ status on those service whose init scripts do not include a status
130
+ command."
131
+ @paramdoc[:restart] = "Specify a *restart* command manually. If left
132
+ unspecified, the restart method will be determined automatically."
133
+ @paramdoc[:start] = "Specify a *start* command manually. If left
134
+ unspecified, the start method will be determined automatically."
135
+ @paramdoc[:status] = "Specify a *status* command manually. If left
136
+ unspecified, the status method will be determined automatically."
137
+ @paramdoc[:stop] = "Specify a *stop* command manually. If left
138
+ unspecified, the stop method will be determined automatically."
139
+
140
+ @doc = "Manage running services. Rather than supporting managing
141
+ individual processes, puppet uses init scripts to simplify
142
+ specification of how to start, stop, or test processes. The
143
+ `path` parameter is provided to enable creation of multiple
144
+ init script directories, including supporting them for normal
145
+ users."
146
+ @name = :service
147
+ @namevar = :name
148
+
149
+ # Return the service type we're using. Default to the Service
150
+ # class itself, but could be set to a module.
151
+ class << self
152
+ attr_accessor :svctype
153
+ end
154
+
155
+ # Retrieve the default type for the current platform.
156
+ def self.defaulttype
157
+ unless defined? @defsvctype
158
+ @defsvctype = nil
159
+ os = Facter["operatingsystem"].value
160
+ case os
161
+ when "Linux":
162
+ case Facter["distro"].value
163
+ when "Debian":
164
+ @defsvctype = Puppet::ServiceTypes::DebianSvc
165
+ end
166
+ when "SunOS":
167
+ release = Float(Facter["operatingsystemrelease"].value)
168
+ if release < 5.10
169
+ @defsvctype = Puppet::ServiceTypes::InitSvc
170
+ else
171
+ @defsvctype = Puppet::ServiceTypes::SMFSvc
172
+ end
173
+ end
174
+
175
+ unless @defsvctype
176
+ Puppet.notice "Defaulting to base service type"
177
+ @defsvctype = Puppet::ServiceTypes::BaseSvc
178
+ end
179
+ end
180
+
181
+ return @defsvctype
182
+ end
183
+
184
+ # Execute a command. Basically just makes sure it exits with a 0
185
+ # code.
186
+ def execute(type, cmd)
187
+ output = %x(#{cmd} 2>&1)
188
+ unless $? == 0
189
+ raise Puppet::Error, "Could not %s %s: %s" %
190
+ [type, self.name, output.chomp]
191
+ end
192
+ end
193
+
194
+ # Get the process ID for a running process. Requires the 'pattern'
195
+ # parameter.
196
+ def getpid
197
+ unless self[:pattern]
198
+ raise Puppet::Error,
199
+ "Either a stop command or a pattern must be specified"
200
+ end
201
+ ps = Facter["ps"].value
202
+ unless ps and ps != ""
203
+ raise Puppet::Error,
204
+ "You must upgrade Facter to a version that includes 'ps'"
205
+ end
206
+ regex = Regexp.new(self[:pattern])
207
+ IO.popen(ps) { |table|
208
+ table.each { |line|
209
+ if regex.match(line)
210
+ ary = line.sub(/^\s+/, '').split(/\s+/)
211
+ return ary[1]
212
+ end
213
+ }
214
+ }
215
+
216
+ return nil
217
+ end
218
+
219
+ # Initialize the service. This is basically responsible for merging
220
+ # in the right module.
221
+ def initialize(hash)
222
+ # We have to extend the object before we call 'super', so that
223
+ # the parameter methods are called correctly.
224
+ type = hash[:type] ||
225
+ hash["type"] ||
226
+ self.class.defaulttype
227
+
228
+ if type.is_a?(String)
229
+ type = type2module(type)
230
+ end
231
+
232
+ # Extend the object with the service type
233
+ #self.info "extending with %s" % type
234
+ self.extend(type)
235
+
236
+ super
237
+
238
+ unless @parameters.include?(:pattern)
239
+ # default to using the service name as the pattern
240
+ self[:pattern] = self.name
241
+ end
242
+
243
+ # and then see if it needs to be checked
244
+ if self.respond_to?(:configchk)
245
+ self.configchk
246
+ end
247
+ end
248
+
249
+ # Retrieve the service type.
250
+ def type2module(type)
251
+ case type
252
+ when "smf":
253
+ return Puppet::ServiceTypes::SMFSvc
254
+ when "init":
255
+ return Puppet::ServiceTypes::InitSvc
256
+ when "launchd":
257
+ #return Puppet::ServiceTypes::LaunchDSvc
258
+ else
259
+ raise Puppet::Error, "Invalid service type %s" % type
260
+ end
261
+ end
262
+
263
+ # Basically just a synonym for restarting. Used to respond
264
+ # to events.
265
+ def refresh
266
+ self.restart
267
+ end
268
+
269
+ # How to restart the process.
270
+ def restart
271
+ if self[:restart] or self.respond_to?(:restartcmd)
272
+ cmd = self[:restart] || self.restartcmd
273
+ self.execute("restart", cmd)
274
+ else
275
+ self.stop
276
+ self.start
277
+ end
278
+ end
279
+
280
+ # Check if the process is running. Prefer the 'status' parameter,
281
+ # then 'statuscmd' method, then look in the process table. We give
282
+ # the object the option to not return a status command, which might
283
+ # happen if, for instance, it has an init script (and thus responds to
284
+ # 'statuscmd') but does not have 'hasstatus' enabled.
285
+ def status
286
+ if self[:status] or (
287
+ self.respond_to?(:statuscmd) and self.statuscmd
288
+ )
289
+ cmd = self[:status] || self.statuscmd
290
+ output = %x(#{cmd} 2>&1)
291
+ self.debug "%s status returned %s" %
292
+ [self.name, output]
293
+ if $? == 0
294
+ return :running
295
+ else
296
+ return :stopped
297
+ end
298
+ elsif pid = self.getpid
299
+ return :running
300
+ else
301
+ return :stopped
302
+ end
303
+ end
304
+
305
+ # Run the 'start' parameter command, or the specified 'startcmd'.
306
+ def start
307
+ cmd = self[:start] || self.startcmd
308
+ self.execute("start", cmd)
309
+ end
310
+
311
+ # Stop the service. If a 'stop' parameter is specified, it
312
+ # takes precedence; otherwise checks if the object responds to
313
+ # a 'stopcmd' method, and if so runs that; otherwise, looks
314
+ # for the process in the process table.
315
+ # This method will generally not be overridden by submodules.
316
+ def stop
317
+ if self[:stop]
318
+ return self[:stop]
319
+ elsif self.respond_to?(:stopcmd)
320
+ self.execute("stop", self.stopcmd)
321
+ else
322
+ pid = getpid
323
+ unless pid
324
+ self.info "%s is not running" % self.name
325
+ return false
326
+ end
327
+ output = %x("kill #{pid} 2>&1")
328
+ if $? != 0
329
+ raise Puppet::Error,
330
+ "Could not kill %s, PID %s: %s" %
331
+ [self.name, pid, output]
332
+ end
333
+ return true
334
+ end
335
+ end
336
+ end
337
+ end
338
+ end
339
+
340
+ # Load all of the different service types. We could probably get away with
341
+ # loading less here, but it's not a big deal to do so.
342
+ require 'puppet/type/service/base'
343
+ require 'puppet/type/service/init'
344
+ require 'puppet/type/service/debian'
345
+ require 'puppet/type/service/smf'
346
+
347
+ # $Id: service.rb 742 2005-11-16 17:12:11Z luke $