chef 0.10.8 → 0.10.10.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/distro/arch/etc/rc.d/chef-client +15 -1
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +4 -4
  9. data/distro/common/html/knife-bootstrap.1.html +6 -10
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +6 -6
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +5 -5
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +5 -6
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +7 -8
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +4 -4
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +2 -2
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +3 -7
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +5 -9
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
  51. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  52. data/distro/common/markdown/man1/knife-node.mkd +2 -2
  53. data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
  54. data/distro/common/markdown/man1/knife.mkd +7 -9
  55. data/distro/debian/etc/init.d/chef-client +22 -1
  56. data/distro/redhat/etc/init.d/chef-client +12 -1
  57. data/distro/windows/service_manager.rb +164 -0
  58. data/lib/chef/application.rb +12 -6
  59. data/lib/chef/application/client.rb +4 -3
  60. data/lib/chef/application/knife.rb +7 -12
  61. data/lib/chef/application/solo.rb +2 -1
  62. data/lib/chef/application/windows_service.rb +224 -0
  63. data/lib/chef/checksum_cache.rb +1 -0
  64. data/lib/chef/client.rb +3 -16
  65. data/lib/chef/config.rb +42 -13
  66. data/lib/chef/cookbook/metadata.rb +1 -1
  67. data/lib/chef/cookbook/syntax_check.rb +2 -2
  68. data/lib/chef/cookbook_version.rb +5 -0
  69. data/lib/chef/daemon.rb +1 -1
  70. data/lib/chef/exceptions.rb +7 -1
  71. data/lib/chef/file_access_control.rb +13 -87
  72. data/lib/chef/file_access_control/unix.rb +119 -0
  73. data/lib/chef/file_access_control/windows.rb +257 -0
  74. data/lib/chef/handler/json_file.rb +7 -1
  75. data/lib/chef/knife.rb +10 -16
  76. data/lib/chef/knife/bootstrap.rb +15 -8
  77. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  78. data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
  79. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
  80. data/lib/chef/knife/configure.rb +2 -2
  81. data/lib/chef/knife/cookbook_site_download.rb +60 -21
  82. data/lib/chef/knife/cookbook_site_install.rb +16 -21
  83. data/lib/chef/knife/cookbook_upload.rb +77 -48
  84. data/lib/chef/knife/core/bootstrap_context.rb +3 -1
  85. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  86. data/lib/chef/knife/core/node_editor.rb +1 -1
  87. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  88. data/lib/chef/knife/core/ui.rb +3 -2
  89. data/lib/chef/knife/help_topics.rb +1 -1
  90. data/lib/chef/knife/node_run_list_add.rb +14 -6
  91. data/lib/chef/knife/node_run_list_remove.rb +3 -3
  92. data/lib/chef/knife/ssh.rb +32 -13
  93. data/lib/chef/mash.rb +14 -0
  94. data/lib/chef/mixin/command.rb +1 -0
  95. data/lib/chef/mixin/command/unix.rb +5 -0
  96. data/lib/chef/mixin/convert_to_class_name.rb +2 -0
  97. data/lib/chef/mixin/deep_merge.rb +40 -18
  98. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
  99. data/lib/chef/mixin/language.rb +89 -3
  100. data/lib/chef/mixin/language_include_recipe.rb +8 -4
  101. data/lib/chef/mixin/path_sanity.rb +67 -0
  102. data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
  103. data/lib/chef/mixin/securable.rb +152 -0
  104. data/lib/chef/mixin/shell_out.rb +1 -1
  105. data/lib/chef/mixin/template.rb +8 -3
  106. data/lib/chef/mixins.rb +3 -0
  107. data/lib/chef/monkey_patches/moneta.rb +50 -0
  108. data/lib/chef/monkey_patches/string.rb +1 -1
  109. data/lib/chef/node.rb +2 -1
  110. data/lib/chef/platform.rb +34 -0
  111. data/lib/chef/provider.rb +23 -21
  112. data/lib/chef/provider/cron.rb +17 -12
  113. data/lib/chef/provider/cron/solaris.rb +6 -18
  114. data/lib/chef/provider/deploy.rb +14 -15
  115. data/lib/chef/provider/deploy/timestamped.rb +0 -1
  116. data/lib/chef/provider/directory.rb +1 -3
  117. data/lib/chef/provider/execute.rb +2 -2
  118. data/lib/chef/provider/file.rb +1 -75
  119. data/lib/chef/provider/git.rb +11 -9
  120. data/lib/chef/provider/group/gpasswd.rb +14 -9
  121. data/lib/chef/provider/link.rb +28 -59
  122. data/lib/chef/provider/mdadm.rb +2 -2
  123. data/lib/chef/provider/mount/mount.rb +1 -1
  124. data/lib/chef/provider/package.rb +10 -6
  125. data/lib/chef/provider/package/apt.rb +3 -1
  126. data/lib/chef/provider/package/dpkg.rb +1 -1
  127. data/lib/chef/provider/package/portage.rb +6 -3
  128. data/lib/chef/provider/package/rubygems.rb +75 -6
  129. data/lib/chef/provider/package/smartos.rb +84 -0
  130. data/lib/chef/provider/package/yum-dump.py +3 -2
  131. data/lib/chef/provider/package/yum.rb +51 -10
  132. data/lib/chef/provider/remote_directory.rb +24 -3
  133. data/lib/chef/provider/remote_file.rb +0 -6
  134. data/lib/chef/provider/route.rb +3 -3
  135. data/lib/chef/provider/service/debian.rb +2 -2
  136. data/lib/chef/provider/service/freebsd.rb +1 -1
  137. data/lib/chef/provider/service/macosx.rb +125 -0
  138. data/lib/chef/provider/service/windows.rb +5 -1
  139. data/lib/chef/provider/subversion.rb +10 -7
  140. data/lib/chef/providers.rb +3 -0
  141. data/lib/chef/resource.rb +181 -87
  142. data/lib/chef/resource/apt_package.rb +10 -1
  143. data/lib/chef/resource/chef_gem.rb +53 -0
  144. data/lib/chef/resource/conditional.rb +3 -0
  145. data/lib/chef/resource/cookbook_file.rb +12 -6
  146. data/lib/chef/resource/cron.rb +9 -0
  147. data/lib/chef/resource/directory.rb +14 -31
  148. data/lib/chef/resource/execute.rb +11 -9
  149. data/lib/chef/resource/file.rb +9 -33
  150. data/lib/chef/resource/link.rb +13 -8
  151. data/lib/chef/resource/mdadm.rb +10 -1
  152. data/lib/chef/resource/remote_directory.rb +13 -2
  153. data/lib/chef/resource/remote_file.rb +14 -7
  154. data/lib/chef/resource/smartos_package.rb +36 -0
  155. data/lib/chef/resource/template.rb +12 -5
  156. data/lib/chef/resource_platform_map.rb +153 -0
  157. data/lib/chef/resources.rb +2 -0
  158. data/lib/chef/rest.rb +55 -10
  159. data/lib/chef/rest/auth_credentials.rb +1 -0
  160. data/lib/chef/rest/rest_request.rb +24 -8
  161. data/lib/chef/role.rb +8 -2
  162. data/lib/chef/run_list.rb +1 -1
  163. data/lib/chef/run_list/run_list_expansion.rb +2 -2
  164. data/lib/chef/run_list/run_list_item.rb +7 -0
  165. data/lib/chef/runner.rb +4 -0
  166. data/lib/chef/shef.rb +2 -2
  167. data/lib/chef/shef/shef_session.rb +4 -5
  168. data/lib/chef/shell_out.rb +2 -245
  169. data/lib/chef/util/file_edit.rb +99 -89
  170. data/lib/chef/version.rb +1 -1
  171. data/lib/chef/win32/api.rb +349 -0
  172. data/lib/chef/win32/api/error.rb +921 -0
  173. data/lib/chef/win32/api/file.rb +289 -0
  174. data/lib/chef/win32/api/memory.rb +105 -0
  175. data/lib/chef/win32/api/process.rb +40 -0
  176. data/lib/chef/win32/api/psapi.rb +51 -0
  177. data/lib/chef/win32/api/security.rb +341 -0
  178. data/lib/chef/win32/api/system.rb +192 -0
  179. data/lib/chef/win32/api/unicode.rb +178 -0
  180. data/lib/chef/win32/error.rb +73 -0
  181. data/lib/chef/win32/file.rb +117 -0
  182. data/lib/chef/win32/file/info.rb +100 -0
  183. data/lib/chef/win32/handle.rb +48 -0
  184. data/lib/chef/win32/memory.rb +101 -0
  185. data/lib/chef/win32/process.rb +84 -0
  186. data/lib/chef/win32/security.rb +489 -0
  187. data/lib/chef/win32/security/ace.rb +125 -0
  188. data/lib/chef/win32/security/acl.rb +101 -0
  189. data/lib/chef/win32/security/securable_object.rb +109 -0
  190. data/lib/chef/win32/security/security_descriptor.rb +93 -0
  191. data/lib/chef/win32/security/sid.rb +199 -0
  192. data/lib/chef/win32/security/token.rb +64 -0
  193. data/lib/chef/win32/unicode.rb +43 -0
  194. data/lib/chef/win32/version.rb +119 -0
  195. metadata +104 -158
  196. data/lib/chef/shell_out/unix.rb +0 -223
  197. data/lib/chef/shell_out/windows.rb +0 -588
