chef 0.7.16 → 0.8.2

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 (180) hide show
  1. data/README.rdoc +11 -10
  2. data/bin/chef-client +2 -2
  3. data/bin/chef-solo +1 -1
  4. data/bin/knife +27 -0
  5. data/bin/shef +49 -0
  6. data/distro/README +2 -0
  7. data/distro/{debian → common}/man/man1/chef-indexer.1 +0 -0
  8. data/distro/{debian → common}/man/man1/chef-server.1 +0 -0
  9. data/distro/{debian → common}/man/man8/chef-client.8 +0 -0
  10. data/distro/{debian → common}/man/man8/chef-solo.8 +0 -0
  11. data/distro/common/man/man8/knife.8 +375 -0
  12. data/distro/redhat/etc/init.d/chef-client +8 -4
  13. data/distro/redhat/etc/init.d/chef-server +16 -15
  14. data/distro/redhat/etc/init.d/chef-server-webui +78 -0
  15. data/distro/redhat/etc/init.d/chef-solr +76 -0
  16. data/distro/redhat/etc/init.d/chef-solr-indexer +75 -0
  17. data/distro/redhat/etc/sysconfig/chef-client +10 -0
  18. data/distro/redhat/etc/sysconfig/chef-server +10 -0
  19. data/distro/redhat/etc/sysconfig/chef-server-webui +10 -0
  20. data/distro/redhat/etc/sysconfig/chef-solr +9 -0
  21. data/distro/redhat/etc/sysconfig/chef-solr-indexer +7 -0
  22. data/distro/suse/etc/init.d/chef-client +121 -0
  23. data/lib/chef.rb +1 -1
  24. data/lib/chef/api_client.rb +263 -0
  25. data/lib/chef/application.rb +1 -1
  26. data/lib/chef/application/client.rb +21 -3
  27. data/lib/chef/application/knife.rb +144 -0
  28. data/lib/chef/application/server.rb +2 -1
  29. data/lib/chef/application/solo.rb +9 -2
  30. data/lib/chef/cache.rb +61 -0
  31. data/lib/chef/cache/checksum.rb +70 -0
  32. data/lib/chef/certificate.rb +154 -0
  33. data/lib/chef/client.rb +123 -220
  34. data/lib/chef/compile.rb +9 -21
  35. data/lib/chef/config.rb +67 -10
  36. data/lib/chef/cookbook.rb +49 -22
  37. data/lib/chef/cookbook/metadata.rb +85 -5
  38. data/lib/chef/cookbook_loader.rb +4 -4
  39. data/lib/chef/couchdb.rb +99 -30
  40. data/lib/chef/daemon.rb +1 -1
  41. data/lib/chef/data_bag.rb +215 -0
  42. data/lib/chef/data_bag_item.rb +219 -0
  43. data/lib/chef/exceptions.rb +3 -0
  44. data/lib/chef/index_queue.rb +29 -0
  45. data/lib/chef/index_queue/amqp_client.rb +106 -0
  46. data/lib/chef/index_queue/consumer.rb +76 -0
  47. data/lib/chef/index_queue/indexable.rb +74 -0
  48. data/lib/chef/knife.rb +309 -0
  49. data/lib/chef/knife/client_bulk_delete.rb +40 -0
  50. data/lib/chef/knife/client_create.rb +62 -0
  51. data/lib/chef/knife/client_delete.rb +37 -0
  52. data/lib/chef/knife/client_edit.rb +37 -0
  53. data/lib/chef/knife/client_list.rb +40 -0
  54. data/lib/chef/knife/client_reregister.rb +48 -0
  55. data/lib/chef/knife/client_show.rb +42 -0
  56. data/lib/chef/knife/configure.rb +123 -0
  57. data/lib/chef/knife/cookbook_bulk_delete.rb +46 -0
  58. data/lib/chef/knife/cookbook_delete.rb +41 -0
  59. data/lib/chef/knife/cookbook_download.rb +57 -0
  60. data/lib/chef/knife/cookbook_list.rb +41 -0
  61. data/lib/chef/knife/cookbook_metadata.rb +87 -0
  62. data/lib/chef/knife/cookbook_show.rb +75 -0
  63. data/lib/chef/knife/cookbook_upload.rb +179 -0
  64. data/lib/chef/knife/data_bag_create.rb +43 -0
  65. data/lib/chef/knife/data_bag_delete.rb +43 -0
  66. data/lib/chef/knife/data_bag_edit.rb +49 -0
  67. data/lib/chef/knife/data_bag_list.rb +42 -0
  68. data/lib/chef/knife/data_bag_show.rb +40 -0
  69. data/lib/chef/knife/ec2_instance_data.rb +46 -0
  70. data/lib/chef/knife/index_rebuild.rb +51 -0
  71. data/lib/chef/knife/node_bulk_delete.rb +43 -0
  72. data/lib/chef/knife/node_create.rb +39 -0
  73. data/lib/chef/knife/node_delete.rb +36 -0
  74. data/lib/chef/knife/node_edit.rb +36 -0
  75. data/lib/chef/knife/node_from_file.rb +42 -0
  76. data/lib/chef/knife/node_list.rb +41 -0
  77. data/lib/chef/knife/node_run_list_add.rb +64 -0
  78. data/lib/chef/knife/node_run_list_remove.rb +45 -0
  79. data/lib/chef/knife/node_show.rb +46 -0
  80. data/lib/chef/knife/role_bulk_delete.rb +44 -0
  81. data/lib/chef/knife/role_create.rb +44 -0
  82. data/lib/chef/knife/role_delete.rb +36 -0
  83. data/lib/chef/knife/role_edit.rb +37 -0
  84. data/lib/chef/knife/role_from_file.rb +46 -0
  85. data/lib/chef/knife/role_list.rb +40 -0
  86. data/lib/chef/knife/role_show.rb +43 -0
  87. data/lib/chef/knife/search.rb +94 -0
  88. data/lib/chef/knife/ssh.rb +170 -0
  89. data/lib/chef/log.rb +30 -8
  90. data/lib/chef/mixin/checksum.rb +2 -7
  91. data/lib/chef/mixin/command.rb +32 -13
  92. data/lib/chef/mixin/convert_to_class_name.rb +15 -0
  93. data/lib/chef/mixin/deep_merge.rb +199 -11
  94. data/lib/chef/mixin/generate_url.rb +18 -9
  95. data/lib/chef/mixin/language.rb +29 -1
  96. data/lib/chef/mixin/language_include_attribute.rb +56 -0
  97. data/lib/chef/mixin/language_include_recipe.rb +53 -0
  98. data/lib/chef/mixin/params_validate.rb +25 -12
  99. data/lib/chef/mixin/recipe_definition_dsl_core.rb +2 -0
  100. data/lib/chef/mixin/template.rb +11 -1
  101. data/lib/chef/mixin/xml_escape.rb +87 -0
  102. data/lib/chef/node.rb +144 -122
  103. data/lib/chef/openid_registration.rb +12 -5
  104. data/lib/chef/platform.rb +89 -47
  105. data/lib/chef/provider/breakpoint.rb +36 -0
  106. data/lib/chef/provider/cron.rb +5 -6
  107. data/lib/chef/provider/deploy.rb +43 -10
  108. data/lib/chef/provider/deploy/revision.rb +2 -3
  109. data/lib/chef/provider/erl_call.rb +72 -0
  110. data/lib/chef/provider/file.rb +8 -4
  111. data/lib/chef/provider/git.rb +10 -5
  112. data/lib/chef/provider/group/dscl.rb +128 -0
  113. data/lib/chef/provider/http_request.rb +6 -2
  114. data/lib/chef/provider/ifconfig.rb +1 -0
  115. data/lib/chef/provider/link.rb +1 -1
  116. data/lib/chef/provider/log.rb +53 -0
  117. data/lib/chef/provider/mdadm.rb +88 -0
  118. data/lib/chef/provider/mount/mount.rb +1 -1
  119. data/lib/chef/provider/package.rb +1 -1
  120. data/lib/chef/provider/package/easy_install.rb +106 -0
  121. data/lib/chef/provider/package/pacman.rb +101 -0
  122. data/lib/chef/provider/package/portage.rb +1 -1
  123. data/lib/chef/provider/package/rpm.rb +10 -8
  124. data/lib/chef/provider/package/yum-dump.py +22 -3
  125. data/lib/chef/provider/package/yum.rb +32 -8
  126. data/lib/chef/provider/package/zypper.rb +132 -0
  127. data/lib/chef/provider/remote_directory.rb +58 -49
  128. data/lib/chef/provider/remote_file.rb +1 -1
  129. data/lib/chef/provider/route.rb +136 -80
  130. data/lib/chef/provider/ruby_block.rb +18 -1
  131. data/lib/chef/provider/service/arch.rb +109 -0
  132. data/lib/chef/provider/service/freebsd.rb +0 -1
  133. data/lib/chef/provider/service/simple.rb +2 -3
  134. data/lib/chef/provider/service/upstart.rb +191 -0
  135. data/lib/chef/provider/subversion.rb +12 -4
  136. data/lib/chef/provider/template.rb +85 -53
  137. data/lib/chef/provider/user.rb +1 -1
  138. data/lib/chef/provider/user/dscl.rb +277 -0
  139. data/lib/chef/provider/user/useradd.rb +1 -0
  140. data/lib/chef/recipe.rb +2 -41
  141. data/lib/chef/resource.rb +9 -3
  142. data/lib/chef/resource/breakpoint.rb +35 -0
  143. data/lib/chef/resource/deploy.rb +16 -2
  144. data/lib/chef/resource/easy_install_package.rb +41 -0
  145. data/lib/chef/resource/erl_call.rb +83 -0
  146. data/lib/chef/resource/freebsd_package.rb +35 -0
  147. data/lib/chef/resource/log.rb +62 -0
  148. data/lib/chef/resource/mdadm.rb +82 -0
  149. data/lib/chef/resource/pacman_package.rb +33 -0
  150. data/lib/chef/resource/ruby_block.rb +21 -2
  151. data/lib/chef/resource/scm.rb +8 -0
  152. data/lib/chef/resource/subversion.rb +1 -0
  153. data/lib/chef/resource/user.rb +5 -2
  154. data/lib/chef/resource/yum_package.rb +36 -0
  155. data/lib/chef/resource_collection.rb +17 -9
  156. data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
  157. data/lib/chef/rest.rb +166 -81
  158. data/lib/chef/role.rb +114 -38
  159. data/lib/chef/run_list.rb +15 -6
  160. data/lib/chef/runner.rb +13 -11
  161. data/lib/chef/search/query.rb +60 -0
  162. data/lib/chef/shef.rb +220 -0
  163. data/lib/chef/shef/ext.rb +297 -0
  164. data/lib/chef/shef/shef_session.rb +175 -0
  165. data/lib/chef/streaming_cookbook_uploader.rb +187 -0
  166. data/lib/chef/tasks/chef_repo.rake +53 -155
  167. data/lib/chef/util/file_edit.rb +94 -96
  168. data/lib/chef/webui_user.rb +233 -0
  169. metadata +219 -63
  170. data/distro/debian/etc/init.d/chef-indexer +0 -175
  171. data/distro/redhat/etc/chef/client.rb +0 -16
  172. data/distro/redhat/etc/chef/indexer.rb +0 -10
  173. data/distro/redhat/etc/chef/server.rb +0 -22
  174. data/distro/redhat/etc/init.d/chef-indexer +0 -76
  175. data/lib/chef/application/indexer.rb +0 -141
  176. data/lib/chef/queue.rb +0 -145
  177. data/lib/chef/search.rb +0 -88
  178. data/lib/chef/search/result.rb +0 -64
  179. data/lib/chef/search_index.rb +0 -77
  180. data/lib/chef/util/fileedit.rb +0 -121
