Date: 2011-06-03 05:38
Sender: s b
See the following example which, replicates the race condition
invoking remote rake tasks with multiple hosts. Similar to the
update task in in core.rb.
Using vlad (2.2.0)
-- deploy.rb --
role :app, [ "host1", "host2" ]
set :file, "/tmp/foo.txt"
def touch_file
run "echo touching file #{file} on `hostname`"
run "if [ `hostname` = \"host2\" ]; then sleep
10; fi"
run "touch #{file}"
run "echo touched file #{file} on on `hostname`"
end
def test_file
run "echo testing file #{file} on `hostname`"
run "if [ ! -e #{file} ]; then exit 1; fi"
run "echo file #{file} exists on `hostname`"
end
namespace :remote_deps do
task :default => :test_file
remote_task :touch_file, {:needs => :clean}, :roles =>
:app do
touch_file
end
remote_task :test_file, {:needs => :touch_file}, :roles
=> :app do
test_file
end
end
namespace :remote_invoke do
task :default => :touch_file
remote_task :touch_file, {:needs => :clean}, :roles =>
:app do
touch_file
Rake::Task['remote_invoke:test_file'].invoke
end
remote_task :test_file, :roles => :app do
test_file
end
end
remote_task :clean, :roles => :app do
run "rm -f /tmp/foo.txt"
end
-- end deploy.rb --
Running 'remote_invoke:default' results in an error:
$ rake remote_invoke:default
touching file /tmp/foo.txt on host1
touching file /tmp/foo.txt on host2
touched file /tmp/foo.txt on on host1
testing file /tmp/foo.txt on host2
testing file /tmp/foo.txt on host1
file /tmp/foo.txt exists on host1
touched file /tmp/foo.txt on on host2
rake aborted!
execution failed with status 1: ssh host2.local if [ ! -e
/tmp/foo.txt ]; then exit 1; fi
--
If we use remote task dependencies over remote task invocation
the deployment runs successfully:
$ rake remote_deps:default
touching file /tmp/foo.txt on host1
touching file /tmp/foo.txt on host2
touched file /tmp/foo.txt on on host1
touched file /tmp/foo.txt on on host2
testing file /tmp/foo.txt on host1
testing file /tmp/foo.txt on host2
file /tmp/foo.txt exists on host2
file /tmp/foo.txt exists on host1
|