giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
@@ -0,0 +1,281 @@
|
|
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
|
+
require "chef/mixin/command"
|
20
|
+
require "chef/mixin/from_file"
|
21
|
+
require "chef/provider/git"
|
22
|
+
require "chef/provider/subversion"
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Deploy < Chef::Provider
|
27
|
+
|
28
|
+
include Chef::Mixin::FromFile
|
29
|
+
include Chef::Mixin::Command
|
30
|
+
|
31
|
+
attr_reader :scm_provider, :release_path
|
32
|
+
|
33
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
34
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
35
|
+
|
36
|
+
# NOTE: workaround for CHEF-577
|
37
|
+
@definitions ||= Hash.new
|
38
|
+
@collection = Chef::ResourceCollection.new
|
39
|
+
|
40
|
+
@scm_provider = @new_resource.scm_provider.new(@node, @new_resource)
|
41
|
+
|
42
|
+
# @configuration is not used by Deploy, it is only for backwards compat with
|
43
|
+
# chef-deploy or capistrano hooks that might use it to get environment information
|
44
|
+
@configuration = @new_resource.to_hash
|
45
|
+
@configuration[:environment] = @configuration[:environment] && @configuration[:environment]["RAILS_ENV"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_current_resource
|
49
|
+
@release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def sudo(command,&block)
|
53
|
+
execute(command, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def run(command, &block)
|
57
|
+
exec = execute(command, &block)
|
58
|
+
exec.user(@new_resource.user)
|
59
|
+
exec
|
60
|
+
end
|
61
|
+
|
62
|
+
def action_deploy
|
63
|
+
if all_releases.include?(release_path)
|
64
|
+
Chef::Log.info("Already deployed app at #{release_path}, skipping. Use action :force_deploy to force.")
|
65
|
+
else
|
66
|
+
deploy
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def action_force_deploy
|
71
|
+
if all_releases.include?(release_path)
|
72
|
+
Chef::Log.info("Already deployed app at #{release_path}, forcing.")
|
73
|
+
FileUtils.rm_rf(release_path)
|
74
|
+
end
|
75
|
+
deploy
|
76
|
+
end
|
77
|
+
|
78
|
+
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
|
82
|
+
Chef::Log.info "rolling back to previous release: #{release_path}"
|
83
|
+
symlink
|
84
|
+
Chef::Log.info "removing last release: #{release_to_nuke}"
|
85
|
+
FileUtils.rm_rf release_to_nuke
|
86
|
+
Chef::Log.info "restarting with previous release"
|
87
|
+
restart
|
88
|
+
end
|
89
|
+
|
90
|
+
def deploy
|
91
|
+
Chef::Log.info "deploying branch: #{@new_resource.branch}"
|
92
|
+
enforce_ownership
|
93
|
+
update_cached_repo
|
94
|
+
copy_cached_repo
|
95
|
+
install_gems
|
96
|
+
enforce_ownership
|
97
|
+
callback(:before_migrate, @new_resource.before_migrate)
|
98
|
+
migrate
|
99
|
+
callback(:before_symlink, @new_resource.before_symlink)
|
100
|
+
symlink
|
101
|
+
callback(:before_restart, @new_resource.before_restart)
|
102
|
+
restart
|
103
|
+
callback(:after_restart, @new_resource.after_restart)
|
104
|
+
cleanup!
|
105
|
+
end
|
106
|
+
|
107
|
+
def callback(what, callback_code=nil)
|
108
|
+
@collection = Chef::ResourceCollection.new
|
109
|
+
case callback_code
|
110
|
+
when Proc
|
111
|
+
Chef::Log.info "Running callback #{what} code block"
|
112
|
+
recipe_eval(&callback_code)
|
113
|
+
when String
|
114
|
+
callback_file = "#{release_path}/#{callback_code}"
|
115
|
+
unless ::File.exist?(callback_file)
|
116
|
+
raise RuntimeError, "Can't find your callback file #{callback_file}"
|
117
|
+
end
|
118
|
+
run_callback_from_file(callback_file)
|
119
|
+
when nil
|
120
|
+
run_callback_from_file("#{release_path}/deploy/#{what}.rb")
|
121
|
+
else
|
122
|
+
raise RuntimeError, "You gave me a callback I don't know what to do with: #{callback_code.inspect}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def migrate
|
127
|
+
if @new_resource.migrate
|
128
|
+
enforce_ownership
|
129
|
+
link_shared_db_config_to_current_release
|
130
|
+
|
131
|
+
environment = @new_resource.environment
|
132
|
+
env_info = environment && environment.map do |key_and_val|
|
133
|
+
"#{key_and_val.first}='#{key_and_val.last}'"
|
134
|
+
end.join(" ")
|
135
|
+
|
136
|
+
Chef::Log.info "Migrating: running #{@new_resource.migration_command} as #{@new_resource.user} " +
|
137
|
+
"with environment #{env_info}"
|
138
|
+
run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path))
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def symlink
|
143
|
+
Chef::Log.info "Symlinking"
|
144
|
+
purge_tempfiles_from_current_release
|
145
|
+
link_tempfiles_to_current_release
|
146
|
+
link_current_release_to_production
|
147
|
+
end
|
148
|
+
|
149
|
+
def restart
|
150
|
+
if restart_cmd = @new_resource.restart_command
|
151
|
+
if restart_cmd.kind_of?(Proc)
|
152
|
+
Chef::Log.info("Restarting app with embedded recipe")
|
153
|
+
recipe_eval(&restart_cmd)
|
154
|
+
else
|
155
|
+
Chef::Log.info("Restarting app with #{@new_resource.restart_command} in #{@new_resource.current_path}")
|
156
|
+
run_command(run_options(:command => @new_resource.restart_command, :cwd => @new_resource.current_path))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def cleanup!
|
162
|
+
all_releases[0..-6].each do |old_release|
|
163
|
+
Chef::Log.info "Removing old release #{old_release}"
|
164
|
+
FileUtils.rm_rf(old_release)
|
165
|
+
release_deleted(old_release)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def all_releases
|
170
|
+
Dir.glob(@new_resource.deploy_to + "/releases/*").sort
|
171
|
+
end
|
172
|
+
|
173
|
+
def update_cached_repo
|
174
|
+
Chef::Log.info "updating the cached checkout"
|
175
|
+
@scm_provider.action_sync
|
176
|
+
end
|
177
|
+
|
178
|
+
def copy_cached_repo
|
179
|
+
Chef::Log.info "copying the cached checkout to #{release_path}"
|
180
|
+
FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
|
181
|
+
FileUtils.cp_r("#{@new_resource.destination}.", release_path, :preserve => true)
|
182
|
+
release_created(release_path)
|
183
|
+
end
|
184
|
+
|
185
|
+
def enforce_ownership
|
186
|
+
Chef::Log.info "ensuring proper ownership"
|
187
|
+
FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to)
|
188
|
+
end
|
189
|
+
|
190
|
+
def link_current_release_to_production
|
191
|
+
Chef::Log.info "Linking release #{release_path} into production at #{@new_resource.current_path}"
|
192
|
+
FileUtils.rm_f(@new_resource.current_path)
|
193
|
+
FileUtils.ln_sf(release_path, @new_resource.current_path)
|
194
|
+
enforce_ownership
|
195
|
+
end
|
196
|
+
|
197
|
+
def link_shared_db_config_to_current_release
|
198
|
+
links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
199
|
+
Chef::Log.info "Making pre-migration symlinks: #{links_info}"
|
200
|
+
@new_resource.symlink_before_migrate.each do |src, dest|
|
201
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def link_tempfiles_to_current_release
|
206
|
+
dirs_info = @new_resource.create_dirs_before_symlink.join(",")
|
207
|
+
Chef::Log.info("creating directories before symlink: #{dirs_info}")
|
208
|
+
@new_resource.create_dirs_before_symlink.each { |dir| FileUtils.mkdir_p(release_path + "/#{dir}") }
|
209
|
+
|
210
|
+
links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
211
|
+
Chef::Log.info("Linking shared paths into current release: #{links_info}")
|
212
|
+
@new_resource.symlinks.each do |src, dest|
|
213
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
214
|
+
end
|
215
|
+
link_shared_db_config_to_current_release
|
216
|
+
enforce_ownership
|
217
|
+
end
|
218
|
+
|
219
|
+
def create_dirs_before_symlink
|
220
|
+
end
|
221
|
+
|
222
|
+
def purge_tempfiles_from_current_release
|
223
|
+
log_info = @new_resource.purge_before_symlink.join(", ")
|
224
|
+
Chef::Log.info("Purging directories in checkout #{log_info}")
|
225
|
+
@new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
|
226
|
+
end
|
227
|
+
|
228
|
+
protected
|
229
|
+
|
230
|
+
# Internal callback, called after copy_cached_repo.
|
231
|
+
# Override if you need to keep state externally.
|
232
|
+
def release_created(release_path)
|
233
|
+
end
|
234
|
+
|
235
|
+
# Internal callback, called during cleanup! for each old release removed.
|
236
|
+
# Override if you need to keep state externally.
|
237
|
+
def release_deleted(release_path)
|
238
|
+
end
|
239
|
+
|
240
|
+
def release_slug
|
241
|
+
raise Chef::Exceptions::Override, "You must override release_slug in #{self.to_s}"
|
242
|
+
end
|
243
|
+
|
244
|
+
def install_gems
|
245
|
+
gems_collection = Chef::ResourceCollection.new
|
246
|
+
gem_packages.each { |rbgem| gems_collection << rbgem }
|
247
|
+
Chef::Runner.new(@node, gems_collection).converge
|
248
|
+
end
|
249
|
+
|
250
|
+
def gem_packages
|
251
|
+
return [] unless ::File.exist?("#{release_path}/gems.yml")
|
252
|
+
gems = YAML.load(IO.read("#{release_path}/gems.yml"))
|
253
|
+
|
254
|
+
gems.map do |g|
|
255
|
+
r = Chef::Resource::GemPackage.new(g[:name], nil, node)
|
256
|
+
r.version g[:version]
|
257
|
+
r.action :install
|
258
|
+
r.source "http://gems.github.com"
|
259
|
+
r
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def run_options(run_opts={})
|
264
|
+
run_opts[:user] = @new_resource.user if @new_resource.user
|
265
|
+
run_opts[:group] = @new_resource.group if @new_resource.group
|
266
|
+
run_opts[:environment] = @new_resource.environment if @new_resource.environment
|
267
|
+
run_opts
|
268
|
+
end
|
269
|
+
|
270
|
+
def run_callback_from_file(callback_file)
|
271
|
+
if ::File.exist?(callback_file)
|
272
|
+
Dir.chdir(release_path) do
|
273
|
+
Chef::Log.info "running deploy hook: #{callback_file}"
|
274
|
+
recipe_eval { from_file(callback_file) }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
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 Deploy
|
22
|
+
class Revision < Chef::Provider::Deploy
|
23
|
+
|
24
|
+
def all_releases
|
25
|
+
sorted_releases
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def release_created(release)
|
31
|
+
sorted_releases { |r| r << release }
|
32
|
+
end
|
33
|
+
|
34
|
+
def release_deleted(release)
|
35
|
+
sorted_releases { |r| r.delete(release)}
|
36
|
+
end
|
37
|
+
|
38
|
+
def release_slug
|
39
|
+
scm_provider.revision_slug
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def sorted_releases
|
45
|
+
cache = load_cache
|
46
|
+
if block_given?
|
47
|
+
yield cache
|
48
|
+
save_cache(cache)
|
49
|
+
end
|
50
|
+
cache
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_cache
|
54
|
+
begin
|
55
|
+
JSON.parse(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
|
56
|
+
rescue
|
57
|
+
Chef::Exceptions::FileNotFound
|
58
|
+
save_cache([])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def save_cache(cache)
|
63
|
+
Chef::FileCache.store("revision-deploys/#{new_resource.name}", cache.to_json)
|
64
|
+
cache
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
3
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
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 Deploy
|
22
|
+
class Timestamped < Chef::Provider::Deploy
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def release_slug
|
27
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/config'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/resource/directory'
|
22
|
+
require 'chef/provider'
|
23
|
+
require 'chef/provider/file'
|
24
|
+
require 'fileutils'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Provider
|
28
|
+
class Directory < Chef::Provider::File
|
29
|
+
def load_current_resource
|
30
|
+
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
|
31
|
+
@current_resource.path(@new_resource.path)
|
32
|
+
if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path)
|
33
|
+
cstats = ::File.stat(@current_resource.path)
|
34
|
+
@current_resource.owner(cstats.uid)
|
35
|
+
@current_resource.group(cstats.gid)
|
36
|
+
@current_resource.mode("%o" % (cstats.mode & 007777))
|
37
|
+
end
|
38
|
+
@current_resource
|
39
|
+
end
|
40
|
+
|
41
|
+
def action_create
|
42
|
+
unless ::File.exists?(@new_resource.path)
|
43
|
+
Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
|
44
|
+
if @new_resource.recursive == true
|
45
|
+
::FileUtils.mkdir_p(@new_resource.path)
|
46
|
+
else
|
47
|
+
::Dir.mkdir(@new_resource.path)
|
48
|
+
end
|
49
|
+
@new_resource.updated = true
|
50
|
+
end
|
51
|
+
set_owner if @new_resource.owner != nil
|
52
|
+
set_group if @new_resource.group != nil
|
53
|
+
set_mode if @new_resource.mode != nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_delete
|
57
|
+
if ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path)
|
58
|
+
if @new_resource.recursive == true
|
59
|
+
Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}")
|
60
|
+
FileUtils.rm_rf(@new_resource.path)
|
61
|
+
else
|
62
|
+
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
|
63
|
+
::Dir.delete(@new_resource.path)
|
64
|
+
end
|
65
|
+
@new_resource.updated = true
|
66
|
+
else
|
67
|
+
raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|