@@ -19,6 +19,7 @@
19
19
  require 'chef/config'
20
20
  require 'chef/mixin/params_validate'
21
21
  require 'chef/couchdb'
22
+ require 'chef/index_queue'
22
23
  require 'digest/sha1'
23
24
  require 'rubygems'
24
25
  require 'json'
@@ -29,6 +30,7 @@ class Chef
29
30
  attr_accessor :name, :salt, :validated, :password, :couchdb_rev, :admin
30
31
 
31
32
  include Chef::Mixin::ParamsValidate
33
+ include Chef::IndexQueue::Indexable
32
34
 
33
35
  DESIGN_DOCUMENT = {
34
36
  "version" => 3,
@@ -138,6 +140,10 @@ class Chef
138
140
  end
139
141
  end
140
142
 
143
+ def self.cdb_list(*args)
144
+ list(*args)
145
+ end
146
+
141
147
  # Load an OpenIDRegistration by name from CouchDB
142
148
  def self.load(name)
143
149
  Chef::CouchDB.new.load("openid_registration", name)
@@ -148,20 +154,21 @@ class Chef
148
154
  Chef::CouchDB.new.has_key?("openid_registration", name)
149
155
  end
150
156
 
151
- # Remove this node from the CouchDB
157
+ # Remove this OpenIDRegistration from the CouchDB
152
158
  def destroy
153
159
  @couchdb.delete("openid_registration", @name, @couchdb_rev)
154
160
  end
155
161
 
156
- # Save this node to the CouchDB
162
+ # Save this OpenIDRegistration to the CouchDB
157
163
  def save
158
164
  results = @couchdb.store("openid_registration", @name, self)
159
165
  @couchdb_rev = results["rev"]
160
166
  end
161
167
 
162
168
  # Set up our CouchDB design document
163
- def self.create_design_document
164
- Chef::CouchDB.new.create_design_document("registrations", DESIGN_DOCUMENT)
169
+ def self.create_design_document(couchdb=nil)
170
+ couchdb ||= Chef::CouchDB.new
171
+ couchdb.create_design_document("registrations", DESIGN_DOCUMENT)
165
172
  end
166
173
 
167
174
  protected
@@ -178,4 +185,4 @@ class Chef
178
185
  end
179
186
 
180
187
  end
181
- end
188
+ end
@@ -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.
@@ -25,19 +25,22 @@ Dir[File.join(File.dirname(__FILE__), 'provider/**/*.rb')].sort.each { |lib| req
25
25
 
26
26
  class Chef
27
27
  class Platform
28
-
28
+
29
29
  @platforms = {
30
30
  :mac_os_x => {
31
31
  :default => {
32
- :package => Chef::Provider::Package::Macports
32
+ :package => Chef::Provider::Package::Macports,
33
+ :user => Chef::Provider::User::Dscl,
34
+ :group => Chef::Provider::Group::Dscl
33
35
  }
34
36
  },
35
37
  :freebsd => {
36
38
  :default => {
37
- :group => Chef::Provider::Group::Pw,
39
+ :group => Chef::Provider::Group::Pw,
38
40
  :package => Chef::Provider::Package::Freebsd,
39
41
  :service => Chef::Provider::Service::Freebsd,
40
- :user => Chef::Provider::User::Pw
42
+ :user => Chef::Provider::User::Pw,
43
+ :cron => Chef::Provider::Cron
41
44
  }
42
45
  },
43
46
  :ubuntu => {
@@ -45,6 +48,7 @@ class Chef
45
48
  :package => Chef::Provider::Package::Apt,
46
49
  :service => Chef::Provider::Service::Debian,
47
50
  :cron => Chef::Provider::Cron,
51
+ :mdadm => Chef::Provider::Mdadm
48
52
  }
49
53
  },
50
54
  :debian => {
@@ -52,20 +56,30 @@ class Chef
52
56
  :package => Chef::Provider::Package::Apt,
53
57
  :service => Chef::Provider::Service::Debian,
54
58
  :cron => Chef::Provider::Cron,
59
+ :mdadm => Chef::Provider::Mdadm
55
60
  }
56
61
  },
57
62
  :centos => {
58
63
  :default => {
59
64
  :service => Chef::Provider::Service::Redhat,
60
65
  :cron => Chef::Provider::Cron,
61
- :package => Chef::Provider::Package::Yum
66
+ :package => Chef::Provider::Package::Yum,
67
+ :mdadm => Chef::Provider::Mdadm
68
+ }
69
+ },
70
+ :suse => {
71
+ :default => {
72
+ :service => Chef::Provider::Service::Redhat,
73
+ :cron => Chef::Provider::Cron,
74
+ :package => Chef::Provider::Package::Zypper
62
75
  }
63
76
  },
64
77
  :redhat => {
65
78
  :default => {
66
79
  :service => Chef::Provider::Service::Redhat,
67
80
  :cron => Chef::Provider::Cron,
68
- :package => Chef::Provider::Package::Yum
81
+ :package => Chef::Provider::Package::Yum,
82
+ :mdadm => Chef::Provider::Mdadm
69
83
  }
70
84
  },
71
85
  :gentoo => {
@@ -73,6 +87,15 @@ class Chef
73
87
  :package => Chef::Provider::Package::Portage,
74
88
  :service => Chef::Provider::Service::Gentoo,
75
89
  :cron => Chef::Provider::Cron,
90
+ :mdadm => Chef::Provider::Mdadm
91
+ }
92
+ },
93
+ :arch => {
94
+ :default => {
95
+ :package => Chef::Provider::Package::Pacman,
96
+ :service => Chef::Provider::Service::Arch,
97
+ :cron => Chef::Provider::Cron,
98
+ :mdadm => Chef::Provider::Mdadm
76
99
  }
77
100
  },