@@ -23,7 +23,7 @@ class Chef
23
23
  module ShellOut
24
24
 
25
25
  def shell_out(*command_args)
26
- cmd = Chef::ShellOut.new(*command_args)
26
+ cmd = Mixlib::ShellOut.new(*command_args)
27
27
  if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.debug?
28
28
  cmd.live_stream = STDOUT
29
29
  end
@@ -71,10 +71,15 @@ class Chef
71
71
 
72
72
  def source_listing
73
73
  @source_listing ||= begin
74
- line_index = line_number - 1
75
- beginning_line = line_index <= SOURCE_CONTEXT_WINDOW ? 0 : line_index - SOURCE_CONTEXT_WINDOW
76
- source_size = SOURCE_CONTEXT_WINDOW * 2 + 1
77
74
  lines = @template.split(/\n/)
75
+ if line_number
76
+ line_index = line_number - 1
77
+ beginning_line = line_index <= SOURCE_CONTEXT_WINDOW ? 0 : line_index - SOURCE_CONTEXT_WINDOW
78
+ source_size = SOURCE_CONTEXT_WINDOW * 2 + 1
79
+ else
80
+ beginning_line = 0
81
+ source_size = lines.length
82
+ end
78
83
  contextual_lines = lines[beginning_line, source_size]
