chef 0.8.16 → 0.9.0.a3

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.

Files changed (185) hide show
  1. data/bin/shef +1 -0
  2. data/distro/common/man/man1/chef-server-webui.1 +106 -0
  3. data/distro/common/man/man1/chef-server.1 +0 -1
  4. data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
  5. data/distro/common/man/man1/chef-solr.1 +55 -0
  6. data/distro/common/man/man8/chef-client.8 +4 -2
  7. data/distro/common/man/man8/chef-solo.8 +1 -2
  8. data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
  9. data/distro/common/man/man8/knife.8 +668 -266
  10. data/distro/common/man/man8/shef.8 +45 -0
  11. data/distro/common/markdown/README +3 -0
  12. data/distro/common/markdown/knife.mkd +520 -0
  13. data/distro/debian/etc/default/chef-client +4 -0
  14. data/distro/debian/etc/default/chef-server +6 -0
  15. data/distro/debian/etc/default/chef-server-webui +6 -0
  16. data/distro/debian/etc/default/chef-solr +4 -0
  17. data/distro/debian/etc/default/chef-solr-indexer +4 -0
  18. data/distro/debian/etc/init.d/chef-client +41 -41
  19. data/distro/debian/etc/init.d/chef-server +10 -10
  20. data/distro/debian/etc/init.d/chef-server-webui +121 -0
  21. data/distro/debian/etc/init.d/chef-solr +177 -0
  22. data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
  23. data/distro/redhat/etc/init.d/chef-client +76 -48
  24. data/distro/redhat/etc/init.d/chef-server +85 -51
  25. data/distro/redhat/etc/init.d/chef-server-webui +85 -51
  26. data/distro/redhat/etc/init.d/chef-solr +77 -49
  27. data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
  28. data/distro/redhat/etc/logrotate.d/chef-client +8 -0
  29. data/distro/redhat/etc/logrotate.d/chef-server +8 -0
  30. data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
  31. data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
  32. data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
  33. data/distro/redhat/etc/sysconfig/chef-client +9 -4
  34. data/distro/redhat/etc/sysconfig/chef-server +10 -6
  35. data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
  36. data/distro/redhat/etc/sysconfig/chef-solr +3 -4
  37. data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
  38. data/lib/chef.rb +16 -5
  39. data/lib/chef/application/knife.rb +2 -2
  40. data/lib/chef/application/solo.rb +1 -7
  41. data/lib/chef/cache/checksum.rb +12 -5
  42. data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
  43. data/lib/chef/checksum.rb +115 -0
  44. data/lib/chef/client.rb +193 -185
  45. data/lib/chef/config.rb +9 -1
  46. data/lib/chef/cookbook/cookbook_collection.rb +43 -0
  47. data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
  48. data/lib/chef/cookbook/file_vendor.rb +47 -0
  49. data/lib/chef/cookbook/metadata.rb +34 -35
  50. data/lib/chef/cookbook/metadata/version.rb +1 -1
  51. data/lib/chef/cookbook_loader.rb +70 -45
  52. data/lib/chef/cookbook_version.rb +760 -0
  53. data/lib/chef/couchdb.rb +8 -5
  54. data/lib/chef/data_bag_item.rb +5 -5
  55. data/lib/chef/exceptions.rb +10 -0
  56. data/lib/chef/file_access_control.rb +134 -0
  57. data/lib/chef/handler.rb +62 -0
  58. data/lib/chef/handler/json_file.rb +47 -0
  59. data/lib/chef/knife.rb +14 -2
  60. data/lib/chef/knife/bootstrap.rb +126 -0
  61. data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
  62. data/lib/chef/knife/cookbook_delete.rb +4 -4
  63. data/lib/chef/knife/cookbook_download.rb +57 -26
  64. data/lib/chef/knife/cookbook_metadata.rb +2 -2
  65. data/lib/chef/knife/cookbook_show.rb +30 -11
  66. data/lib/chef/knife/cookbook_upload.rb +113 -86
  67. data/lib/chef/knife/ec2_server_create.rb +146 -0
  68. data/lib/chef/knife/ec2_server_delete.rb +84 -0
  69. data/lib/chef/knife/ec2_server_list.rb +82 -0
  70. data/lib/chef/knife/status.rb +51 -0
  71. data/lib/chef/mixin/language_include_attribute.rb +16 -11
  72. data/lib/chef/mixin/language_include_recipe.rb +15 -16
  73. data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
  74. data/lib/chef/mixin/shell_out.rb +38 -0
  75. data/lib/chef/mixins.rb +1 -1
  76. data/lib/chef/node.rb +190 -63
  77. data/lib/chef/node/attribute.rb +92 -78
  78. data/lib/chef/platform.rb +24 -4
  79. data/lib/chef/provider.rb +28 -10
  80. data/lib/chef/provider/breakpoint.rb +2 -2
  81. data/lib/chef/provider/cookbook_file.rb +96 -0
  82. data/lib/chef/provider/cron.rb +2 -2
  83. data/lib/chef/provider/deploy.rb +12 -10
  84. data/lib/chef/provider/env.rb +152 -0
  85. data/lib/chef/provider/env/windows.rb +75 -0
  86. data/lib/chef/provider/file.rb +10 -14
  87. data/lib/chef/provider/group.rb +15 -2
  88. data/lib/chef/provider/group/dscl.rb +17 -25
  89. data/lib/chef/provider/group/gpasswd.rb +6 -3
  90. data/lib/chef/provider/group/pw.rb +3 -7
  91. data/lib/chef/provider/group/windows.rb +79 -0
  92. data/lib/chef/provider/link.rb +4 -5
  93. data/lib/chef/provider/mdadm.rb +25 -18
  94. data/lib/chef/provider/mount/mount.rb +28 -27
  95. data/lib/chef/provider/package.rb +35 -35
  96. data/lib/chef/provider/package/dpkg.rb +13 -10
  97. data/lib/chef/provider/package/easy_install.rb +6 -6
  98. data/lib/chef/provider/package/freebsd.rb +17 -51
  99. data/lib/chef/provider/package/rpm.rb +1 -1
  100. data/lib/chef/provider/package/rubygems.rb +391 -74
  101. data/lib/chef/provider/package/yum.rb +2 -2
  102. data/lib/chef/provider/package/zypper.rb +2 -1
  103. data/lib/chef/provider/remote_directory.rb +60 -83
  104. data/lib/chef/provider/remote_file.rb +17 -66
  105. data/lib/chef/provider/script.rb +20 -9
  106. data/lib/chef/provider/service.rb +23 -30
  107. data/lib/chef/provider/service/arch.rb +3 -3
  108. data/lib/chef/provider/service/debian.rb +22 -17
  109. data/lib/chef/provider/service/freebsd.rb +4 -4
  110. data/lib/chef/provider/service/init.rb +2 -2
  111. data/lib/chef/provider/service/redhat.rb +14 -16
  112. data/lib/chef/provider/service/simple.rb +7 -3
  113. data/lib/chef/provider/service/solaris.rb +85 -0
  114. data/lib/chef/provider/service/upstart.rb +12 -7
  115. data/lib/chef/provider/service/windows.rb +2 -2
  116. data/lib/chef/provider/template.rb +133 -118
  117. data/lib/chef/provider/user.rb +34 -17
  118. data/lib/chef/provider/user/dscl.rb +117 -114
  119. data/lib/chef/provider/user/windows.rb +124 -0
  120. data/lib/chef/providers.rb +7 -0
  121. data/lib/chef/recipe.rb +39 -20
  122. data/lib/chef/resource.rb +47 -52
  123. data/lib/chef/resource/apt_package.rb +4 -4
  124. data/lib/chef/resource/bash.rb +4 -4
  125. data/lib/chef/resource/cookbook_file.rb +45 -0
  126. data/lib/chef/resource/cron.rb +3 -3
  127. data/lib/chef/resource/csh.rb +4 -4
  128. data/lib/chef/resource/deploy.rb +3 -3
  129. data/lib/chef/resource/directory.rb +4 -4
  130. data/lib/chef/resource/dpkg_package.rb +4 -4
  131. data/lib/chef/resource/easy_install_package.rb +3 -3
  132. data/lib/chef/resource/env.rb +58 -0
  133. data/lib/chef/resource/erl_call.rb +3 -3
  134. data/lib/chef/resource/execute.rb +3 -3
  135. data/lib/chef/resource/file.rb +3 -3
  136. data/lib/chef/resource/freebsd_package.rb +3 -3
  137. data/lib/chef/resource/gem_package.rb +17 -9
  138. data/lib/chef/resource/git.rb +3 -3
  139. data/lib/chef/resource/group.rb +3 -3
  140. data/lib/chef/resource/http_request.rb +4 -4
  141. data/lib/chef/resource/ifconfig.rb +3 -3
  142. data/lib/chef/resource/link.rb +3 -3
  143. data/lib/chef/resource/log.rb +2 -2
  144. data/lib/chef/resource/macports_package.rb +2 -2
  145. data/lib/chef/resource/mdadm.rb +3 -3
  146. data/lib/chef/resource/mount.rb +2 -2
  147. data/lib/chef/resource/package.rb +4 -4
  148. data/lib/chef/resource/pacman_package.rb +4 -4
  149. data/lib/chef/resource/perl.rb +4 -4
  150. data/lib/chef/resource/portage_package.rb +4 -4
  151. data/lib/chef/resource/python.rb +4 -4
  152. data/lib/chef/resource/remote_directory.rb +3 -3
  153. data/lib/chef/resource/remote_file.rb +26 -3
  154. data/lib/chef/resource/route.rb +3 -3
  155. data/lib/chef/resource/ruby.rb +3 -3
  156. data/lib/chef/resource/ruby_block.rb +3 -2
  157. data/lib/chef/resource/scm.rb +7 -5
  158. data/lib/chef/resource/script.rb +4 -4
  159. data/lib/chef/resource/service.rb +3 -3
  160. data/lib/chef/resource/subversion.rb +4 -2
  161. data/lib/chef/resource/template.rb +3 -3
  162. data/lib/chef/resource/user.rb +3 -3
  163. data/lib/chef/resource/yum_package.rb +3 -3
  164. data/lib/chef/resource_collection.rb +9 -5
  165. data/lib/chef/resources.rb +2 -0
  166. data/lib/chef/rest.rb +4 -0
  167. data/lib/chef/role.rb +2 -0
  168. data/lib/chef/run_context.rb +108 -0
  169. data/lib/chef/run_list.rb +75 -98
  170. data/lib/chef/run_list/run_list_expansion.rb +156 -0
  171. data/lib/chef/run_list/run_list_item.rb +71 -0
  172. data/lib/chef/runner.rb +58 -61
  173. data/lib/chef/sandbox.rb +147 -0
  174. data/lib/chef/shef.rb +4 -3
  175. data/lib/chef/shef/ext.rb +12 -4
  176. data/lib/chef/shef/shef_session.rb +27 -23
  177. data/lib/chef/shell_out.rb +375 -0
  178. data/lib/chef/util/windows.rb +56 -0
  179. data/lib/chef/util/windows/net_group.rb +101 -0
  180. data/lib/chef/util/windows/net_user.rb +198 -0
  181. data/lib/chef/version.rb +20 -0
  182. metadata +112 -22
  183. data/lib/chef/compile.rb +0 -158
  184. data/lib/chef/cookbook.rb +0 -201
  185. data/lib/chef/mixin/generate_url.rb +0 -58