78
101
  :solaris => {},
@@ -97,27 +120,29 @@ class Chef
97
120
  :http_request => Chef::Provider::HttpRequest,
98
121
  :route => Chef::Provider::Route,
99
122
  :ifconfig => Chef::Provider::Ifconfig,
100
- :ruby_block => Chef::Provider::RubyBlock
123
+ :ruby_block => Chef::Provider::RubyBlock,
124
+ :erl_call => Chef::Provider::ErlCall,
125
+ :log => Chef::Provider::Log::ChefLog
101
126
  }
102
127
  }
103
128
 
104
129
  class << self
105
130
  attr_accessor :platforms
106
-
131
+
107
132
  include Chef::Mixin::ParamsValidate
108
-
133
+
109
134
  def find(name, version)
110
135
  provider_map = @platforms[:default].clone
111
-
136
+
112
137
  name_sym = name
113
138
  if name.kind_of?(String)
114
139
  name.downcase!
115
140
  name.gsub!(/\s/, "_")
116
141
  name_sym = name.to_sym
117
142
  end
118
-
143
+
119
144
  if @platforms.has_key?(name_sym)
120
- if @platforms[name_sym].has_key?(version)
145
+ if @platforms[name_sym].has_key?(version)
121
146
  Chef::Log.debug("Platform #{name.to_s} version #{version} found")
