Alright, a bit of background.
Tasks are not executed serially, for each host. Rather, if a task is
to be run on multiple roles, the task is run exactly _once_, and each
"run" command is then parallelized across each host. In other words,
given the following roles and task:
role :app, "foo.com", "bar.com"
task :something, :roles => :app do
run "echo first $CAPISTRANO:HOST$"
run "echo second $CAPISTRANO:HOST$"
end
If you were to execute "cap something", the following steps would occur.
1. The task 'something' would be located and executed.
2. While 'something' executes, it encounters the first 'run' command.
3. 'run' determines that the servers associated with the current
scope are 'foo.com' and 'bar.com'.
4. 'run' establishes connections to 'foo.com' and 'bar.com'.
5. 'run' passes the command string "echo first $CAPISTRANO:HOST$" to
the command executor, along with the Net::SSH sessions for 'foo.com'
and 'bar.com'.
6. The command executor opens SSH channels on both 'foo.com' and
'bar.com', and sends the command string to each, after substituting
$CAPISTRANO:HOST$ with 'foo.com' and 'bar.com', respectively.
7. The command executor streams the output back to 'run', which
displays it to the console. The output is two lines, "first foo.com"
and "first bar.com".
8. The command terminates, and the task continues.
9. The second 'run' is encountered.
10. 'run' determines that 'foo.com' and 'bar.com' are associated with
the current scope. The connections for those servers are already
established, so the command string "echo second $CAPISTRANO:HOST$" is
sent to the command executor.
11. Just as with step 6, the executor opens SSH channels and sends
the command string to each server, after substituting the
$CAPISTRANO:HOST$ place holder.
12. The output is "second foo.com" and "second bar.com".
13. The command terminates, and the task terminates.
As you can see, therefore, it makes no sense to ask what server a
task is currently being executed for, because it is effectively being
executed for all servers at once.
What you want is to create two mongrel config files, one for each
server you are deploying to, and check those each into config/
mongrel. Name them with the appropriate hostname as part of the
filename (e.g., config/mongrel/foo.com.yml and config/mongrel/bar.com/
yml). Then, when you deploy, you'll have an after_update_code task
that copies the appropriate config to your mongrel_cluster.yml file:
task :copy_correct_mongrel_config do
run "cp #{release_path}/config/mongrel/$CAPISTRANO:HOST$.yml #
{release_path}/config/mongrel_cluster.yml"
end
after "deploy:update_code", :copy_correct_mongrel_config
The above command will execute on each host, copying the mongrel
config for that host to the general config/mongrel_cluster.yml file.
Hope that helps,
Jamis
On Jun 14, 2007, at 5:27 PM, rtec88 wrote:
>
> When deploying to mulitple application servers,
>
> role :app, "192.168.1.1", "192.168.1.2"
>
> Is there a variable accessable to my task that can tell me when I am
> running a task for "192.168.1.1" or "192.168.1.2".
>
> The reason I need this, is to update my mongrel_cluster.yml config
> file. Inside the file it desigates which address to bind to (address:
> 192.168.1.1). When deploying to two application servers, each server
> binds to a seperate address.
>
> I would like to be able to do something like this:
>
> namespace :mongrel do
> task :custom_config, :roles => :app do
> server_address = some_variable_that
> _conatins_"192.168.1.1"_or_"192.168.1.2"
> mongrel_config = render("./deploy/
> mongrel_cluster_template.yml", :address => server_address )
> put mongrel_config, "#{release_path/config/
> mongrel_cluster.yml", :mode => 0777
> end
> end
>
> I have tried using the "$CAPISTRANO:HOST$", but it doesn't seem to
> work like I would expect it to.
>
> Is there such a variable or should I be looking at doing this a
> different way?
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---