chef 0.10.0.beta.6 → 0.10.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/application.rb +3 -0
- data/lib/chef/application/client.rb +34 -2
- data/lib/chef/checksum.rb +2 -2
- data/lib/chef/checksum_cache.rb +2 -2
- data/lib/chef/client.rb +7 -5
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/environment.rb +31 -9
- data/lib/chef/file_access_control.rb +7 -3
- data/lib/chef/index_queue/indexable.rb +2 -2
- data/lib/chef/knife.rb +1 -1
- data/lib/chef/knife/bootstrap.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +2 -2
- data/lib/chef/knife/cookbook_upload.rb +32 -11
- data/lib/chef/knife/core/subcommand_loader.rb +24 -13
- data/lib/chef/knife/core/text_formatter.rb +2 -2
- data/lib/chef/knife/core/ui.rb +1 -1
- data/lib/chef/knife/search.rb +1 -1
- data/lib/chef/knife/ssh.rb +1 -0
- data/lib/chef/mixin/shell_out.rb +2 -2
- data/lib/chef/node.rb +7 -4
- data/lib/chef/provider/cookbook_file.rb +4 -5
- data/lib/chef/provider/cron.rb +3 -3
- data/lib/chef/provider/cron/solaris.rb +7 -7
- data/lib/chef/provider/deploy.rb +52 -29
- data/lib/chef/provider/directory.rb +8 -8
- data/lib/chef/provider/env.rb +8 -8
- data/lib/chef/provider/erl_call.rb +7 -6
- data/lib/chef/provider/execute.rb +7 -2
- data/lib/chef/provider/file.rb +9 -9
- data/lib/chef/provider/git.rb +17 -8
- data/lib/chef/provider/group.rb +6 -6
- data/lib/chef/provider/group/aix.rb +1 -1
- data/lib/chef/provider/group/dscl.rb +2 -2
- data/lib/chef/provider/group/gpasswd.rb +3 -3
- data/lib/chef/provider/group/groupadd.rb +1 -1
- data/lib/chef/provider/group/pw.rb +3 -3
- data/lib/chef/provider/group/usermod.rb +2 -2
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +9 -7
- data/lib/chef/provider/link.rb +27 -24
- data/lib/chef/provider/mdadm.rb +10 -10
- data/lib/chef/provider/mount.rb +10 -13
- data/lib/chef/provider/mount/mount.rb +10 -10
- data/lib/chef/provider/mount/windows.rb +4 -3
- data/lib/chef/provider/ohai.rb +2 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +18 -18
- data/lib/chef/provider/package/dpkg.rb +3 -3
- data/lib/chef/provider/package/easy_install.rb +2 -2
- data/lib/chef/provider/package/freebsd.rb +4 -5
- data/lib/chef/provider/package/macports.rb +2 -2
- data/lib/chef/provider/package/pacman.rb +2 -2
- data/lib/chef/provider/package/portage.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +3 -3
- data/lib/chef/provider/package/rubygems.rb +7 -7
- data/lib/chef/provider/package/solaris.rb +9 -9
- data/lib/chef/provider/package/yum.rb +4 -4
- data/lib/chef/provider/package/zypper.rb +5 -11
- data/lib/chef/provider/remote_directory.rb +15 -14
- data/lib/chef/provider/remote_file.rb +11 -12
- data/lib/chef/provider/route.rb +8 -10
- data/lib/chef/provider/ruby_block.rb +1 -0
- data/lib/chef/provider/service.rb +10 -16
- data/lib/chef/provider/service/debian.rb +1 -1
- data/lib/chef/provider/service/freebsd.rb +16 -18
- data/lib/chef/provider/service/gentoo.rb +2 -3
- data/lib/chef/provider/service/simple.rb +7 -5
- data/lib/chef/provider/service/upstart.rb +8 -8
- data/lib/chef/provider/service/windows.rb +3 -3
- data/lib/chef/provider/subversion.rb +12 -9
- data/lib/chef/provider/template.rb +2 -3
- data/lib/chef/provider/user.rb +13 -14
- data/lib/chef/provider/user/dscl.rb +2 -2
- data/lib/chef/provider/user/pw.rb +4 -4
- data/lib/chef/provider/user/useradd.rb +3 -3
- data/lib/chef/provider/user/windows.rb +3 -3
- data/lib/chef/resource.rb +4 -3
- data/lib/chef/resource/deploy.rb +1 -1
- data/lib/chef/rest/rest_request.rb +2 -2
- data/lib/chef/run_context.rb +1 -1
- data/lib/chef/shell_out.rb +13 -1
- data/lib/chef/solr_query.rb +1 -1
- data/lib/chef/solr_query/solr_http_request.rb +1 -1
- data/lib/chef/tasks/chef_repo.rake +74 -0
- data/lib/chef/version.rb +1 -1
- metadata +2 -2
@@ -1,5 +1,3 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
1
|
# Author:: Christopher Brown (<cb@opscode.com>)
|
4
2
|
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
5
3
|
# Copyright:: Copyright (c) 2009, 2011 Opscode, Inc.
|
@@ -19,7 +17,6 @@
|
|
19
17
|
#
|
20
18
|
|
21
19
|
require 'chef/version'
|
22
|
-
|
23
20
|
class Chef
|
24
21
|
class Knife
|
25
22
|
class SubcommandLoader
|
@@ -32,11 +29,12 @@ class Chef
|
|
32
29
|
|
33
30
|
def initialize(chef_config_dir, env=ENV)
|
34
31
|
@chef_config_dir, @env = chef_config_dir, env
|
32
|
+
@forced_activate = {}
|
35
33
|
end
|
36
34
|
|
37
35
|
# Load all the sub-commands
|
38
36
|
def load_commands
|
39
|
-
subcommand_files.each { |subcommand|
|
37
|
+
subcommand_files.each { |subcommand| Kernel.load subcommand }
|
40
38
|
true
|
41
39
|
end
|
42
40
|
|
@@ -52,12 +50,18 @@ class Chef
|
|
52
50
|
# finally search ~/.chef/plugins/knife/*.rb
|
53
51
|
user_specific_files.concat Dir.glob(File.join(env['HOME'], '.chef', 'plugins', 'knife', '*.rb'))
|
54
52
|
|
55
|
-
user_specific_files.map! { |path| path[/(.+).rb/, 1] }
|
56
53
|
user_specific_files
|
57
54
|
end
|
58
55
|
|
59
|
-
# Returns
|
56
|
+
# Returns a Hash of paths to knife commands built-in to chef, or installed via gem.
|
60
57
|
# If rubygems is not installed, falls back to globbing the knife directory.
|
58
|
+
# The Hash is of the form {"relative/path" => "/absolute/path"}
|
59
|
+
#--
|
60
|
+
# Note: the "right" way to load the plugins is to require the relative path, i.e.,
|
61
|
+
# require 'chef/knife/command'
|
62
|
+
# but we're getting frustrated by bugs at every turn, and it's slow besides. So
|
63
|
+
# subcommand loader has been modified to load the plugins by using Kernel.load
|
64
|
+
# with the absolute path.
|
61
65
|
def gem_and_builtin_subcommands
|
62
66
|
# search all gems for chef/knife/*.rb
|
63
67
|
require 'rubygems'
|
@@ -67,23 +71,30 @@ class Chef
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def subcommand_files
|
70
|
-
@subcommand_files ||= (gem_and_builtin_subcommands + site_subcommands).flatten.uniq
|
74
|
+
@subcommand_files ||= (gem_and_builtin_subcommands.values + site_subcommands).flatten.uniq
|
71
75
|
end
|
72
76
|
|
73
77
|
def find_subcommands_via_dirglob
|
74
78
|
# The "require paths" of the core knife subcommands bundled with chef
|
75
79
|
files = Dir[File.expand_path('../../../knife/*.rb', __FILE__)]
|
76
|
-
|
77
|
-
files
|
80
|
+
subcommand_files = {}
|
81
|
+
files.each do |knife_file|
|
82
|
+
rel_path = knife_file[/#{CHEF_ROOT}#{Regexp.escape(File::SEPARATOR)}(.*)\.rb/,1]
|
83
|
+
subcommand_files[rel_path] = knife_file
|
84
|
+
end
|
85
|
+
subcommand_files
|
78
86
|
end
|
79
87
|
|
80
88
|
def find_subcommands_via_rubygems
|
81
89
|
files = Gem.find_files 'chef/knife/*.rb'
|
82
90
|
files.reject! {|f| from_old_gem?(f) }
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
91
|
+
subcommand_files = {}
|
92
|
+
files.each do |file|
|
93
|
+
rel_path = file[/(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 1]
|
94
|
+
subcommand_files[rel_path] = file
|
95
|
+
end
|
96
|
+
|
97
|
+
subcommand_files.merge(find_subcommands_via_dirglob)
|
87
98
|
end
|
88
99
|
|
89
100
|
private
|
@@ -72,7 +72,7 @@ class Chef
|
|
72
72
|
# Ruby 1.8 Strings include enumberable, which is not what we want. So
|
73
73
|
# we have this heuristic to detect hashes and arrays instead.
|
74
74
|
def should_enumerate?(value)
|
75
|
-
((value.respond_to?(:keys) && !value.empty? ) || ( value.kind_of?(Array) && value.size > 1 ))
|
75
|
+
((value.respond_to?(:keys) && !value.empty? ) || ( value.kind_of?(Array) && (value.size > 1 || should_enumerate?(value.first) )))
|
76
76
|
end
|
77
77
|
|
78
78
|
def indent_line(string, indent)
|
@@ -90,7 +90,7 @@ class Chef
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def stringify_value(data)
|
93
|
-
data.kind_of?(String) ? data : data.
|
93
|
+
data.kind_of?(String) ? data : data.to_s
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
data/lib/chef/knife/core/ui.rb
CHANGED
data/lib/chef/knife/search.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
|
+
require 'chef/knife/core/node_presenter'
|
20
21
|
|
21
22
|
class Chef
|
22
23
|
class Knife
|
@@ -24,7 +25,6 @@ class Chef
|
|
24
25
|
|
25
26
|
deps do
|
26
27
|
require 'chef/search/query'
|
27
|
-
require 'chef/knife/core/node_presenter'
|
28
28
|
end
|
29
29
|
|
30
30
|
include Knife::Core::NodeFormattingOptions
|
data/lib/chef/knife/ssh.rb
CHANGED
data/lib/chef/mixin/shell_out.rb
CHANGED
@@ -24,8 +24,8 @@ class Chef
|
|
24
24
|
|
25
25
|
def shell_out(*command_args)
|
26
26
|
cmd = Chef::ShellOut.new(*command_args)
|
27
|
-
if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.
|
28
|
-
cmd.live_stream
|
27
|
+
if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.debug?
|
28
|
+
cmd.live_stream = STDOUT
|
29
29
|
end
|
30
30
|
cmd.run_command
|
31
31
|
cmd
|
data/lib/chef/node.rb
CHANGED
@@ -447,10 +447,13 @@ class Chef
|
|
447
447
|
# Apply the default and overrides attributes from the expansion
|
448
448
|
# passed in, which came from roles.
|
449
449
|
def apply_expansion_attributes(expansion)
|
450
|
-
|
451
|
-
|
450
|
+
load_chef_environment_object = (chef_environment == "_default" ? nil : Chef::Environment.load(chef_environment))
|
451
|
+
environment_default_attrs = load_chef_environment_object.nil? ? {} : load_chef_environment_object.default_attributes
|
452
|
+
default_before_roles = Chef::Mixin::DeepMerge.merge(default_attrs, environment_default_attrs)
|
453
|
+
@default_attrs = Chef::Mixin::DeepMerge.merge(default_before_roles, expansion.default_attrs)
|
454
|
+
environment_override_attrs = load_chef_environment_object.nil? ? {} : load_chef_environment_object.override_attributes
|
452
455
|
overrides_before_environments = Chef::Mixin::DeepMerge.merge(override_attrs, expansion.override_attrs)
|
453
|
-
@override_attrs = Chef::Mixin::DeepMerge.merge(overrides_before_environments,
|
456
|
+
@override_attrs = Chef::Mixin::DeepMerge.merge(overrides_before_environments, environment_override_attrs)
|
454
457
|
end
|
455
458
|
|
456
459
|
# Transform the node to a Hash
|
@@ -647,7 +650,7 @@ class Chef
|
|
647
650
|
def load_attributes
|
648
651
|
cookbook_collection.values.each do |cookbook|
|
649
652
|
cookbook.segment_filenames(:attributes).each do |segment_filename|
|
650
|
-
Chef::Log.debug("
|
653
|
+
Chef::Log.debug("Node #{name} loading cookbook #{cookbook.name}'s attribute file #{segment_filename}")
|
651
654
|
self.from_file(segment_filename)
|
652
655
|
end
|
653
656
|
end
|
@@ -31,18 +31,18 @@ class Chef
|
|
31
31
|
@current_resource
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
34
|
def action_create
|
36
35
|
assert_enclosing_directory_exists!
|
37
36
|
if file_cache_location && content_stale?
|
38
|
-
Chef::Log.debug("
|
37
|
+
Chef::Log.debug("#{@new_resource} has new contents")
|
39
38
|
backup_new_resource
|
40
39
|
Tempfile.open(::File.basename(@new_resource.name)) do |staging_file|
|
41
|
-
Chef::Log.debug("staging #{file_cache_location} to #{staging_file.path}")
|
40
|
+
Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{staging_file.path}")
|
42
41
|
staging_file.close
|
43
42
|
stage_file_to_tmpdir(staging_file.path)
|
44
43
|
FileUtils.mv(staging_file.path, @new_resource.path)
|
45
44
|
end
|
45
|
+
Chef::Log.info("#{@new_resource} created file #{@new_resource.path}")
|
46
46
|
@new_resource.updated_by_last_action(true)
|
47
47
|
else
|
48
48
|
set_all_access_controls(@new_resource.path)
|
@@ -52,7 +52,7 @@ class Chef
|
|
52
52
|
|
53
53
|
def action_create_if_missing
|
54
54
|
if ::File.exists?(@new_resource.path)
|
55
|
-
Chef::Log.debug("
|
55
|
+
Chef::Log.debug("#{@new_resource} exists at #{@new_resource.path} taking no action.")
|
56
56
|
else
|
57
57
|
action_create
|
58
58
|
end
|
@@ -87,7 +87,6 @@ class Chef
|
|
87
87
|
|
88
88
|
def backup_new_resource
|
89
89
|
if ::File.exists?(@new_resource.path)
|
90
|
-
Chef::Log.info "Backing up current file at #{@new_resource.path}"
|
91
90
|
backup @new_resource.path
|
92
91
|
end
|
93
92
|
end
|
data/lib/chef/provider/cron.rb
CHANGED
@@ -132,7 +132,7 @@ class Chef
|
|
132
132
|
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
133
133
|
crontab.each_line { |line| stdin.puts "#{line}" }
|
134
134
|
end
|
135
|
-
Chef::Log.info("
|
135
|
+
Chef::Log.info("#{@new_resource} updated crontab entry")
|
136
136
|
@new_resource.updated_by_last_action(true)
|
137
137
|
else
|
138
138
|
unless @cron_empty
|
@@ -146,7 +146,7 @@ class Chef
|
|
146
146
|
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
147
147
|
crontab.each_line { |line| stdin.puts "#{line}" }
|
148
148
|
end
|
149
|
-
Chef::Log.info("
|
149
|
+
Chef::Log.info("#{@new_resource} added crontab entry")
|
150
150
|
@new_resource.updated_by_last_action(true)
|
151
151
|
end
|
152
152
|
end
|
@@ -176,7 +176,7 @@ class Chef
|
|
176
176
|
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
|
177
177
|
crontab.each_line { |line| stdin.puts "#{line}" }
|
178
178
|
end
|
179
|
-
Chef::Log.
|
179
|
+
Chef::Log.info("#{@new_resource} deleted crontab entry")
|
180
180
|
@new_resource.updated_by_last_action(true)
|
181
181
|
end
|
182
182
|
end
|
@@ -51,7 +51,7 @@ class Chef
|
|
51
51
|
crontab_lines.each do |line|
|
52
52
|
case line.chomp
|
53
53
|
when "# Chef Name: #{@new_resource.name}"
|
54
|
-
Chef::Log.debug("
|
54
|
+
Chef::Log.debug("#{@new_resource} found cron '#{@new_resource.name}'")
|
55
55
|
cron_found = true
|
56
56
|
@cron_exists = true
|
57
57
|
next
|
@@ -82,9 +82,9 @@ class Chef
|
|
82
82
|
next
|
83
83
|
end
|
84
84
|
end
|
85
|
-
Chef::Log.debug("
|
85
|
+
Chef::Log.debug("#{@new_resource} cron '#{@new_resource.name}' not found") unless @cron_exists
|
86
86
|
elsif status.exitstatus == 1
|
87
|
-
Chef::Log.debug("
|
87
|
+
Chef::Log.debug("#{@new_resource} cron empty for '#{@new_resource.user}'")
|
88
88
|
@cron_empty = true
|
89
89
|
end
|
90
90
|
|
@@ -125,7 +125,7 @@ class Chef
|
|
125
125
|
|
126
126
|
if @cron_exists
|
127
127
|
unless compare_cron
|
128
|
-
Chef::Log.debug("
|
128
|
+
Chef::Log.debug("#{@new_resource} skipping existing cron entry '#{@new_resource.name}'")
|
129
129
|
return
|
130
130
|
end
|
131
131
|
status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
@@ -148,7 +148,7 @@ class Chef
|
|
148
148
|
end
|
149
149
|
|
150
150
|
status = write_crontab(crontab)
|
151
|
-
Chef::Log.info("
|
151
|
+
Chef::Log.info("#{@new_resource} updated crontab entry")
|
152
152
|
else
|
153
153
|
unless @cron_empty
|
154
154
|
status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
|
@@ -158,7 +158,7 @@ class Chef
|
|
158
158
|
|
159
159
|
crontab << newcron
|
160
160
|
status = write_crontab(crontab)
|
161
|
-
Chef::Log.info("
|
161
|
+
Chef::Log.info("#{@new_resource} added crontab entry")
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -185,7 +185,7 @@ class Chef
|
|
185
185
|
end
|
186
186
|
|
187
187
|
status = write_crontab(crontab)
|
188
|
-
Chef::Log.info("
|
188
|
+
Chef::Log.info("#{@new_resource} deleted crontab entry")
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
data/lib/chef/provider/deploy.rb
CHANGED
@@ -61,9 +61,8 @@ class Chef
|
|
61
61
|
def action_deploy
|
62
62
|
if all_releases.include?(release_path)
|
63
63
|
if all_releases[-1] == release_path
|
64
|
-
Chef::Log.debug("
|
64
|
+
Chef::Log.debug("#{@new_resource} is the latest version")
|
65
65
|
else
|
66
|
-
Chef::Log.info("Already deployed app at #{release_path}. Rolling back to it - use action :force_deploy to re-checkout this revision.")
|
67
66
|
action_rollback
|
68
67
|
end
|
69
68
|
else
|
@@ -74,8 +73,8 @@ class Chef
|
|
74
73
|
|
75
74
|
def action_force_deploy
|
76
75
|
if all_releases.include?(release_path)
|
77
|
-
Chef::Log.info("Already deployed app at #{release_path}, forcing.")
|
78
76
|
FileUtils.rm_rf(release_path)
|
77
|
+
Chef::Log.info("#{@new_resource} forcing deploy of already deployed app at #{release_path}")
|
79
78
|
end
|
80
79
|
deploy
|
81
80
|
@new_resource.updated_by_last_action(true)
|
@@ -93,12 +92,12 @@ class Chef
|
|
93
92
|
releases_to_nuke = [ all_releases.last ]
|
94
93
|
end
|
95
94
|
|
96
|
-
Chef::Log.info "rolling back to previous release
|
95
|
+
Chef::Log.info "#{@new_resource} rolling back to previous release #{release_path}"
|
97
96
|
symlink
|
98
|
-
Chef::Log.info "restarting with previous release"
|
97
|
+
Chef::Log.info "#{@new_resource} restarting with previous release"
|
99
98
|
restart
|
100
99
|
releases_to_nuke.each do |i|
|
101
|
-
Chef::Log.info "
|
100
|
+
Chef::Log.info "#{@new_resource} removing release: #{i}"
|
102
101
|
FileUtils.rm_rf i
|
103
102
|
release_deleted(i)
|
104
103
|
end
|
@@ -106,7 +105,6 @@ class Chef
|
|
106
105
|
end
|
107
106
|
|
108
107
|
def deploy
|
109
|
-
Chef::Log.info "deploying branch: #{@new_resource.branch}"
|
110
108
|
enforce_ownership
|
111
109
|
update_cached_repo
|
112
110
|
copy_cached_repo
|
@@ -120,13 +118,14 @@ class Chef
|
|
120
118
|
restart
|
121
119
|
callback(:after_restart, @new_resource.after_restart)
|
122
120
|
cleanup!
|
121
|
+
Chef::Log.info "#{@new_resource} deployed to #{@new_resource.deploy_to}"
|
123
122
|
end
|
124
123
|
|
125
124
|
def callback(what, callback_code=nil)
|
126
125
|
@collection = Chef::ResourceCollection.new
|
127
126
|
case callback_code
|
128
127
|
when Proc
|
129
|
-
Chef::Log.info "
|
128
|
+
Chef::Log.info "#{@new_resource} running callback #{what}"
|
130
129
|
recipe_eval(&callback_code)
|
131
130
|
when String
|
132
131
|
callback_file = "#{release_path}/#{callback_code}"
|
@@ -152,26 +151,25 @@ class Chef
|
|
152
151
|
"#{key_and_val.first}='#{key_and_val.last}'"
|
153
152
|
end.join(" ")
|
154
153
|
|
155
|
-
Chef::Log.info
|
156
|
-
|
157
|
-
run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path))
|
154
|
+
Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
|
155
|
+
run_command(run_options(:command => @new_resource.migration_command, :cwd=>release_path, :command_log_level => :info))
|
158
156
|
end
|
159
157
|
end
|
160
158
|
|
161
159
|
def symlink
|
162
|
-
Chef::Log.info "Symlinking"
|
163
160
|
purge_tempfiles_from_current_release
|
164
161
|
link_tempfiles_to_current_release
|
165
162
|
link_current_release_to_production
|
163
|
+
Chef::Log.info "#{@new_resource} updated symlinks"
|
166
164
|
end
|
167
165
|
|
168
166
|
def restart
|
169
167
|
if restart_cmd = @new_resource.restart_command
|
170
168
|
if restart_cmd.kind_of?(Proc)
|
171
|
-
Chef::Log.info("
|
169
|
+
Chef::Log.info("#{@new_resource} restarting app with embedded recipe")
|
172
170
|
recipe_eval(&restart_cmd)
|
173
171
|
else
|
174
|
-
Chef::Log.info("
|
172
|
+
Chef::Log.info("#{@new_resource} restarting app")
|
175
173
|
run_command(run_options(:command => @new_resource.restart_command, :cwd => @new_resource.current_path))
|
176
174
|
end
|
177
175
|
end
|
@@ -179,7 +177,7 @@ class Chef
|
|
179
177
|
|
180
178
|
def cleanup!
|
181
179
|
all_releases[0..-6].each do |old_release|
|
182
|
-
Chef::Log.info "
|
180
|
+
Chef::Log.info "#{@new_resource} removing old release #{old_release}"
|
183
181
|
FileUtils.rm_rf(old_release)
|
184
182
|
release_deleted(old_release)
|
185
183
|
end
|
@@ -199,52 +197,70 @@ class Chef
|
|
199
197
|
end
|
200
198
|
|
201
199
|
def run_scm_sync
|
202
|
-
Chef::Log.info "updating the cached checkout"
|
203
200
|
@scm_provider.action_sync
|
204
201
|
end
|
205
202
|
|
206
203
|
def svn_force_export
|
207
|
-
Chef::Log.info "exporting source repository
|
204
|
+
Chef::Log.info "#{@new_resource} exporting source repository"
|
208
205
|
@scm_provider.action_force_export
|
209
206
|
end
|
210
207
|
|
211
208
|
def copy_cached_repo
|
212
|
-
Chef::Log.info "copying the cached checkout to #{release_path}"
|
213
209
|
FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
|
214
210
|
run_command(:command => "cp -RPp #{::File.join(@new_resource.destination, ".")} #{release_path}")
|
211
|
+
Chef::Log.info "#{@new_resource} copied the cached checkout to #{release_path}"
|
215
212
|
release_created(release_path)
|
216
213
|
end
|
217
214
|
|
218
215
|
def enforce_ownership
|
219
|
-
Chef::Log.info "ensuring proper ownership"
|
220
216
|
FileUtils.chown_R(@new_resource.user, @new_resource.group, @new_resource.deploy_to)
|
217
|
+
Chef::Log.info("#{@new_resource} set user to #{@new_resource.user}") if @new_resource.user
|
218
|
+
Chef::Log.info("#{@new_resource} set group to #{@new_resource.group}") if @new_resource.group
|
221
219
|
end
|
222
220
|
|
223
221
|
def link_current_release_to_production
|
224
|
-
Chef::Log.info "Linking release #{release_path} into production at #{@new_resource.current_path}"
|
225
222
|
FileUtils.rm_f(@new_resource.current_path)
|
226
|
-
|
223
|
+
begin
|
224
|
+
FileUtils.ln_sf(release_path, @new_resource.current_path)
|
225
|
+
rescue => e
|
226
|
+
raise Chef::Exceptions::FileNotFound.new("Cannot symlink current release to production: #{e.message}")
|
227
|
+
end
|
228
|
+
Chef::Log.info "#{@new_resource} linked release #{release_path} into production at #{@new_resource.current_path}"
|
227
229
|
enforce_ownership
|
228
230
|
end
|
229
231
|
|
230
232
|
def run_symlinks_before_migrate
|
231
233
|
links_info = @new_resource.symlink_before_migrate.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
232
|
-
Chef::Log.info "Making pre-migration symlinks: #{links_info}"
|
233
234
|
@new_resource.symlink_before_migrate.each do |src, dest|
|
234
|
-
|
235
|
+
begin
|
236
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
237
|
+
rescue => e
|
238
|
+
raise Chef::Exceptions::FileNotFound.new("Cannot symlink #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest} before migrate: #{e.message}")
|
239
|
+
end
|
235
240
|
end
|
241
|
+
Chef::Log.info "#{@new_resource} made pre-migration symlinks"
|
236
242
|
end
|
237
243
|
|
238
244
|
def link_tempfiles_to_current_release
|
239
245
|
dirs_info = @new_resource.create_dirs_before_symlink.join(",")
|
240
|
-
|
241
|
-
|
246
|
+
@new_resource.create_dirs_before_symlink.each do |dir|
|
247
|
+
begin
|
248
|
+
FileUtils.mkdir_p(release_path + "/#{dir}")
|
249
|
+
rescue => e
|
250
|
+
raise Chef::Exceptions::FileNotFound.new("Cannot create directory #{dir}: #{e.message}")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
Chef::Log.info("#{@new_resource} created directories before symlinking #{dirs_info}")
|
242
254
|
|
243
255
|
links_info = @new_resource.symlinks.map { |src, dst| "#{src} => #{dst}" }.join(", ")
|
244
|
-
Chef::Log.info("Linking shared paths into current release: #{links_info}")
|
245
256
|
@new_resource.symlinks.each do |src, dest|
|
246
|
-
|
257
|
+
begin
|
258
|
+
FileUtils.ln_sf(@new_resource.shared_path + "/#{src}", release_path + "/#{dest}")
|
259
|
+
rescue => e
|
260
|
+
raise Chef::Exceptions::FileNotFound.new("Cannot symlink shared data #{@new_resource.shared_path}/#{src} to #{release_path}/#{dest}: #{e.message}")
|
261
|
+
end
|
247
262
|
end
|
263
|
+
Chef::Log.info("#{@new_resource} linked shared paths into current release: #{links_info}")
|
248
264
|
run_symlinks_before_migrate
|
249
265
|
enforce_ownership
|
250
266
|
end
|
@@ -254,8 +270,8 @@ class Chef
|
|
254
270
|
|
255
271
|
def purge_tempfiles_from_current_release
|
256
272
|
log_info = @new_resource.purge_before_symlink.join(", ")
|
257
|
-
Chef::Log.info("Purging directories in checkout #{log_info}")
|
258
273
|
@new_resource.purge_before_symlink.each { |dir| FileUtils.rm_rf(release_path + "/#{dir}") }
|
274
|
+
Chef::Log.info("#{@new_resource} purged directories in checkout #{log_info}")
|
259
275
|
end
|
260
276
|
|
261
277
|
protected
|
@@ -303,13 +319,20 @@ class Chef
|
|
303
319
|
run_opts[:user] = @new_resource.user if @new_resource.user
|
304
320
|
run_opts[:group] = @new_resource.group if @new_resource.group
|
305
321
|
run_opts[:environment] = @new_resource.environment if @new_resource.environment
|
322
|
+
run_opts[:command_log_prepend] = @new_resource.to_s
|
323
|
+
run_opts[:command_log_level] ||= :debug
|
324
|
+
if run_opts[:command_log_level] == :info
|
325
|
+
if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
|
326
|
+
run_opts[:live_stream] = STDOUT
|
327
|
+
end
|
328
|
+
end
|
306
329
|
run_opts
|
307
330
|
end
|
308
331
|
|
309
332
|
def run_callback_from_file(callback_file)
|
310
333
|
if ::File.exist?(callback_file)
|
311
334
|
Dir.chdir(release_path) do
|
312
|
-
Chef::Log.info "running deploy hook
|
335
|
+
Chef::Log.info "#{@new_resource} running deploy hook #{callback_file}"
|
313
336
|
recipe_eval { from_file(callback_file) }
|
314
337
|
end
|
315
338
|
end
|