122
147
  if @platforms[name_sym].has_key?(:default)
123
148
  provider_map.merge!(@platforms[name_sym][:default])
@@ -131,37 +156,19 @@ class Chef
131
156
  end
132
157
  provider_map
133
158
  end
134
-
135
- def find_provider(platform, version, resource_type)
136
- pmap = Chef::Platform.find(platform, version)
137
- rtkey = resource_type
138
- if resource_type.kind_of?(Chef::Resource)
139
- return resource_type.provider if resource_type.provider
140
- rtkey = resource_type.resource_name.to_sym
141
- end
142
- if pmap.has_key?(rtkey)
143
- pmap[rtkey]
144
- else
145
- Chef::Log.error("#{rtkey.inspect} #{pmap.inspect}")
146
- raise(
147
- ArgumentError,
148
- "Cannot find a provider for #{resource_type} on #{platform} version #{version}"
149
- )
150
- end
151
- end
152
-
159
+
153
160
  def find_platform_and_version(node)
154
161
  platform = nil
155
162
  version = nil
156
-
163
+
157
164
  if node[:platform]
158
165
  platform = node[:platform]
159
166
  elsif node.attribute?("os")
160
167
  platform = node[:os]
161
168
  end
162
-
169
+
163
170
  raise ArgumentError, "Cannot find a platform for #{node}" unless platform