79
84
  output = []
80
85
  contextual_lines.each_with_index do |line, index|
@@ -5,11 +5,14 @@ require 'chef/mixin/command'
5
5
  require 'chef/mixin/convert_to_class_name'
6
6
  require 'chef/mixin/create_path'
7
7
  require 'chef/mixin/deep_merge'
8
+ require 'chef/mixin/enforce_ownership_and_permissions'
8
9
  require 'chef/mixin/from_file'
9
10
  require 'chef/mixin/language'
10
11
  require 'chef/mixin/language_include_attribute'
11
12
  require 'chef/mixin/language_include_recipe'
12
13
  require 'chef/mixin/params_validate'
14
+ require 'chef/mixin/path_sanity'
13
15
  require 'chef/mixin/recipe_definition_dsl_core'
14
16
  require 'chef/mixin/template'
17
+ require 'chef/mixin/securable'
15
18
  require 'chef/mixin/xml_escape'
@@ -0,0 +1,50 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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
+ # ensure data is written and read in binary mode
20
+ # stops "dump format error for symbol(0x75)" errors
21
+ module Moneta
22
+ class BasicFile
23
+
24
+ def store(key, value, options = {})
25
+ ensure_directory_created(::File.dirname(path(key)))
26
+ ::File.open(path(key), "wb") do |file|
27
+ if @expires
28
+ data = {:value => value}
29
+ if options[:expires_in]
30
+ data[:expires_at] = Time.now + options[:expires_in]
31
+ end
32
+ contents = Marshal.dump(data)
33
+ else
34
+ contents = Marshal.dump(value)
35
+ end
36
+ file.puts(contents)
37
+ end
38
+ end
39
+
40
+ def raw_get(key)
41
+ if ::File.respond_to?(:binread)
42
+ data = ::File.binread(path(key))
43
+ else
44
+ data = ::File.open(path(key),"rb") { |f| f.read }
45
+ end
46
+ Marshal.load(data)
47
+ end
48
+
49
+ end
50
+ end
@@ -43,7 +43,7 @@ end
43
43
  class String
44
44
  unless method_defined?(:ord)
45
45
  def ord
46
- self.unpack('c').first
46
+ self.unpack('C').first
47
47
  end
48
48
  end
49
49
  end
@@ -495,7 +495,8 @@ class Chef
495
495
  "chef_type" => "node",
496
496
  "default" => default_attrs,
