在Capistrano任务中引用当前服务器

问题描述 投票:7回答:6

我如何在Capistrano任务中引用当前服务器?我想curl一个本地文件来清除APC缓存,但是服务器不监听localhost,所以我需要服务器的IP地址。

例如,

role :web, "1.1.1.1", "2.2.2.2", "3.3.3.3"

task :clear_apc, :role => :web do
    run "curl http://#{WHAT_DO_I_PUT_HERE}/deploy/clearAPC.php"
end

我将使用什么变量,以便当任务在1.1.1.1上运行时,它会curl s http://1.1.1.1/deploy/clearAPC.php,但是在2.2.2.2上运行时,它将调用curl s http://2.2.2.2/deploy/clearAPC.php

php ruby deployment capistrano apc
6个回答
11
投票
run "curl http://$CAPISTRANO:HOST$/deploy/clearAPC.php"

应该完全按照自己的意愿做。

注意:请勿通过字符串插值将其用作变量,capistrano只会替换字符串本身中的$ CAPISTRANO:HOST $。

这是一个非常奇怪且(afaik)未记录的功能:-)


28
投票
task :clear_apc, :role => :web do find_servers_for_task(current_task).each do |current_server| run "curl http://#{current_server.host}/deploy/clearAPC.php", :hosts => current_server.host end end

接受的答案将起作用,但是该答案使您可以作为变量/方法访问服务器


3
投票

0
投票
actions = current_task.namespace.parent.logger.instance_variable_get('@options')[:actions] message = "I am deploying #{fetch(:latest_release).split('/').last} using cap #{actions.join(' ')}"

所以当我部署它时,将其发布到篝火我正在使用上限QA2 campfire部署20121206154442:通知部署deploy:flex_master


0
投票
puts current_task.namespace.logger.instance_variable_get('@base_logger').instance_variable_get('@options')[:actions].join(' ')

由]弄清楚了>

puts current_task.namespace.logger.inspect

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.