164
-
171
+
165
172
  if node[:platform_version]
166
173
  version = node[:platform_version]
167
174
  elsif node[:os_version]
@@ -169,21 +176,21 @@ class Chef
169
176
  elsif node[:os_release]
170
177
  version = node[:os_release]
171
178
  end
172
-
179
+
173
180
  raise ArgumentError, "Cannot find a version for #{node}" unless version
174
-
181
+
175
182
  return platform, version
176
183
  end
177
-
184
+
178
185
  def provider_for_node(node, resource_type)
179
186
  find_provider_for_node(node, resource_type).new(node, resource_type)
180
187
  end
181
188
 
182
189
  def find_provider_for_node(node, resource_type)
183
- platform, version = find_platform_and_version(node)
190
+ platform, version = find_platform_and_version(node)
184
191
  provider = find_provider(platform, version, resource_type)
185
192
  end
186
-
193
+
187
194
  def set(args)
188
195
  validate(
189
196
  args,
@@ -204,14 +211,14 @@ class Chef
204
211
  }
205
212
  }
206
213
  )
207
- if args.has_key?(:platform)
214
+ if args.has_key?(:platform)
208
215
  if args.has_key?(:version)
209
216
  if @platforms.has_key?(args[:platform])
210
217
  if @platforms[args[:platform]].has_key?(args[:version])