497
497
  "override" => override_attrs,
498
- "run_list" => run_list.run_list
498
+ #Render correctly for run_list items so malformed json does not result
499
+ "run_list" => run_list.run_list.map { |item| item.to_s }
499
500
  }
500
501
  result["_rev"] = couchdb_rev if couchdb_rev
501
502
  result.to_json(*a)
@@ -43,6 +43,7 @@ class Chef
43
43
  :mac_os_x => {
44
44
  :default => {
45
45
  :package => Chef::Provider::Package::Macports,
46
+ :service => Chef::Provider::Service::Macosx,
46
47
  :user => Chef::Provider::User::Dscl,
47
48
  :group => Chef::Provider::Group::Dscl
48
49
  }
@@ -50,6 +51,7 @@ class Chef
50
51
  :mac_os_x_server => {
51
52
  :default => {
52
53
  :package => Chef::Provider::Package::Macports,
54
+ :service => Chef::Provider::Service::Macosx,
53
55
  :user => Chef::Provider::User::Dscl,
54
56
  :group => Chef::Provider::Group::Dscl
55
57
  }
@@ -71,6 +73,14 @@ class Chef
71
73
  :mdadm => Chef::Provider::Mdadm
72
74
  }
73
75
  },
76
+ :linuxmint => {
77
+ :default => {
78
+ :package => Chef::Provider::Package::Apt,
79
+ :service => Chef::Provider::Service::Upstart,
80
+ :cron => Chef::Provider::Cron,
81
+ :mdadm => Chef::Provider::Mdadm
82
+ }
83
+ },
74
84
  :debian => {
75
85
  :default => {
76
86
  :package => Chef::Provider::Package::Apt,
@@ -130,6 +140,14 @@ class Chef
130
140
  :group => Chef::Provider::Group::Suse
131
141
  }
132
142
  },
143
+ :oracle => {
144
+ :default => {
145
+ :service => Chef::Provider::Service::Redhat,
146
+ :cron => Chef::Provider::Cron,
147
+ :package => Chef::Provider::Package::Yum,
148
+ :mdadm => Chef::Provider::Mdadm
149
+ }
150
+ },
133
151
  :redhat => {
134
152
  :default => {
135
153
  :service => Chef::Provider::Service::Redhat,
@@ -214,6 +232,14 @@ class Chef
214
232
  :group => Chef::Provider::Group::Usermod
215
233
  }
216
234
  },
