| 3 |
3 |
Puppet::Type.type(:service).provide :gentoo, :parent => :init do
|
| 4 |
4 |
desc "Gentoo's form of ``init``-style service management.
|
| 5 |
5 |
|
| 6 |
|
Uses ``rc-update`` for service enabling and disabling.
|
|
6 |
Managing /etc/runlevels/default directly for enabling and disabling.
|
| 7 |
7 |
|
| 8 |
|
"
|
| 9 |
|
|
| 10 |
|
commands :update => "/sbin/rc-update"
|
|
8 |
"
|
| 11 |
9 |
|
| 12 |
10 |
confine :operatingsystem => :gentoo
|
| 13 |
11 |
|
| 14 |
12 |
defaultfor :operatingsystem => :gentoo
|
| 15 |
13 |
|
|
14 |
@@levels = []
|
|
15 |
|
|
16 |
begin
|
|
17 |
Dir.open("/etc/runlevels").each do |entry|
|
|
18 |
@@levels.push entry if File.directory?("/etc/runlevels/#{entry}") and entry =~ /^[^.]/
|
|
19 |
end
|
|
20 |
rescue
|
|
21 |
raise Puppet::Error, "Could not get service names"
|
|
22 |
end
|
|
23 |
|
| 16 |
24 |
def self.defpath
|
| 17 |
25 |
superclass.defpath
|
| 18 |
26 |
end
|
| 19 |
27 |
|
| 20 |
28 |
def disable
|
| 21 |
|
begin
|
| 22 |
|
output = update :del, @resource[:name], :default
|
| 23 |
|
rescue Puppet::ExecutionFailure
|
| 24 |
|
raise Puppet::Error, "Could not disable %s: %s" %
|
| 25 |
|
[self.name, output]
|
|
29 |
@@levels.each do |l|
|
|
30 |
service = "/etc/runlevels/#{l}/#{@resource[:name]}"
|
|
31 |
|
|
32 |
if File.exist?(service)
|
|
33 |
begin
|
|
34 |
File.delete(service)
|
|
35 |
rescue
|
|
36 |
raise Puppet::Error, "Could not disable %s" % self.name
|
|
37 |
end
|
|
38 |
end
|
| 26 |
39 |
end
|
| 27 |
40 |
end
|
| 28 |
41 |
|
| 29 |
42 |
def enabled?
|
| 30 |
|
begin
|
| 31 |
|
output = update :show
|
| 32 |
|
rescue Puppet::ExecutionFailure
|
| 33 |
|
return :false
|
| 34 |
|
end
|
| 35 |
|
|
| 36 |
|
line = output.split(/\n/).find { |l| l.include?(@resource[:name]) }
|
|
43 |
result = :false
|
| 37 |
44 |
|
| 38 |
|
return :false unless line
|
|
45 |
@@levels.each do |l|
|
|
46 |
service = "/etc/runlevels/#{l}/#{@resource[:name]}"
|
| 39 |
47 |
|
| 40 |
|
# If it's enabled then it will print output showing service | runlevel
|
| 41 |
|
if output =~ /#{@resource[:name]}\s*\|\s*(boot|default)/
|
| 42 |
|
return :true
|
| 43 |
|
else
|
| 44 |
|
return :false
|
|
48 |
if File.exist?(service)
|
|
49 |
result = :true
|
|
50 |
end
|
| 45 |
51 |
end
|
|
52 |
|
|
53 |
return result
|
| 46 |
54 |
end
|
| 47 |
55 |
|
| 48 |
56 |
def enable
|
| 49 |
|
begin
|
| 50 |
|
output = update :add, @resource[:name], :default
|
| 51 |
|
rescue Puppet::ExecutionFailure
|
| 52 |
|
raise Puppet::Error, "Could not enable %s: %s" %
|
| 53 |
|
[self.name, output]
|
|
57 |
service = "/etc/runlevels/default/#{@resource[:name]}"
|
|
58 |
|
|
59 |
unless File.exist?(service)
|
|
60 |
begin
|
|
61 |
File.symlink("/etc/init.d/#{@resource[:name]}", service)
|
|
62 |
rescue
|
|
63 |
raise Puppet::Error, "Could not enable %s: %s" %
|
|
64 |
[self.name]
|
|
65 |
end
|
| 54 |
66 |
end
|
| 55 |
67 |
end
|
| 56 |
68 |
end
|
| 57 |
|
-
|