@@ -106,9 +106,9 @@ class Chef
106
106
  end
107
107
  end
108
108
 
109
- def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
109
+ def initialize(new_resource, run_context)
110
110
  @yum = YumCache.instance
111
- super(node, new_resource, collection, definitions, cookbook_loader)
111
+ super
112
112
  end
113
113
 
114
114
  def load_current_resource
@@ -32,8 +32,9 @@ class Chef
32
32
  @current_resource.package_name(@new_resource.package_name)
33
33
 
34
34
  is_installed=false
35
- version=''
36
35
  is_out_of_date=false
36
+ version=''
37
+ oud_version=''
37
38
  Chef::Log.debug("Checking zypper for #{@new_resource.package_name}")
38
39
  status = popen4("zypper info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
39
40
  stdout.each do |line|
@@ -18,8 +18,8 @@
18
18
 
19
19
  require 'chef/provider/file'
20
20
  require 'chef/provider/directory'
21
- require 'chef/rest'
22
- require 'chef/mixin/find_preferred_file'
21
+ #require 'chef/rest'
22
+ #require 'chef/mixin/find_preferred_file'
23
23
  require 'chef/resource/directory'
24
24
  require 'chef/resource/remote_file'
25
25
  require 'chef/platform'
@@ -32,30 +32,29 @@ class Chef
32
32
  class Provider
33
33
  class RemoteDirectory < Chef::Provider::Directory
34
34
 
35
- include ::Chef::Mixin::FindPreferredFile
36
-
37
35
  def action_create
38
36
  super
39
- do_recursive
40
- end
41
-
42
- protected
43
-
44
- def do_recursive
45
- if Chef::Config[:solo]
46
- Chef::Log.debug("Doing a local recursive directory copy for #{@new_resource}")
47
- else
48
- Chef::Log.debug("Doing a remote recursive directory transfer for #{@new_resource}")
49
- end
37
+ Chef::Log.debug("Doing a remote recursive directory transfer for #{@new_resource}")
50
38
 
51
- existing_files = Set.new Dir[::File.join(@new_resource.path, '**', '*')]
39
+ files_to_purge = Set.new Dir[::File.join(@new_resource.path, '**', '*')]
52
40
 
53
- files_to_transfer.each do |remote_file_source|
54
- fetch_remote_file(remote_file_source)
55
- existing_files.delete(::File.join(@new_resource.path, remote_file_source))
41
+ files_to_transfer.each do |cookbook_file_relative_path|
42
+ create_cookbook_file(cookbook_file_relative_path)
43
+ files_to_purge.delete(::File.dirname(::File.join(@new_resource.path, cookbook_file_relative_path)))
44
+ files_to_purge.delete(::File.join(@new_resource.path, cookbook_file_relative_path))
56
45
  end
46
+ purge_unmanaged_files(files_to_purge)
47
+ end
48
+
49
+ def action_create_if_missing
50
+ raise Chef::Exceptions::UnsupportedAction, "Remote Directories do not support create_if_missing."
51
+ end
52
+
53
+ protected
54
+
55
+ def purge_unmanaged_files(unmanaged_files)
57
56
  if @new_resource.purge
58
- existing_files.sort { |a,b| b <=> a }.each do |f|
57
+ unmanaged_files.sort.reverse.each do |f|
59
58
  if ::File.directory?(f)
60
59
  Chef::Log.debug("Removing directory #{f}")
61
60
  Dir::rmdir(f)
@@ -66,89 +65,67 @@ class Chef
66
65
  end
67
66
  end
68
67
  end
69
-
68
+
70
69
  def files_to_transfer
71
- file_list = Chef::Config[:solo] ? generate_solo_file_list : generate_client_file_list
72
- Chef::Log.debug("Generated file manifest for #{@new_resource}:\n#{file_list.join("\n")}")
73
- file_list
70
+ cookbook = run_context.cookbook_collection[resource_cookbook]
71
+ files = cookbook.relative_filenames_in_preferred_directory(node, :files, @new_resource.source)
72
+ files.sort.reverse
74
73
  end
75
74
 
76
- def generate_solo_file_list
77
- # Pulled from chef-server-slice files controller
78
- directory = find_preferred_file(
79
- @new_resource.cookbook_name,
80
- :remote_file,
81
- @new_resource.source,
82
- @node[:fqdn],
83
- @node[:platform],
84
- @node[:platform_version]
85
- )
86
-
87
- unless (directory && ::File.directory?(directory))
88
- raise NotFound, "Cannot find a suitable directory"
75
+ def directory_root_in_cookbook_cache
76
+ @directory_root_in_cookbook_cache ||= begin
77
+ cookbook = run_context.cookbook_collection[resource_cookbook]
78
+ cookbook.preferred_filename_on_disk_location(node, :files, @new_resource.source, @new_resource.path)
89
79
  end
90
-
91
- file_list = Array.new
92
- Dir[::File.join(directory, '**', '*')].sort.reverse.select do |file|
93
- unless ::File.directory?(file)
94
- file_list << file[/^#{directory}\/(.+)$/, 1]
95
- end
96
- end
97
- file_list
98
80
  end
99
81
 
100
- def generate_client_file_list
101
- r = Chef::REST.new(Chef::Config[:remotefile_url])
102
- r.get_rest(generate_url(@new_resource.source, "files", { :recursive => "true" }))
82
+ # Determine the cookbook to get the file from. If new resource sets an
83
+ # explicit cookbook, use it, otherwise fall back to the implicit cookbook
84
+ # i.e., the cookbook the resource was declared in.
85
+ def resource_cookbook
86
+ @new_resource.cookbook || @new_resource.cookbook_name
103
87
  end
104
-
105
- def fetch_remote_file(remote_file_source)
106
- full_path = ::File.join(@new_resource.path, remote_file_source)
88
+
89
+ def create_cookbook_file(cookbook_file_relative_path)
90
+ full_path = ::File.join(@new_resource.path, cookbook_file_relative_path)
107
91
 
108
92
  ensure_directory_exists(::File.dirname(full_path))
109
93
 
110
- file_to_fetch = provider_for_remote_file(full_path, remote_file_source)
111
- file_to_fetch.load_current_resource
112
- file_to_fetch.action_create
113
- @new_resource.updated = true if file_to_fetch.new_resource.updated
94
+ file_to_fetch = cookbook_file_resource(full_path, cookbook_file_relative_path)
95
+ file_to_fetch.run_action(:create)
96
+ @new_resource.updated = true if file_to_fetch.updated?
114
97
  end
115
98
 
116
- def provider_for_remote_file(path, source)
117
- remote_file = Chef::Resource::RemoteFile.new(path, nil, @node)
118
- remote_file.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
119
- remote_file.source(::File.join(@new_resource.source, source))
120
- remote_file.mode(@new_resource.files_mode) if @new_resource.files_mode
121
- remote_file.group(@new_resource.files_group) if @new_resource.files_group
122
- remote_file.owner(@new_resource.files_owner) if @new_resource.files_owner
123
- remote_file.backup(@new_resource.files_backup) if @new_resource.files_backup
99
+ def cookbook_file_resource(target_path, relative_source_path)
100
+ cookbook_file = Chef::Resource::CookbookFile.new(target_path, run_context)
101
+ cookbook_file.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
102
+ cookbook_file.source(::File.join(@new_resource.source, relative_source_path))
103
+ cookbook_file.mode(@new_resource.files_mode) if @new_resource.files_mode
104
+ cookbook_file.group(@new_resource.files_group) if @new_resource.files_group
105
+ cookbook_file.owner(@new_resource.files_owner) if @new_resource.files_owner
106
+ cookbook_file.backup(@new_resource.files_backup) if @new_resource.files_backup
124
107
 
125
- Chef::Platform.provider_for_node(@node, remote_file)
108
+ cookbook_file
126
109
  end
127
110
 
128
111
  def ensure_directory_exists(path)
129
112
  unless ::File.directory?(path)
130
- directory_to_create = provider_for_directory(path)
131
- directory_to_create.load_current_resource
132
- directory_to_create.action_create
133
- @new_resource.updated = true if directory_to_create.new_resource.updated
113
+ directory_to_create = resource_for_directory(path)
114
+ directory_to_create.run_action(:create)
115
+ @new_resource.updated = true if directory_to_create.updated?
134
116
  end
135
117
  end
136
-
137
- def provider_for_directory(path)
138
- new_dir = Chef::Resource::Directory.new(path, nil, @node)
139
- new_dir.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
140
- new_dir.mode(@new_resource.mode)
141
- new_dir.group(@new_resource.group)
142
- new_dir.owner(@new_resource.owner)
143
- new_dir.recursive(true)
144
-
145
- Chef::Platform.provider_for_node(@node, new_dir)
146
- end
147
-
148
- def action_create_if_missing
149
- raise Chef::Exceptions::UnsupportedAction, "Remote Directories do not support create_if_missing."
118
+
119
+ def resource_for_directory(path)
120
+ dir = Chef::Resource::Directory.new(path, run_context)
121
+ dir.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
122
+ dir.mode(@new_resource.mode)
123
+ dir.group(@new_resource.group)
124
+ dir.owner(@new_resource.owner)
125
+ dir.recursive(true)
126
+ dir
150
127
  end
151
128
 
152
129
  end
153
130
  end
154
- end
131
+ end
@@ -31,56 +31,38 @@ class Chef
31
31
 
32
32
  def action_create
33
33
  Chef::Log.debug("Checking #{@new_resource} for changes")
34
- do_remote_file(@new_resource.source, @current_resource.path)
35
- end
36
-
37
- def action_create_if_missing
38
- if ::File.exists?(@new_resource.path)
39
- Chef::Log.debug("File #{@new_resource.path} exists, taking no action.")
40
- else
41
- action_create
42
- end
43
- end
44
-
45
- def do_remote_file(source, path)
46
- retval = true
47
34
 
48
35
  if current_resource_matches_target_checksum?
49
36
  Chef::Log.debug("File #{@new_resource} checksum matches target checksum (#{@new_resource.checksum}), not updating")
50
37
  else
51
- begin
52
- source_file(source, @current_resource.checksum) do |raw_file|
53
- if matches_current_checksum?(raw_file)
54
- Chef::Log.debug "#{@new_resource}: Target and Source checksums are the same, taking no action"
55
- else
56
- backup_new_resource
57
- Chef::Log.debug "copying remote file from origin #{raw_file.path} to destination #{@new_resource.path}"
58
- FileUtils.cp raw_file.path, @new_resource.path
59
- @new_resource.updated = true
60
- end
61
- end
62
- rescue Net::HTTPRetriableError => e
63
- if e.response.kind_of?(Net::HTTPNotModified)
64
- Chef::Log.debug("File #{path} is unchanged")
65
- retval = false
38
+ Chef::REST.new(@new_resource.source, nil, nil).fetch(@new_resource.source) do |raw_file|
39
+ if matches_current_checksum?(raw_file)
40
+ Chef::Log.debug "#{@new_resource}: Target and Source checksums are the same, taking no action"
66
41
  else
67
- raise e
42
+ backup_new_resource
43
+ Chef::Log.debug "copying remote file from origin #{raw_file.path} to destination #{@new_resource.path}"
44
+ FileUtils.cp raw_file.path, @new_resource.path
45
+ @new_resource.updated = true
68
46
  end
69
47
  end
70
-
71
- Chef::Log.debug "#{@new_resource} completed"
72
- retval
73
48
  end
74
49
  enforce_ownership_and_permissions
75
50
 
76
- retval
51
+ @new_resource.updated
52
+ end
53
+
54
+ def action_create_if_missing
55
+ if ::File.exists?(@new_resource.path)
56
+ Chef::Log.debug("File #{@new_resource.path} exists, taking no action.")
57
+ else
58
+ action_create
59
+ end
77
60
  end
78
61
 
79
62
  def enforce_ownership_and_permissions
80
63
  set_owner if @new_resource.owner
81
64
  set_group if @new_resource.group
82
65
  set_mode if @new_resource.mode
83
-
84
66
  end
85
67
 
86
68
  def current_resource_matches_target_checksum?
@@ -94,6 +76,7 @@ class Chef
94
76
  @new_resource.checksum(checksum(candidate_file.path))
95
77
  Chef::Log.debug "#{@new_resource}: Target checksum: #{@current_resource.checksum}"
96
78
  Chef::Log.debug "#{@new_resource}: Source checksum: #{@new_resource.checksum}"
79
+
97
80
  @new_resource.checksum == @current_resource.checksum
98
81
  else
99
82
  Chef::Log.info "#{@new_resource}: Creating #{@new_resource.path}"
@@ -127,38 +110,6 @@ class Chef
127
110
  false
128
111
  end
129
112
 
130
- def fetch_from_uri(source)
131
- Chef::Log.debug("Downloading from absolute URI: #{source}")
132
- Chef::REST.new(source, nil, nil).fetch(source) { |tmp_file| yield tmp_file }
133
- end
134
-
135
- def fetch_from_chef_server(source, current_checksum)
136
- url = generate_url(source, "files", :checksum => current_checksum)
137
- Chef::Log.debug("Downloading #{@new_resource} from server: #{url}")
138
- Chef::REST.new(Chef::Config[:remotefile_url]).fetch(url) { |tmp_file| yield tmp_file }
139
- end
140
-
141
- def fetch_from_local_cookbook(source)
142
- if Chef::Config[:solo]
143
- cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
144
- filename = find_preferred_file(
145
- cookbook_name,
146
- :remote_file,
147
- source,
148
- @node[:fqdn],
149
- @node[:platform],
150
- @node[:platform_version]
151
- )
152
- Chef::Log.debug("Using local file for remote_file:#{filename}")
153
- begin
154
- file = ::File.open(filename)
155
- yield file
156
- ensure
157
- file.close
158
- end
159
- end
160
- end
161
-
162
113
  end
163
114
  end
164
115
  end
@@ -24,19 +24,30 @@ class Chef
24
24
  class Script < Chef::Provider::Execute
25
25
 
26
26
  def action_run
27
- tf = Tempfile.new("chef-script")
28
- tf.puts(@new_resource.code)
29
- tf.close
27
+ script_file.puts(@new_resource.code)
28
+ script_file.close
30
29
 
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)
30
+ set_owner_and_group
35
31
 
36
- @new_resource.command("#{@new_resource.interpreter} #{tf.path}")
32
+ @new_resource.command("#{@new_resource.interpreter} #{script_file.path}")
37
33
  super
38
34
  ensure
39
- tf && tf.close!
35
+ unlink_script_file
36
+ end
37
+
38
+ def set_owner_and_group
39
+ # FileUtils itself implements a no-op if +user+ or +group+ are nil
40
+ # You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
41
+ # as an unprivileged user.
42
+ FileUtils.chown(@new_resource.user, @new_resource.group, script_file.path)
43
+ end
44
+
45
+ def script_file
46
+ @script_file ||= Tempfile.open("chef-script")
47
+ end
48
+
49
+ def unlink_script_file
50
+ @script_file && @script_file.close!
40
51
  end
41
52
 
42
53
  end
@@ -25,29 +25,27 @@ class Chef
25
25
 
26
26
  include Chef::Mixin::Command
27
27
 
28
- def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
29
- super(node, new_resource, collection, definitions, cookbook_loader)
28
+ def initialize(new_resource, run_context)
29
+ super
30
30
  @enabled = nil
31
31
  end
32
32
 
33
33
  def action_enable
34
- unless @current_resource.enabled
34
+ if @current_resource.enabled
35
+ Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
36
+ else
35
37
  Chef::Log.debug("#{@new_resource}: attempting to enable")
36
- status = enable_service()
37
- if status
38
+ if enable_service
38
39
  @new_resource.updated = true
39
40
  Chef::Log.info("#{@new_resource}: enabled successfully")
40
41
  end
41
- else
42
- Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
43
42
  end
44
43
  end
45
44
 
46
45
  def action_disable
47
46
  if @current_resource.enabled
48
47
  Chef::Log.debug("#{@new_resource}: attempting to disable")
49
- status = disable_service()
50
- if status
48
+ if disable_service
51
49
  @new_resource.updated = true
52
50
  Chef::Log.info("#{@new_resource}: disabled successfully")
53
51
  end
@@ -59,8 +57,7 @@ class Chef
59
57
  def action_start
60
58
  unless @current_resource.running
61
59
  Chef::Log.debug("#{@new_resource}: attempting to start")
62
- status = start_service()
63
- if status
60
+ if start_service
64
61
  @new_resource.updated = true
65
62
  Chef::Log.info("Started service #{@new_resource} successfully")
66
63
  end
@@ -72,8 +69,7 @@ class Chef
72
69
  def action_stop
73
70
  if @current_resource.running
74
71
  Chef::Log.debug("#{@new_resource}: attempting to stop")
75
- status = stop_service()
76
- if status
72
+ if stop_service
77
73
  @new_resource.updated = true
78
74
  Chef::Log.info("#{@new_resource}: stopped successfully")
79
75
  end
@@ -84,49 +80,46 @@ class Chef
84
80
 
85
81
  def action_restart
86
82
  Chef::Log.debug("#{@new_resource}: attempting to restart")
87
- status = restart_service()
88
- if status
83
+ if restart_service
89
84
  @new_resource.updated = true
90
85
  Chef::Log.info("#{@new_resource}: restarted successfully")
91
86
  end
92
87
  end
93
88
 
94
89
  def action_reload
95
- unless @new_resource.supports[:reload] or @new_resource.reload_command
90
+ unless (@new_resource.supports[:reload] || @new_resource.reload_command)
96
91
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
97
- else
98
- if @current_resource.running
99
- Chef::Log.debug("#{@new_resource}: attempting to reload")
100
- status = reload_service()
101
- if status
102
- @new_resource.updated = true
103
- Chef::Log.info("#{@new_resource}: reloaded successfully")
104
- end
92
+ end
93
+ if @current_resource.running
94
+ Chef::Log.debug("#{@new_resource}: attempting to reload")
95
+ if reload_service
96
+ @new_resource.updated = true
97
+ Chef::Log.info("#{@new_resource}: reloaded successfully")
105
98
  end
106
99
  end
107
100
  end
108
101
 
109
- def enable_service(name)
102
+ def enable_service
110
103
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
111
104
  end
112
105
 
113
- def disable_service(name)
106
+ def disable_service
114
107
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
115
108
  end
116
109
 
117
- def start_service(name)
110
+ def start_service
118
111
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
119
112
  end
120
113
 
121
- def stop_service(name)
114
+ def stop_service
122
115
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
123
116
  end
124
117
 
125
- def restart_service(name)
118
+ def restart_service
126
119
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
127
120
  end
128
121
 
129
- def reload_service(name)
122
+ def reload_service
130
123
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
131
124
  end
132
125