235
+ :smartos => {
236
+ :default => {
237
+ :service => Chef::Provider::Service::Solaris,
238
+ :package => Chef::Provider::Package::SmartOS,
239
+ :cron => Chef::Provider::Cron::Solaris,
240
+ :group => Chef::Provider::Group::Usermod
241
+ }
242
+ },
217
243
  :netbsd => {
218
244
  :default => {
219
245
  :group => Chef::Provider::Group::Usermod
@@ -404,6 +430,14 @@ class Chef
404
430
  provider_klass
405
431
  end
406
432
 
433
+ def windows?
434
+ if RUBY_PLATFORM =~ /mswin|mingw|windows/
435
+ true
436
+ else
437
+ false
438
+ end
439
+ end
440
+
407
441
  private
408
442
 
409
443
  def explicit_provider(platform, version, resource_type)
@@ -7,9 +7,9 @@
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
8
8
  # you may not use this file except in compliance with the License.
9
9
  # You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing, software
14
14
  # distributed under the License is distributed on an "AS IS" BASIS,
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,14 +20,16 @@
20
20
  require 'chef/mixin/from_file'
21
21
  require 'chef/mixin/convert_to_class_name'
22
22
  require 'chef/mixin/recipe_definition_dsl_core'
23
+ require 'chef/mixin/enforce_ownership_and_permissions'
23
24
 
24
25
  class Chef
25
26
  class Provider
26
-
27
+
27
28
  include Chef::Mixin::RecipeDefinitionDSLCore
28
-
29
+ include Chef::Mixin::EnforceOwnershipAndPermissions
30
+
29
31
  attr_accessor :new_resource, :current_resource, :run_context
30
-
32
+
31
33
  def initialize(new_resource, run_context)
32
34
  @new_resource = new_resource
33
35
  @current_resource = nil
@@ -46,18 +48,18 @@ class Chef
46
48
  def cookbook_name
47
49
  new_resource.cookbook_name
48
50
  end
49
-
51
+
50
52
  def load_current_resource
51
53
  raise Chef::Exceptions::Override, "You must override load_current_resource in #{self.to_s}"
52
54
  end
53
-
55
+
54
56
  def action_nothing
55
57
  Chef::Log.debug("Doing nothing for #{@new_resource.to_s}")
56
58
  true
57
59
  end
58
-
60
+
59
61
  protected
60
-
62
+
61
63
  def recipe_eval(&block)
62
64
  # This block has new resource definitions within it, which
63
65
  # essentially makes it an in-line Chef run. Save our current
@@ -72,32 +74,32 @@ class Chef
72
74
  @run_context.resource_collection = Chef::ResourceCollection.new
73
75
  instance_eval(&block)
74
76
  Chef::Runner.new(@run_context).converge
75
-
77
+
76
78
  @run_context = saved_run_context
77
79
  end
78
-
80
+
79
81
  public
80
-
82
+
81
83
  class << self
82
84
  include Chef::Mixin::ConvertToClassName
83
-
85
+
84
86
  def build_from_file(cookbook_name, filename, run_context)
85
87
  pname = filename_to_qualified_string(cookbook_name, filename)
86
-
88
+
87
89
  # Add log entry if we override an existing light-weight provider.
88
90
  class_name = convert_to_class_name(pname)
89
91
  overriding = Chef::Provider.const_defined?(class_name)
90
92
  Chef::Log.info("#{class_name} light-weight provider already initialized -- overriding!") if overriding
91
-
93
+
92
94
  new_provider_class = Class.new self do |cls|
93
-
95
+
94
96
  def load_current_resource
95
97
  # silence Chef::Exceptions::Override exception
96
98
  end
97
-
99
+
98
100
  class << cls
99
101
  include Chef::Mixin::FromFile
100
-
102
+
101
103
  # setup DSL's shortcut methods
102
104
  def action(name, &block)
103
105
  define_method("action_#{name.to_s}") do
@@ -105,17 +107,17 @@ class Chef
105
107
  end
106
108
  end
107
109
  end
108
-
110
+
109
111
  # load provider definition from file
110
112
  cls.class_from_file(filename)
111
113
  end
112
-
114
+
113
115
  # register new class as a Chef::Provider
114
116
  pname = filename_to_qualified_string(cookbook_name, filename)
115
117
  class_name = convert_to_class_name(pname)
116
118
  Chef::Provider.const_set(class_name, new_provider_class)
117
119
  Chef::Log.debug("Loaded contents of #{filename} into a provider named #{pname} defined in Chef::Provider::#{class_name}")
118
-
120
+
119
121
  new_provider_class
120
122
  end
121
123
  end
@@ -26,6 +26,7 @@ class Chef
26
26
  include Chef::Mixin::Command
27
27
 
28
28
  CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
29
+ CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home, :environment]
29
30
 
30
31
  def initialize(new_resource, run_context)
31
32
  super(new_resource, run_context)
@@ -52,17 +53,8 @@ class Chef
52
53
  cron_found = true
53
54
  @cron_exists = true
54
55
  next
55
- when /^MAILTO=(\S*)/
56
- @current_resource.mailto($1) if cron_found
57
- next
58
- when /^PATH=(\S*)/
59
- @current_resource.path($1) if cron_found
60
- next
61
- when /^SHELL=(\S*)/
62
- @current_resource.shell($1) if cron_found
63
- next
64
- when /^HOME=(\S*)/
65
- @current_resource.home($1) if cron_found
56
+ when /^(\S*)=(\S*)/
57
+ set_environment_var($1, $2) if cron_found
66
58
  next
67
59
  when CRON_PATTERN
68
60
  if cron_found
@@ -89,7 +81,7 @@ class Chef
89
81
  end
90
82
 
91
83
  def compare_cron
92
- [ :minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home ].any? do |cron_var|
84
+ CRON_ATTRIBUTES.any? do |cron_var|
93
85
  !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
94
86
  end
95
87
  end
@@ -103,6 +95,9 @@ class Chef
103
95
  [ :mailto, :path, :shell, :home ].each do |v|
104
96
  newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
105
97
  end
98
+ @new_resource.environment.each do |name, value|
99
+ newcron << "#{name}=#{value}\n"
100
+ end
106
101
  newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
107
102
 
108
103
  if @cron_exists
@@ -181,6 +176,16 @@ class Chef
181
176
  end
182
177
  end
183
178
 
179
+ private
180
+
181
+ def set_environment_var(attr_name, attr_value)
182
+ method_name = attr_name.downcase.to_sym
183
+ if CRON_ATTRIBUTES.include?(method_name)
184
+ @current_resource.send(method_name, attr_value)
185
+ else
186
+ @current_resource.environment(@current_resource.environment.merge(attr_name => attr_value))
187
+ end
188
+ end
184
189
  end
185
190
  end
186
191
  end
@@ -55,17 +55,8 @@ class Chef
55
55
  cron_found = true
56
56
  @cron_exists = true
57
57
  next
58
- when /^MAILTO=(\S*)/
59
- @current_resource.mailto($1) if cron_found
60
- next
61
- when /^PATH=(\S*)/
62
- @current_resource.path($1) if cron_found
63
- next
64
- when /^SHELL=(\S*)/
65
- @current_resource.shell($1) if cron_found
66
- next
67
- when /^HOME=(\S*)/
68
- @current_resource.home($1) if cron_found
58
+ when /^(\S*)=(\S*)/
59
+ set_environment_var($1, $2) if cron_found
69
60
  next
70
61
  when CRON_PATTERN
71
62
  if cron_found
@@ -91,12 +82,6 @@ class Chef
91
82
  @current_resource
92
83
  end
93
84
 
94
- def compare_cron
95
- [ :minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home ].any? do |cron_var|
96
- !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
97
- end
98
- end
99
-
100
85
  def write_crontab(crontab)
101
86
  tempcron = Tempfile.new("chef-cron")
102
87
  tempcron << crontab
@@ -121,6 +106,10 @@ class Chef
121
106
  [ :mailto, :path, :shell, :home ].each do |v|
122
107
  newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
123
108
  end
109
+ @new_resource.environment.each do |name, value|
110
+ newcron << "#{name}=#{value}\n"
111
+ end
112
+
124
113
  newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
125
114
 
126
115
  if @cron_exists
@@ -188,7 +177,6 @@ class Chef
188
177
  Chef::Log.info("#{@new_resource} deleted crontab entry")
189
178
  end
190
179
  end
191
-
192
180
  end
193
181
  end
194
182
  end
@@ -65,7 +65,7 @@ class Chef
65
65
  if current_release?(release_path)
66
66
  Chef::Log.debug("#{@new_resource} is the latest version")
67
67
  else
68
- action_rollback
68
+ rollback_to release_path
69
69
  end
70
70
  else
71
71
 
@@ -93,16 +93,15 @@ class Chef
93
93
  end
94
94
 
95
95
  def action_rollback
96
- if release_path
97
- rp_index = all_releases.index(release_path)
98
- raise RuntimeError, "There is no release to rollback to!" unless rp_index
99
- rp_index += 1
100
- releases_to_nuke = all_releases[rp_index..-1]
101
- else
102
- @release_path = all_releases[-2]
103
- raise RuntimeError, "There is no release to rollback to!" unless @release_path
104
- releases_to_nuke = [ all_releases.last ]
105
- end
96
+ rollback_to all_releases[-2]
97
+ end
98
+
99
+ def rollback_to(target_release_path)
100
+ @release_path = target_release_path
101
+ raise RuntimeError, "There is no release to rollback to!" unless @release_path
102
+
103
+ rp_index = all_releases.index(release_path)
104
+ releases_to_nuke = all_releases[(rp_index + 1)..-1]
106
105
 
107
106
  rollback
108
107
 
@@ -170,7 +169,7 @@ class Chef
170
169
  end.join(" ")
171
170
 
172
171
  Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
173
- run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path, :command_log_level => :info))
172
+ run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path, :log_level => :info))
174
173
  end
175
174
  end
176
175
 
@@ -338,9 +337,9 @@ class Chef
338
337
  run_opts[:user] = @new_resource.user if @new_resource.user
339
338
  run_opts[:group] = @new_resource.group if @new_resource.group
340
339
  run_opts[:environment] = @new_resource.environment if @new_resource.environment
341
- run_opts[:command_log_prepend] = @new_resource.to_s
342
- run_opts[:command_log_level] ||= :debug
343
- if run_opts[:command_log_level] == :info
340
+ run_opts[:log_tag] = @new_resource.to_s
341
+ run_opts[:log_level] ||= :debug
342
+ if run_opts[:log_level] == :info
344
343
  if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
345
344
  run_opts[:live_stream] = STDOUT
346
345
  end