211
218
  @platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
212
219
  else
213
220
  @platforms[args[:platform]][args[:version]] = {
214
- args[:resource].to_sym => args[:provider]
221
+ args[:resource].to_sym => args[:provider]
215
222
  }
216
223
  end
217
224
  else
@@ -222,7 +229,7 @@ class Chef
222
229
  }
223
230
  end
224
231
  else
225
- if @platforms.has_key?(args[:platform])
232
+ if @platforms.has_key?(args[:platform])
226
233
  if @platforms[args[:platform]].has_key?(:default)
227
234
  @platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
228
235
  else
@@ -246,8 +253,43 @@ class Chef
246
253
  end
247
254
  end
248
255
  end
249
-
250
- end
251
-
256
+
257
+ def find_provider(platform, version, resource_type)
258
+ pmap = Chef::Platform.find(platform, version)
259
+ provider_klass = explicit_provider(platform, version, resource_type) ||
260
+ platform_provider(platform, version, resource_type) ||
261
+ resource_matching_provider(platform, version, resource_type)
262
+
263
+ raise ArgumentError, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil?
264
+
265
+ provider_klass
266
+ end
267
+
268
+ private
269
+
270
+ def explicit_provider(platform, version, resource_type)
271
+ resource_type.kind_of?(Chef::Resource) ? resource_type.provider : nil
272
+ end
273
+
274
+ def platform_provider(platform, version, resource_type)
275
+ pmap = Chef::Platform.find(platform, version)
276
+ rtkey = resource_type.kind_of?(Chef::Resource) ? resource_type.resource_name.to_sym : resource_type
277
+ pmap.has_key?(rtkey) ? pmap[rtkey] : nil
278
+ end
279
+
280
+ def resource_matching_provider(platform, version, resource_type)
281
+ if resource_type.kind_of?(Chef::Resource)
282
+ begin
283
+ Chef::Provider.const_get(resource_type.class.to_s.split('::').last)
284
+ rescue NameError
285
+ nil
286
+ end
287
+ else
288
+ nil
289
+ end
290
+ end
291
+
292
+ end
293
+
252
294
  end
