chef 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +351 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +121 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +113 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +134 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +129 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/group.rb +68 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +123 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'tempfile'
|
20
|
+
require 'chef/provider/execute'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Script < Chef::Provider::Execute
|
25
|
+
|
26
|
+
def action_run
|
27
|
+
tf = Tempfile.new("chef-script")
|
28
|
+
tf.puts(@new_resource.code)
|
29
|
+
tf.close
|
30
|
+
|
31
|
+
fr = Chef::Resource::File.new(tf.path, nil, @node)
|
32
|
+
fr.owner(@new_resource.user)
|
33
|
+
fr.group(@new_resource.group)
|
34
|
+
fr.run_action(:create)
|
35
|
+
|
36
|
+
@new_resource.command("#{@new_resource.interpreter} #{tf.path}")
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/mixin/command'
|
20
|
+
require 'chef/provider'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service < Chef::Provider
|
25
|
+
|
26
|
+
include Chef::Mixin::Command
|
27
|
+
|
28
|
+
def initialize(node, new_resource)
|
29
|
+
super(node, new_resource)
|
30
|
+
@enabled = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def action_enable
|
34
|
+
unless @current_resource.enabled
|
35
|
+
Chef::Log.debug("#{@new_resource}: attempting to enable")
|
36
|
+
status = enable_service()
|
37
|
+
if status
|
38
|
+
Chef::Log.info("#{@new_resource}: enabled successfully")
|
39
|
+
end
|
40
|
+
else
|
41
|
+
Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def action_disable
|
46
|
+
if @current_resource.enabled
|
47
|
+
Chef::Log.debug("#{@new_resource}: attempting to disable")
|
48
|
+
status = disable_service()
|
49
|
+
if status
|
50
|
+
Chef::Log.info("#{@new_resource}: disabled successfully")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def action_start
|
58
|
+
unless @current_resource.running
|
59
|
+
Chef::Log.debug("#{@new_resource}: attempting to start")
|
60
|
+
status = start_service()
|
61
|
+
if status
|
62
|
+
Chef::Log.info("Started service #{@new_resource} successfully")
|
63
|
+
end
|
64
|
+
else
|
65
|
+
Chef::Log.debug("#{@new_resource}: not starting, already running")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def action_stop
|
70
|
+
if @current_resource.running
|
71
|
+
Chef::Log.debug("#{@new_resource}: attempting to stop")
|
72
|
+
status = stop_service()
|
73
|
+
if status
|
74
|
+
Chef::Log.info("#{@new_resource}: stopped successfully")
|
75
|
+
end
|
76
|
+
else
|
77
|
+
Chef::Log.debug("#{@new_resource}: not stopping, already stopped")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def action_restart
|
82
|
+
Chef::Log.debug("#{@new_resource}: attempting to restart")
|
83
|
+
status = restart_service()
|
84
|
+
if status
|
85
|
+
Chef::Log.info("#{@new_resource}: restarted successfully")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def action_reload
|
90
|
+
unless @new_resource.supports[:reload] or @new_resource.reload_command
|
91
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
|
92
|
+
else
|
93
|
+
if @current_resource.running
|
94
|
+
Chef::Log.debug("#{@new_resource}: attempting to reload")
|
95
|
+
status = reload_service()
|
96
|
+
if status
|
97
|
+
Chef::Log.info("#{@new_resource}: reloaded successfully")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def enable_service(name)
|
104
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
|
105
|
+
end
|
106
|
+
|
107
|
+
def disable_service(name)
|
108
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
|
109
|
+
end
|
110
|
+
|
111
|
+
def start_service(name)
|
112
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
|
113
|
+
end
|
114
|
+
|
115
|
+
def stop_service(name)
|
116
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
|
117
|
+
end
|
118
|
+
|
119
|
+
def restart_service(name)
|
120
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
|
121
|
+
end
|
122
|
+
|
123
|
+
def reload_service(name)
|
124
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/service'
|
20
|
+
require 'chef/provider/service/init'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Service
|
26
|
+
class Debian < Chef::Provider::Service::Init
|
27
|
+
def load_current_resource
|
28
|
+
super
|
29
|
+
|
30
|
+
unless ::File.exists? "/usr/sbin/update-rc.d"
|
31
|
+
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d does not exist!"
|
32
|
+
end
|
33
|
+
|
34
|
+
status = popen4("/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
|
35
|
+
r = /etc\/rc[\dS].d\/S|not installed/i
|
36
|
+
stdout.each_line do |line|
|
37
|
+
if r.match(line)
|
38
|
+
@current_resource.enabled true
|
39
|
+
break
|
40
|
+
else
|
41
|
+
@current_resource.enabled false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
unless status.exitstatus == 0
|
47
|
+
raise Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
@current_resource
|
51
|
+
end
|
52
|
+
|
53
|
+
def enable_service()
|
54
|
+
run_command(:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
|
55
|
+
end
|
56
|
+
|
57
|
+
def disable_service()
|
58
|
+
run_command(:command => "/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/service'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service
|
25
|
+
class Freebsd < Chef::Provider::Service::Init
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
29
|
+
@current_resource.service_name(@new_resource.service_name)
|
30
|
+
|
31
|
+
# Determine if we're talking about /etc/rc.d or /usr/local/etc/rc.d
|
32
|
+
if ::File.exists?("/etc/rc.d/#{current_resource.service_name}")
|
33
|
+
@init_command = "/etc/rc.d/#{current_resource.service_name}"
|
34
|
+
elsif ::File.exists?("/usr/local/etc/rc.d/#{current_resource.service_name}")
|
35
|
+
@init_command = "/usr/local/etc/rc.d/#{current_resource.service_name}"
|
36
|
+
else
|
37
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: unable to locate the rc.d script"
|
38
|
+
end
|
39
|
+
Chef::Log.debug("#{@current_resource.name} found at #{@init_command}")
|
40
|
+
|
41
|
+
if @new_resource.supports[:status]
|
42
|
+
Chef::Log.debug("#{@new_resource} supports status, checking state")
|
43
|
+
|
44
|
+
begin
|
45
|
+
if run_command(:command => "#{@init_command} status") == 0
|
46
|
+
@current_resource.running true
|
47
|
+
end
|
48
|
+
rescue Chef::Exceptions::Exec
|
49
|
+
@current_resource.running false
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif @new_resource.status_command
|
54
|
+
Chef::Log.debug("#{@new_resource} doesn't support status but you have specified a status command, running..")
|
55
|
+
|
56
|
+
begin
|
57
|
+
if run_command(:command => @new_resource.status_command) == 0
|
58
|
+
@current_resource.running true
|
59
|
+
end
|
60
|
+
rescue Chef::Exceptions::Exec
|
61
|
+
@current_resource.running false
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
else
|
66
|
+
Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
|
67
|
+
|
68
|
+
if @node[:command][:ps].nil? or @node[:command][:ps].empty?
|
69
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'ps' attribute"
|
70
|
+
end
|
71
|
+
|
72
|
+
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
73
|
+
stdin.close
|
74
|
+
r = Regexp.new(@new_resource.pattern)
|
75
|
+
Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
76
|
+
stdout.each_line do |line|
|
77
|
+
if r.match(line)
|
78
|
+
@current_resource.running true
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
@current_resource.running false unless @current_resource.running
|
83
|
+
end
|
84
|
+
unless status.exitstatus == 0
|
85
|
+
raise Chef::Exceptions::Service, "Command #{@node[:command][:ps]} failed"
|
86
|
+
else
|
87
|
+
Chef::Log.debug("#{@new_resource}: #{@node[:command][:ps]} exited and parsed successfully, process running: #{@current_resource.running}")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if ::File.exists?("/etc/rc.conf")
|
92
|
+
read_rc_conf.each do |line|
|
93
|
+
case line
|
94
|
+
when /#{service_enable_variable_name}="(\w+)"/
|
95
|
+
if $1 =~ /[Yy][Ee][Ss]/
|
96
|
+
@current_resource.enabled true
|
97
|
+
elsif $1 =~ /[Nn][Oo][Nn]?[Oo]?[Nn]?[Ee]?/
|
98
|
+
@current_resource.enabled false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
unless @current_resource.enabled
|
104
|
+
Chef::Log.debug("#{@new_resource.name} enable/disable state unknown")
|
105
|
+
end
|
106
|
+
|
107
|
+
@current_resource
|
108
|
+
end
|
109
|
+
|
110
|
+
def read_rc_conf
|
111
|
+
::File.open("/etc/rc.conf", 'r') { |file| file.readlines }
|
112
|
+
end
|
113
|
+
|
114
|
+
def write_rc_conf(lines)
|
115
|
+
::File.open("/etc/rc.conf", 'w') do |file|
|
116
|
+
lines.each { |line| file.puts(line) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# The variable name used in /etc/rc.conf for enabling this service
|
122
|
+
def service_enable_variable_name
|
123
|
+
# Look for name="foo" in the shell script @init_command. Use this for determining the variable name in /etc/rc.conf
|
124
|
+
# corresponding to this service
|
125
|
+
# For example: to enable the service mysql-server with the init command /usr/local/etc/rc.d/mysql-server, you need
|
126
|
+
# to set mysql_enable="YES" in /etc/rc.conf
|
127
|
+
makefile = ::File.open(@init_command)
|
128
|
+
makefile.each do |line|
|
129
|
+
case line
|
130
|
+
when /^name="?(\w+)"?/
|
131
|
+
return $1 + "_enable"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
raise Chef::Exceptions::Service, "Could not find name=\"service\" line in #{@init_command}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def set_service_enable(value)
|
138
|
+
lines = read_rc_conf
|
139
|
+
# Remove line that set the old value
|
140
|
+
lines.delete_if { |line| line =~ /#{service_enable_variable_name}/ }
|
141
|
+
# And append the line that sets the new value at the end
|
142
|
+
lines << "#{service_enable_variable_name}=\"#{value}\""
|
143
|
+
write_rc_conf(lines)
|
144
|
+
end
|
145
|
+
|
146
|
+
def enable_service()
|
147
|
+
set_service_enable("YES") unless @current_resource.enabled
|
148
|
+
end
|
149
|
+
|
150
|
+
def disable_service()
|
151
|
+
set_service_enable("NO") if @current_resource.enabled
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Lee Jensen (<ljensen@engineyard.com>)
|
3
|
+
# Author:: AJ Christensen (<aj@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/provider/service'
|
21
|
+
require 'chef/mixin/command'
|
22
|
+
|
23
|
+
class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
|
24
|
+
def load_current_resource
|
25
|
+
|
26
|
+
@new_resource.supports[:status] = true
|
27
|
+
@new_resource.supports[:restart] = true
|
28
|
+
|
29
|
+
super
|
30
|
+
|
31
|
+
raise Chef::Exceptions::Service unless ::File.exists?("/sbin/rc-update")
|
32
|
+
|
33
|
+
Chef::Log.debug "#{@new_resource}: checking service enable state"
|
34
|
+
@current_resource.enabled(
|
35
|
+
Dir.glob("/etc/runlevels/**/#{@current_resource.service_name}").any? do |file|
|
36
|
+
exists = ::File.exists? file
|
37
|
+
readable = ::File.readable? file
|
38
|
+
Chef::Log.debug "#{@new_resource}: exists: #{exists}, readable: #{readable}"
|
39
|
+
exists and readable
|
40
|
+
end
|
41
|
+
)
|
42
|
+
Chef::Log.debug "#{@new_resource}: enabled: #{@current_resource.enabled}"
|
43
|
+
|
44
|
+
@current_resource
|
45
|
+
end
|
46
|
+
|
47
|
+
def enable_service()
|
48
|
+
run_command(:command => "/sbin/rc-update add #{@new_resource.service_name} default")
|
49
|
+
end
|
50
|
+
|
51
|
+
def disable_service()
|
52
|
+
run_command(:command => "/sbin/rc-update del #{@new_resource.service_name} default")
|
53
|
+
end
|
54
|
+
end
|