1
# The standard init-based service type. Many other service types are
2
# customizations of this module.
3
Puppet::Type.type(:service).provide :init, :parent => :base do
4
desc "Standard init service management.
6
This provider assumes that the init script has no `status` command,
7
because so few scripts do, so you need to either provide a status
8
command or specify via `hasstatus` that one already exists in the
14
attr_accessor :defpath
17
case Facter["operatingsystem"].value
19
@defpath = ["/etc/rc.d", "/usr/local/etc/rc.d"]
21
@defpath = "/sbin/init.d"
23
@defpath = "/etc/init.d"
26
# We can't confine this here, because the init path can be overridden.
27
#confine :exists => @defpath
29
# List all services of this type.
31
get_services(self.defpath)
34
def self.get_services(defpath, exclude=[])
35
defpath = [defpath] unless defpath.is_a? Array
37
defpath.each do |path|
38
unless FileTest.directory?(path)
39
Puppet.debug "Service path #{path} does not exist"
45
check << :enable if public_method_defined? :enabled?
47
Dir.entries(path).each do |name|
48
fullpath = File.join(path, name)
50
next if exclude.include? name
51
next if not FileTest.executable?(fullpath)
52
instances << new(:name => name, :path => path, :hasstatus => true)
58
# Mark that our init script supports 'status' commands.
61
when true, "true"; @parameters[:hasstatus] = true
62
when false, "false"; @parameters[:hasstatus] = false
64
raise Puppet::Error, "Invalid 'hasstatus' value #{value.inspect}"
68
# Where is our init script?
70
@initscript ||= self.search(@resource[:name])
74
@paths ||= @resource[:path].find_all do |path|
75
if File.directory?(path)
78
if File.exist?(path) and ! File.directory?(path)
79
self.debug "Search path #{path} is not a directory"
81
self.debug "Search path #{path} does not exist"
90
fqname = File.join(path,name)
92
stat = File.stat(fqname)
94
# should probably rescue specific errors...
95
self.debug("Could not find #{name} in #{path}")
99
# if we've gotten this far, we found a valid script
104
fqname_sh = File.join(path,"#{name}.sh")
106
stat = File.stat(fqname_sh)
108
# should probably rescue specific errors...
109
self.debug("Could not find #{name}.sh in #{path}")
113
# if we've gotten this far, we found a valid script
116
raise Puppet::Error, "Could not find init script for '#{name}'"
119
# The start command is just the init scriptwith 'start'.
124
# The stop command is just the init script with 'stop'.
130
(@resource[:hasrestart] == :true) && [initscript, :restart]
133
# If it was specified that the init script has a 'status' command, then
134
# we just return that; otherwise, we return false, which causes it to
135
# fallback to other mechanisms.
137
(@resource[:hasstatus] == :true) && [initscript, :status]