253
295
  end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@kallistec.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
+ class Chef
20
+ class Provider
21
+ class Breakpoint < Chef::Provider
22
+
23
+ def load_current_resource
24
+ end
25
+
26
+ def action_break
27
+ if defined?(Shef) && Shef.running?
28
+ @collection.iterator.pause
29
+ @new_resource.updated = true
30
+ @collection.iterator
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -25,6 +25,8 @@ class Chef
25
25
  class Cron < Chef::Provider
26
26
  include Chef::Mixin::Command
27
27
 
28
+ CRON_PATTERN = /([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*(.*)/
29
+
28
30
  def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
29
31
  super(node, new_resource, collection, definitions, cookbook_loader)
30
32
  @cron_exists = false
@@ -62,7 +64,7 @@ class Chef
62
64
  when /^HOME=(\S*)/
63
65
  @current_resource.home($1) if cron_found
64
66
  next
65
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
67
+ when CRON_PATTERN
66
68
  if cron_found
67
69
  @current_resource.minute($1)
68
70
  @current_resource.hour($2)
@@ -114,7 +116,7 @@ class Chef
114
116
  when /^# Chef Name: #{@new_resource.name}\n/
115
117
  cron_found = true
116
118
  next
117
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
119
+ when CRON_PATTERN
118
120
  if cron_found
119
121
  cron_found = false
120
122
  crontab << newcron
@@ -129,7 +131,6 @@ class Chef
129
131
 
130
132
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
131
133
  crontab.each { |line| stdin.puts "#{line}" }
132
- stdin.close rescue nil
133
134
  end
134
135
  Chef::Log.info("Updated cron '#{@new_resource.name}'")
135
136
  @new_resource.updated = true
@@ -144,7 +145,6 @@ class Chef
144
145
 
145
146
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
146
147
  crontab.each { |line| stdin.puts "#{line}" }
147
- stdin.close rescue nil
148
148
  end
149
149
  Chef::Log.info("Added cron '#{@new_resource.name}'")
150
150
  @new_resource.updated = true
@@ -161,7 +161,7 @@ class Chef
161
161
  when /^# Chef Name: #{@new_resource.name}\n/
162
162
  cron_found = true
163
163
  next
164
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
164
+ when CRON_PATTERN
165
165
  if cron_found
166
166
  cron_found = false
167
167
  next
@@ -175,7 +175,6 @@ class Chef
175
175
 
176
176
  status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
177
177
  crontab.each { |line| stdin.puts "#{line}" }
178
- stdin.close rescue nil
179
178
  end
180
179
  Chef::Log.debug("Deleted cron '#{@new_resource.name}'")
181
180
  @new_resource.updated = true
@@ -61,9 +61,15 @@ class Chef
61
61
 
62
62
  def action_deploy
63
63
  if all_releases.include?(release_path)
64
- Chef::Log.info("Already deployed app at #{release_path}, skipping. Use action :force_deploy to force.")
64
+ if all_releases[-1] == release_path
65
+ Chef::Log.debug("Already deployed app at #{release_path}, and it is the latest revision. Use action :force_deploy to re-deploy this revision.")
66
+ else
67
+ Chef::Log.info("Already deployed app at #{release_path}. Rolling back to it - use action :force_deploy to re-checkout this revision.")
68
+ action_rollback
69
+ end
65
70
  else
66
71
  deploy
72
+ @new_resource.updated = true
67
73
  end
68
74
  end
69
75
 
@@ -73,18 +79,31 @@ class Chef
73
79
  FileUtils.rm_rf(release_path)
74
80
  end
75
81
  deploy
82
+ @new_resource.updated = true
76
83
  end
77
84
 
78
85
  def action_rollback
79
- @release_path = all_releases[-2]
80
- raise RuntimeError, "There is no release to rollback to!" unless @release_path
81
- release_to_nuke = all_releases.last
86
+ if release_path
87
+ rp_index = all_releases.index(release_path)
88
+ raise RuntimeError, "There is no release to rollback to!" unless rp_index
89
+ rp_index += 1
90
+ releases_to_nuke = all_releases[rp_index..-1]
91
+ else
92
+ @release_path = all_releases[-2]
93
+ raise RuntimeError, "There is no release to rollback to!" unless @release_path
94
+ releases_to_nuke = [ all_releases.last ]
95
+ end
96
+
82
97
  Chef::Log.info "rolling back to previous release: #{release_path}"
83
98
  symlink
84
- Chef::Log.info "removing last release: #{release_to_nuke}"
85
- FileUtils.rm_rf release_to_nuke
86
99
  Chef::Log.info "restarting with previous release"
87
100
  restart
101
+ releases_to_nuke.each do |i|
102
+ Chef::Log.info "Removing release: #{i}"
103
+ FileUtils.rm_rf i
104
+ release_deleted(i)
105
+ end
106
+ @new_resource.updated = true
88
107
  end
89
108
 
90
109
  def deploy
@@ -124,9 +143,10 @@ class Chef
124
143
  end
125
144
 
126
145
  def migrate
146
+ run_symlinks_before_migrate
147
+
127
148
  if @new_resource.migrate
128
149
  enforce_ownership
129
- link_shared_db_config_to_current_release
130
150
 
131
151
  environment = @new_resource.environment
132
152
  env_info = environment && environment.map do |key_and_val|
@@ -171,14 +191,27 @@ class Chef
171
191
  end
172
192
 
173
193
  def update_cached_repo
194
+ if @new_resource.svn_force_export
195
+ svn_force_export
196
+ else
197
+ run_scm_sync
198
+ end
199
+ end
200
+
201
+ def run_scm_sync
174
202
  Chef::Log.info "updating the cached checkout"
175
203
  @scm_provider.action_sync
176
204
  end
177
205
 
206
+ def svn_force_export
207
+ Chef::Log.info "exporting source repository to #{@new_resource.destination}"
208
+ @scm_provider.action_force_export
209
+ end
210
+
178
211
  def copy_cached_repo
179
212
  Chef::Log.info "copying the cached checkout to #{release_path}"
180
213
  FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
181
- FileUtils.cp_r("#{@new_resource.destination}.", release_path, :preserve => true)
214
+ FileUtils.cp_r(::File.join(@new_resource.destination, "."), release_path, :preserve => true)
182
215
  release_created(release_path)
183
216
  end
184
217
 
@@ -194,7 +227,7 @@ class Chef
194
227
  enforce_ownership
195
228
  end
196
229
 
197
- def link_shared_db_config_to_current_release
230
+ def run_symlinks_before_migrate
198
231
  links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
199
232
  Chef::Log.info "Making pre-migration symlinks: #{links_info}"
200
233
  @new_resource.symlink_before_migrate.each do |src, dest|
@@ -212,7 +245,7 @@ class Chef
212
245
  @new_resource.symlinks.each do |src, dest|
213
246
  FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
214
247
  end
215
- link_shared_db_config_to_current_release
248
+ run_symlinks_before_migrate
216
249
  enforce_ownership
217
250
  end
218
251