chef 0.10.0.beta.6 → 0.10.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/application.rb +3 -0
- data/lib/chef/application/client.rb +34 -2
- data/lib/chef/checksum.rb +2 -2
- data/lib/chef/checksum_cache.rb +2 -2
- data/lib/chef/client.rb +7 -5
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/environment.rb +31 -9
- data/lib/chef/file_access_control.rb +7 -3
- data/lib/chef/index_queue/indexable.rb +2 -2
- data/lib/chef/knife.rb +1 -1
- data/lib/chef/knife/bootstrap.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +2 -2
- data/lib/chef/knife/cookbook_upload.rb +32 -11
- data/lib/chef/knife/core/subcommand_loader.rb +24 -13
- data/lib/chef/knife/core/text_formatter.rb +2 -2
- data/lib/chef/knife/core/ui.rb +1 -1
- data/lib/chef/knife/search.rb +1 -1
- data/lib/chef/knife/ssh.rb +1 -0
- data/lib/chef/mixin/shell_out.rb +2 -2
- data/lib/chef/node.rb +7 -4
- data/lib/chef/provider/cookbook_file.rb +4 -5
- data/lib/chef/provider/cron.rb +3 -3
- data/lib/chef/provider/cron/solaris.rb +7 -7
- data/lib/chef/provider/deploy.rb +52 -29
- data/lib/chef/provider/directory.rb +8 -8
- data/lib/chef/provider/env.rb +8 -8
- data/lib/chef/provider/erl_call.rb +7 -6
- data/lib/chef/provider/execute.rb +7 -2
- data/lib/chef/provider/file.rb +9 -9
- data/lib/chef/provider/git.rb +17 -8
- data/lib/chef/provider/group.rb +6 -6
- data/lib/chef/provider/group/aix.rb +1 -1
- data/lib/chef/provider/group/dscl.rb +2 -2
- data/lib/chef/provider/group/gpasswd.rb +3 -3
- data/lib/chef/provider/group/groupadd.rb +1 -1
- data/lib/chef/provider/group/pw.rb +3 -3
- data/lib/chef/provider/group/usermod.rb +2 -2
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +9 -7
- data/lib/chef/provider/link.rb +27 -24
- data/lib/chef/provider/mdadm.rb +10 -10
- data/lib/chef/provider/mount.rb +10 -13
- data/lib/chef/provider/mount/mount.rb +10 -10
- data/lib/chef/provider/mount/windows.rb +4 -3
- data/lib/chef/provider/ohai.rb +2 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +18 -18
- data/lib/chef/provider/package/dpkg.rb +3 -3
- data/lib/chef/provider/package/easy_install.rb +2 -2
- data/lib/chef/provider/package/freebsd.rb +4 -5
- data/lib/chef/provider/package/macports.rb +2 -2
- data/lib/chef/provider/package/pacman.rb +2 -2
- data/lib/chef/provider/package/portage.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +3 -3
- data/lib/chef/provider/package/rubygems.rb +7 -7
- data/lib/chef/provider/package/solaris.rb +9 -9
- data/lib/chef/provider/package/yum.rb +4 -4
- data/lib/chef/provider/package/zypper.rb +5 -11
- data/lib/chef/provider/remote_directory.rb +15 -14
- data/lib/chef/provider/remote_file.rb +11 -12
- data/lib/chef/provider/route.rb +8 -10
- data/lib/chef/provider/ruby_block.rb +1 -0
- data/lib/chef/provider/service.rb +10 -16
- data/lib/chef/provider/service/debian.rb +1 -1
- data/lib/chef/provider/service/freebsd.rb +16 -18
- data/lib/chef/provider/service/gentoo.rb +2 -3
- data/lib/chef/provider/service/simple.rb +7 -5
- data/lib/chef/provider/service/upstart.rb +8 -8
- data/lib/chef/provider/service/windows.rb +3 -3
- data/lib/chef/provider/subversion.rb +12 -9
- data/lib/chef/provider/template.rb +2 -3
- data/lib/chef/provider/user.rb +13 -14
- data/lib/chef/provider/user/dscl.rb +2 -2
- data/lib/chef/provider/user/pw.rb +4 -4
- data/lib/chef/provider/user/useradd.rb +3 -3
- data/lib/chef/provider/user/windows.rb +3 -3
- data/lib/chef/resource.rb +4 -3
- data/lib/chef/resource/deploy.rb +1 -1
- data/lib/chef/rest/rest_request.rb +2 -2
- data/lib/chef/run_context.rb +1 -1
- data/lib/chef/shell_out.rb +13 -1
- data/lib/chef/solr_query.rb +1 -1
- data/lib/chef/solr_query/solr_http_request.rb +1 -1
- data/lib/chef/tasks/chef_repo.rake +74 -0
- data/lib/chef/version.rb +1 -1
- metadata +2 -2
@@ -126,7 +126,7 @@ class Chef
|
|
126
126
|
|
127
127
|
# Expect [ { :version => "ver", :release => "rel" }, { :version => "ver", :release => "rel" }, { :version => "ver", :release => "rel" } ] ???
|
128
128
|
matching_versions.each do |ver|
|
129
|
-
Chef::Log.debug("#{
|
129
|
+
Chef::Log.debug("#{@new_resource} trying to match #{desired_version} to version #{ver[:version]} and release #{ver[:release]}")
|
130
130
|
if (desired_version == "#{ver[:version]}-#{ver[:release]}")
|
131
131
|
return true
|
132
132
|
end
|
@@ -176,7 +176,7 @@ class Chef
|
|
176
176
|
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
|
177
177
|
end
|
178
178
|
|
179
|
-
Chef::Log.debug("
|
179
|
+
Chef::Log.debug("#{@new_resource} checking rpm status")
|
180
180
|
status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
|
181
181
|
stdout.each do |line|
|
182
182
|
case line
|
@@ -188,7 +188,7 @@ class Chef
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
Chef::Log.debug("
|
191
|
+
Chef::Log.debug("#{@new_resource} checking yum info for #{@new_resource.package_name}#{yum_arch}")
|
192
192
|
|
193
193
|
@yum.refresh
|
194
194
|
|
@@ -201,7 +201,7 @@ class Chef
|
|
201
201
|
else
|
202
202
|
@candidate_version = installed_version
|
203
203
|
end
|
204
|
-
Chef::Log.debug("#{@
|
204
|
+
Chef::Log.debug("#{@new_resource} installed version: #{installed_version} candidate version: #{candidate_version}")
|
205
205
|
|
206
206
|
@current_resource
|
207
207
|
end
|
@@ -35,24 +35,24 @@ class Chef
|
|
35
35
|
is_out_of_date=false
|
36
36
|
version=''
|
37
37
|
oud_version=''
|
38
|
-
Chef::Log.debug("
|
38
|
+
Chef::Log.debug("#{@new_resource} checking zypper")
|
39
39
|
status = popen4("zypper info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
|
40
40
|
stdout.each do |line|
|
41
41
|
case line
|
42
42
|
when /^Version: (.+)$/
|
43
43
|
version = $1
|
44
|
-
Chef::Log.debug("
|
44
|
+
Chef::Log.debug("#{@new_resource} version #{$1}")
|
45
45
|
when /^Installed: Yes$/
|
46
46
|
is_installed=true
|
47
|
-
Chef::Log.debug("
|
47
|
+
Chef::Log.debug("#{@new_resource} is installed")
|
48
48
|
|
49
49
|
when /^Installed: No$/
|
50
50
|
is_installed=false
|
51
|
-
Chef::Log.debug("
|
51
|
+
Chef::Log.debug("#{@new_resource} is not installed")
|
52
52
|
when /^Status: out-of-date \(version (.+) installed\)$/
|
53
53
|
is_out_of_date=true
|
54
54
|
oud_version=$1
|
55
|
-
Chef::Log.debug("
|
55
|
+
Chef::Log.debug("#{@new_resource} out of date version #{$1}")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -60,28 +60,22 @@ class Chef
|
|
60
60
|
if is_installed==false
|
61
61
|
@candidate_version=version
|
62
62
|
@current_resource.version(nil)
|
63
|
-
Chef::Log.debug("dentro installed false");
|
64
63
|
end
|
65
64
|
|
66
65
|
if is_installed==true
|
67
66
|
if is_out_of_date==true
|
68
67
|
@current_resource.version(oud_version)
|
69
68
|
@candidate_version=version
|
70
|
-
Chef::Log.debug("dentro installed outofdate");
|
71
69
|
else
|
72
70
|
@current_resource.version(version)
|
73
71
|
@candidate_version=version
|
74
|
-
Chef::Log.debug("dentro installed");
|
75
72
|
end
|
76
73
|
end
|
77
74
|
|
78
|
-
|
79
75
|
unless status.exitstatus == 0
|
80
76
|
raise Chef::Exceptions::Package, "zypper failed - #{status.inspect}!"
|
81
77
|
end
|
82
|
-
|
83
78
|
|
84
|
-
Chef::Log.debug("zypper current resource #{@current_resource}")
|
85
79
|
@current_resource
|
86
80
|
end
|
87
81
|
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -32,8 +32,7 @@ class Chef
|
|
32
32
|
|
33
33
|
def action_create
|
34
34
|
super
|
35
|
-
|
36
|
-
|
35
|
+
|
37
36
|
files_to_purge = Set.new(
|
38
37
|
Dir.glob(::File.join(@new_resource.path, '**', '*'), ::File::FNM_DOTMATCH).select do |name|
|
39
38
|
name !~ /(?:^|#{Regexp.escape(::File::SEPARATOR)})\.\.?$/
|
@@ -45,6 +44,8 @@ class Chef
|
|
45
44
|
files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
|
46
45
|
end
|
47
46
|
purge_unmanaged_files(files_to_purge)
|
47
|
+
Chef::Log.info("#{@new_resource} created")
|
48
|
+
@new_resource.updated_by_last_action(true)
|
48
49
|
end
|
49
50
|
|
50
51
|
def action_create_if_missing
|
@@ -59,11 +60,11 @@ class Chef
|
|
59
60
|
if @new_resource.purge
|
60
61
|
unmanaged_files.sort.reverse.each do |f|
|
61
62
|
if ::File.directory?(f)
|
62
|
-
Chef::Log.debug("Removing directory #{f}")
|
63
63
|
Dir::rmdir(f)
|
64
|
+
Chef::Log.debug("#{@new_resource} removed directory #{f}")
|
64
65
|
else
|
65
|
-
Chef::Log.debug("Deleting file #{f}")
|
66
66
|
::File.delete(f)
|
67
|
+
Chef::Log.debug("#{@new_resource} deleted file #{f}")
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end
|
@@ -74,15 +75,15 @@ class Chef
|
|
74
75
|
files = cookbook.relative_filenames_in_preferred_directory(node, :files, @new_resource.source)
|
75
76
|
files.sort.reverse
|
76
77
|
end
|
77
|
-
|
78
|
+
|
78
79
|
def directory_root_in_cookbook_cache
|
79
80
|
@directory_root_in_cookbook_cache ||= begin
|
80
81
|
cookbook = run_context.cookbook_collection[resource_cookbook]
|
81
82
|
cookbook.preferred_filename_on_disk_location(node, :files, @new_resource.source, @new_resource.path)
|
82
83
|
end
|
83
84
|
end
|
84
|
-
|
85
|
-
# Determine the cookbook to get the file from. If new resource sets an
|
85
|
+
|
86
|
+
# Determine the cookbook to get the file from. If new resource sets an
|
86
87
|
# explicit cookbook, use it, otherwise fall back to the implicit cookbook
|
87
88
|
# i.e., the cookbook the resource was declared in.
|
88
89
|
def resource_cookbook
|
@@ -91,9 +92,9 @@ class Chef
|
|
91
92
|
|
92
93
|
def create_cookbook_file(cookbook_file_relative_path)
|
93
94
|
full_path = ::File.join(@new_resource.path, cookbook_file_relative_path)
|
94
|
-
|
95
|
+
|
95
96
|
ensure_directory_exists(::File.dirname(full_path))
|
96
|
-
|
97
|
+
|
97
98
|
file_to_fetch = cookbook_file_resource(full_path, cookbook_file_relative_path)
|
98
99
|
if @new_resource.overwrite
|
99
100
|
file_to_fetch.run_action(:create)
|
@@ -102,7 +103,7 @@ class Chef
|
|
102
103
|
end
|
103
104
|
@new_resource.updated_by_last_action(true) if file_to_fetch.updated?
|
104
105
|
end
|
105
|
-
|
106
|
+
|
106
107
|
def cookbook_file_resource(target_path, relative_source_path)
|
107
108
|
cookbook_file = Chef::Resource::CookbookFile.new(target_path, run_context)
|
108
109
|
cookbook_file.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
|
@@ -111,10 +112,10 @@ class Chef
|
|
111
112
|
cookbook_file.group(@new_resource.files_group) if @new_resource.files_group
|
112
113
|
cookbook_file.owner(@new_resource.files_owner) if @new_resource.files_owner
|
113
114
|
cookbook_file.backup(@new_resource.files_backup) if @new_resource.files_backup
|
114
|
-
|
115
|
+
|
115
116
|
cookbook_file
|
116
117
|
end
|
117
|
-
|
118
|
+
|
118
119
|
def ensure_directory_exists(path)
|
119
120
|
unless ::File.directory?(path)
|
120
121
|
directory_to_create = resource_for_directory(path)
|
@@ -34,18 +34,18 @@ class Chef
|
|
34
34
|
def action_create
|
35
35
|
assert_enclosing_directory_exists!
|
36
36
|
|
37
|
-
Chef::Log.debug("
|
37
|
+
Chef::Log.debug("#{@new_resource} checking for changes")
|
38
38
|
|
39
39
|
if current_resource_matches_target_checksum?
|
40
|
-
Chef::Log.debug("
|
40
|
+
Chef::Log.debug("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating")
|
41
41
|
else
|
42
42
|
Chef::REST.new(@new_resource.source, nil, nil).fetch(@new_resource.source) do |raw_file|
|
43
43
|
if matches_current_checksum?(raw_file)
|
44
|
-
Chef::Log.debug "#{@new_resource}
|
44
|
+
Chef::Log.debug "#{@new_resource} target and source checksums are the same - not updating"
|
45
45
|
else
|
46
46
|
backup_new_resource
|
47
|
-
Chef::Log.debug "copying remote file from origin #{raw_file.path} to destination #{@new_resource.path}"
|
48
47
|
FileUtils.cp raw_file.path, @new_resource.path
|
48
|
+
Chef::Log.info "#{@new_resource} updated"
|
49
49
|
@new_resource.updated_by_last_action(true)
|
50
50
|
end
|
51
51
|
end
|
@@ -57,7 +57,7 @@ class Chef
|
|
57
57
|
|
58
58
|
def action_create_if_missing
|
59
59
|
if ::File.exists?(@new_resource.path)
|
60
|
-
Chef::Log.debug("
|
60
|
+
Chef::Log.debug("#{@new_resource} exists, taking no action.")
|
61
61
|
else
|
62
62
|
action_create
|
63
63
|
end
|
@@ -74,24 +74,23 @@ class Chef
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def matches_current_checksum?(candidate_file)
|
77
|
-
Chef::Log.debug "#{@new_resource}
|
77
|
+
Chef::Log.debug "#{@new_resource} checking for file existence of #{@new_resource.path}"
|
78
78
|
if ::File.exists?(@new_resource.path)
|
79
|
-
Chef::Log.debug "#{@new_resource}
|
79
|
+
Chef::Log.debug "#{@new_resource} file exists at #{@new_resource.path}"
|
80
80
|
@new_resource.checksum(checksum(candidate_file.path))
|
81
|
-
Chef::Log.debug "#{@new_resource}
|
82
|
-
Chef::Log.debug "#{@new_resource}
|
81
|
+
Chef::Log.debug "#{@new_resource} target checksum: #{@current_resource.checksum}"
|
82
|
+
Chef::Log.debug "#{@new_resource} source checksum: #{@new_resource.checksum}"
|
83
83
|
|
84
84
|
@new_resource.checksum == @current_resource.checksum
|
85
85
|
else
|
86
|
-
Chef::Log.
|
86
|
+
Chef::Log.debug "#{@new_resource} creating #{@new_resource.path}"
|
87
87
|
false
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
def backup_new_resource
|
92
92
|
if ::File.exists?(@new_resource.path)
|
93
|
-
Chef::Log.debug "#{@new_resource}
|
94
|
-
Chef::Log.info "#{@new_resource}: Updating #{@new_resource.path}"
|
93
|
+
Chef::Log.debug "#{@new_resource} checksum changed from #{@current_resource.checksum} to #{@new_resource.checksum}"
|
95
94
|
backup @new_resource.path
|
96
95
|
end
|
97
96
|
end
|
data/lib/chef/provider/route.rb
CHANGED
@@ -63,8 +63,6 @@ class Chef::Provider::Route < Chef::Provider
|
|
63
63
|
def load_current_resource
|
64
64
|
is_running = nil
|
65
65
|
|
66
|
-
Chef::Log.debug("Configuring Route #{@new_resource.name}")
|
67
|
-
|
68
66
|
# cidr or quad dot mask
|
69
67
|
if @new_resource.netmask
|
70
68
|
new_ip = IPAddr.new("#{@new_resource.target}/#{@new_resource.netmask}")
|
@@ -86,7 +84,7 @@ class Chef::Provider::Route < Chef::Provider
|
|
86
84
|
destination = IPAddr.new(destination.scan(/../).reverse.to_s.hex, Socket::AF_INET).to_s
|
87
85
|
gateway = IPAddr.new(gateway.scan(/../).reverse.to_s.hex, Socket::AF_INET).to_s
|
88
86
|
mask = IPAddr.new(mask.scan(/../).reverse.to_s.hex, Socket::AF_INET).to_s
|
89
|
-
Chef::Log.debug(
|
87
|
+
Chef::Log.debug("#{@new_resource} system has route: dest=#{destination} mask=#{mask} gw=#{gateway}")
|
90
88
|
|
91
89
|
# check if what were trying to configure is already there
|
92
90
|
# use an ipaddr object with ip/mask this way we can have
|
@@ -94,7 +92,7 @@ class Chef::Provider::Route < Chef::Provider
|
|
94
92
|
# expanding bitmask by hand.
|
95
93
|
#
|
96
94
|
running_ip = IPAddr.new("#{destination}/#{mask}")
|
97
|
-
Chef::Log.debug(
|
95
|
+
Chef::Log.debug("#{@new_resource} new ip: #{new_ip.inspect} running ip: #{running_ip.inspect}")
|
98
96
|
is_running = true if running_ip == new_ip
|
99
97
|
end
|
100
98
|
route_file.close
|
@@ -103,13 +101,13 @@ class Chef::Provider::Route < Chef::Provider
|
|
103
101
|
|
104
102
|
def action_add
|
105
103
|
# check to see if load_current_resource found the route
|
106
|
-
if
|
107
|
-
Chef::Log.debug("
|
104
|
+
if is_running
|
105
|
+
Chef::Log.debug("#{@new_resource} route already active - nothing to do")
|
108
106
|
else
|
109
107
|
command = generate_command(:add)
|
110
108
|
|
111
|
-
Chef::Log.info("Adding route: #{command} ")
|
112
109
|
run_command( :command => command )
|
110
|
+
Chef::Log.info("#{@new_resource} added")
|
113
111
|
@new_resource.updated_by_last_action(true)
|
114
112
|
end
|
115
113
|
|
@@ -121,11 +119,11 @@ class Chef::Provider::Route < Chef::Provider
|
|
121
119
|
if is_running
|
122
120
|
command = generate_command(:delete)
|
123
121
|
|
124
|
-
Chef::Log.info("Removing route: #{command}")
|
125
122
|
run_command( :command => command )
|
123
|
+
Chef::Log.info("#{@new_resource} removed")
|
126
124
|
@new_resource.updated_by_last_action(true)
|
127
125
|
else
|
128
|
-
Chef::Log.debug("
|
126
|
+
Chef::Log.debug("#{@new_resource} route does not exist - nothing to do")
|
129
127
|
end
|
130
128
|
end
|
131
129
|
|
@@ -156,7 +154,7 @@ class Chef::Provider::Route < Chef::Provider
|
|
156
154
|
conf.each do |k, v|
|
157
155
|
network_file = ::File.new("/etc/sysconfig/network-scripts/route-#{k}", "w")
|
158
156
|
network_file.puts(conf[k])
|
159
|
-
Chef::Log.debug("writing route.#{k}\n#{conf[k]}")
|
157
|
+
Chef::Log.debug("#{@new_resource} writing route.#{k}\n#{conf[k]}")
|
160
158
|
network_file.close
|
161
159
|
end
|
162
160
|
end
|
@@ -32,57 +32,52 @@ class Chef
|
|
32
32
|
|
33
33
|
def action_enable
|
34
34
|
if @current_resource.enabled
|
35
|
-
Chef::Log.debug("#{@new_resource}
|
35
|
+
Chef::Log.debug("#{@new_resource} already enabled - nothing to do")
|
36
36
|
else
|
37
|
-
Chef::Log.debug("#{@new_resource}: attempting to enable")
|
38
37
|
if enable_service
|
39
38
|
@new_resource.updated_by_last_action(true)
|
40
|
-
Chef::Log.info("#{@new_resource}
|
39
|
+
Chef::Log.info("#{@new_resource} enabled")
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
44
|
def action_disable
|
46
45
|
if @current_resource.enabled
|
47
|
-
Chef::Log.debug("#{@new_resource}: attempting to disable")
|
48
46
|
if disable_service
|
49
47
|
@new_resource.updated_by_last_action(true)
|
50
|
-
Chef::Log.info("#{@new_resource}
|
48
|
+
Chef::Log.info("#{@new_resource} disabled")
|
51
49
|
end
|
52
50
|
else
|
53
|
-
Chef::Log.debug("#{@new_resource}
|
51
|
+
Chef::Log.debug("#{@new_resource} already disabled - nothing to do")
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
def action_start
|
58
56
|
unless @current_resource.running
|
59
|
-
Chef::Log.debug("#{@new_resource}: attempting to start")
|
60
57
|
if start_service
|
61
58
|
@new_resource.updated_by_last_action(true)
|
62
|
-
Chef::Log.info("
|
59
|
+
Chef::Log.info("#{@new_resource} started")
|
63
60
|
end
|
64
61
|
else
|
65
|
-
Chef::Log.debug("#{@new_resource}
|
62
|
+
Chef::Log.debug("#{@new_resource} already running - nothing to do")
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
66
|
def action_stop
|
70
67
|
if @current_resource.running
|
71
|
-
Chef::Log.debug("#{@new_resource}: attempting to stop")
|
72
68
|
if stop_service
|
73
69
|
@new_resource.updated_by_last_action(true)
|
74
|
-
Chef::Log.info("#{@new_resource}
|
70
|
+
Chef::Log.info("#{@new_resource} stopped")
|
75
71
|
end
|
76
72
|
else
|
77
|
-
Chef::Log.debug("#{@new_resource}
|
73
|
+
Chef::Log.debug("#{@new_resource} already stopped - nothing to do")
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
81
77
|
def action_restart
|
82
|
-
Chef::Log.debug("#{@new_resource}: attempting to restart")
|
83
78
|
if restart_service
|
84
79
|
@new_resource.updated_by_last_action(true)
|
85
|
-
Chef::Log.info("#{@new_resource}
|
80
|
+
Chef::Log.info("#{@new_resource} restarted")
|
86
81
|
end
|
87
82
|
end
|
88
83
|
|
@@ -91,10 +86,9 @@ class Chef
|
|
91
86
|
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
|
92
87
|
end
|
93
88
|
if @current_resource.running
|
94
|
-
Chef::Log.debug("#{@new_resource}: attempting to reload")
|
95
89
|
if reload_service
|
96
90
|
@new_resource.updated_by_last_action(true)
|
97
|
-
Chef::Log.info("#{@new_resource}
|
91
|
+
Chef::Log.info("#{@new_resource} reloaded")
|
98
92
|
end
|
99
93
|
end
|
100
94
|
end
|
@@ -72,7 +72,7 @@ class Chef
|
|
72
72
|
enabled = false
|
73
73
|
|
74
74
|
priority.each { |runlevel, arguments|
|
75
|
-
Chef::Log.debug("
|
75
|
+
Chef::Log.debug("#{@new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}")
|
76
76
|
|
77
77
|
# if we are in a update-rc.d default startup runlevel && we start in this runlevel
|
78
78
|
if (2..5).include?(runlevel.to_i) && arguments[0] == :start
|
@@ -30,20 +30,19 @@ class Chef
|
|
30
30
|
|
31
31
|
# Determine if we're talking about /etc/rc.d or /usr/local/etc/rc.d
|
32
32
|
if ::File.exists?("/etc/rc.d/#{current_resource.service_name}")
|
33
|
-
@init_command = "/etc/rc.d/#{current_resource.service_name}"
|
33
|
+
@init_command = "/etc/rc.d/#{current_resource.service_name}"
|
34
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}"
|
35
|
+
@init_command = "/usr/local/etc/rc.d/#{current_resource.service_name}"
|
36
36
|
else
|
37
37
|
raise Chef::Exceptions::Service, "#{@new_resource}: unable to locate the rc.d script"
|
38
38
|
end
|
39
|
-
Chef::Log.debug("#{@current_resource
|
40
|
-
|
41
|
-
if @new_resource.supports[:status]
|
42
|
-
Chef::Log.debug("#{@new_resource} supports status, checking state")
|
39
|
+
Chef::Log.debug("#{@current_resource} found at #{@init_command}")
|
43
40
|
|
41
|
+
if @new_resource.supports[:status]
|
44
42
|
begin
|
45
43
|
if run_command(:command => "#{@init_command} status") == 0
|
46
44
|
@current_resource.running true
|
45
|
+
Chef::Log.debug("#{@new_resource} is running")
|
47
46
|
end
|
48
47
|
rescue Chef::Exceptions::Exec
|
49
48
|
@current_resource.running false
|
@@ -51,11 +50,10 @@ class Chef
|
|
51
50
|
end
|
52
51
|
|
53
52
|
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
53
|
begin
|
57
54
|
if run_command(:command => @new_resource.status_command) == 0
|
58
55
|
@current_resource.running true
|
56
|
+
Chef::Log.debug("#{@new_resource} is running")
|
59
57
|
end
|
60
58
|
rescue Chef::Exceptions::Exec
|
61
59
|
@current_resource.running false
|
@@ -66,12 +64,12 @@ class Chef
|
|
66
64
|
Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
|
67
65
|
|
68
66
|
if node[:command][:ps].nil? or node[:command][:ps].empty?
|
69
|
-
raise Chef::Exceptions::Service, "#{@new_resource}
|
67
|
+
raise Chef::Exceptions::Service, "#{@new_resource} could not determine how to inspect the process table, please set this nodes 'ps' attribute"
|
70
68
|
end
|
71
69
|
|
72
70
|
status = popen4(node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
73
71
|
r = Regexp.new(@new_resource.pattern)
|
74
|
-
Chef::Log.debug("#{@new_resource}
|
72
|
+
Chef::Log.debug("#{@new_resource} attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
75
73
|
stdout.each_line do |line|
|
76
74
|
if r.match(line)
|
77
75
|
@current_resource.running true
|
@@ -83,7 +81,7 @@ class Chef
|
|
83
81
|
unless status.exitstatus == 0
|
84
82
|
raise Chef::Exceptions::Service, "Command #{node[:command][:ps]} failed"
|
85
83
|
else
|
86
|
-
Chef::Log.debug("#{@new_resource}
|
84
|
+
Chef::Log.debug("#{@new_resource} #{node[:command][:ps]} exited and parsed successfully, process running: #{@current_resource.running}")
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -102,21 +100,21 @@ class Chef
|
|
102
100
|
unless @current_resource.enabled
|
103
101
|
Chef::Log.debug("#{@new_resource.name} enable/disable state unknown")
|
104
102
|
end
|
105
|
-
|
103
|
+
|
106
104
|
@current_resource
|
107
105
|
end
|
108
106
|
|
109
107
|
def read_rc_conf
|
110
108
|
::File.open("/etc/rc.conf", 'r') { |file| file.readlines }
|
111
109
|
end
|
112
|
-
|
110
|
+
|
113
111
|
def write_rc_conf(lines)
|
114
112
|
::File.open("/etc/rc.conf", 'w') do |file|
|
115
113
|
lines.each { |line| file.puts(line) }
|
116
114
|
end
|
117
115
|
end
|
118
|
-
|
119
|
-
|
116
|
+
|
117
|
+
|
120
118
|
# The variable name used in /etc/rc.conf for enabling this service
|
121
119
|
def service_enable_variable_name
|
122
120
|
# Look for name="foo" in the shell script @init_command. Use this for determining the variable name in /etc/rc.conf
|
@@ -132,7 +130,7 @@ class Chef
|
|
132
130
|
end
|
133
131
|
raise Chef::Exceptions::Service, "Could not find name=\"service\" line in #{@init_command}"
|
134
132
|
end
|
135
|
-
|
133
|
+
|
136
134
|
def set_service_enable(value)
|
137
135
|
lines = read_rc_conf
|
138
136
|
# Remove line that set the old value
|
@@ -141,7 +139,7 @@ class Chef
|
|
141
139
|
lines << "#{service_enable_variable_name}=\"#{value}\""
|
142
140
|
write_rc_conf(lines)
|
143
141
|
end
|
144
|
-
|
142
|
+
|
145
143
|
def enable_service()
|
146
144
|
set_service_enable("YES") unless @current_resource.enabled
|
147
145
|
end
|
@@ -149,7 +147,7 @@ class Chef
|
|
149
147
|
def disable_service()
|
150
148
|
set_service_enable("NO") if @current_resource.enabled
|
151
149
|
end
|
152
|
-
|
150
|
+
|
153
151
|
end
|
154
152
|
end
|
155
153
|
end
|