How would I reference the current server in a Capistrano task? I want to curl
a local file to clear the APC cache but the server does not listen on localhost
so I need the server's IP address.
我如何在Capistrano任务中引用当前服务器?我想卷曲本地文件以清除APC缓存但服务器不监听localhost所以我需要服务器的IP地址。
For instance,
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
What variable would I use so that when the task is run on 1.1.1.1 it curl
s http://1.1.1.1/deploy/clearAPC.php
but when run on 2.2.2.2 it calls curl
s http://2.2.2.2/deploy/clearAPC.php
我将使用什么变量,以便当任务在1.1.1.1上运行时,它会卷曲http://1.1.1.1/deploy/clearAPC.php但是当在2.2.2.2上运行它会调用curls http://2.2.2.2/deploy /clearAPC.php
5 个解决方案
#1
11
There's the magical $CAPISTRANO:HOST$
有神奇的$ CAPISTRANO:HOST $
run "curl http://$CAPISTRANO:HOST$/deploy/clearAPC.php"
should do exactly what you want.
应该做你想要的。
note: don't use it as a variable via string interpolation, capistrano will just replace the $CAPISTRANO:HOST$ in the string itself.
注意:不要通过字符串插值将它用作变量,capistrano只会替换字符串本身中的$ CAPISTRANO:HOST $。
That's a very weird and (afaik) undocumented feature :-)
这是一个非常奇怪和(afaik)无证的功能:-)
#2
28
In Capistrano, tasks don't get executed once for each server, run executes your command on each server. Here is what you should do instead:
在Capistrano中,每个服务器都不会执行一次任务,run会在每个服务器上执行命令。这是你应该做的事情:
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
The accepted answer will work, but this one lets you access the servers as variables/methods
接受的答案将起作用,但是这个可以让您作为变量/方法访问服务器
#3
3
current_host = capture("echo $CAPISTRANO:HOST$").strip
#4
0
I wanted to know the current server I was deploying to, so that I could send a message to campfire. This is what I was able to figure out, though I'm sure there is a better way
我想知道我正在部署的当前服务器,以便我可以向campfire发送消息。这是我能够弄清楚的,虽然我确信有更好的方法
actions = current_task.namespace.parent.logger.instance_variable_get('@options')[:actions]
message = "I am deploying #{fetch(:latest_release).split('/').last} using cap #{actions.join(' ')}"
so when I deploy it posts this to campfire I am deploying 20121206154442 using cap QA2 campfire:notify deploy deploy:flex_master
因此,当我部署它时将其发布到篝火我使用cap QA2 campfire部署20121206154442:notify deploy deploy:flex_master
#5
0
capistrano (2.13.5) required
需要capistrano(2.13.5)
puts current_task.namespace.logger.instance_variable_get('@base_logger').instance_variable_get('@options')[:actions].join(' ')
figured this out by
想通了
puts current_task.namespace.logger.inspect
#1
11
There's the magical $CAPISTRANO:HOST$
有神奇的$ CAPISTRANO:HOST $
run "curl http://$CAPISTRANO:HOST$/deploy/clearAPC.php"
should do exactly what you want.
应该做你想要的。
note: don't use it as a variable via string interpolation, capistrano will just replace the $CAPISTRANO:HOST$ in the string itself.
注意:不要通过字符串插值将它用作变量,capistrano只会替换字符串本身中的$ CAPISTRANO:HOST $。
That's a very weird and (afaik) undocumented feature :-)
这是一个非常奇怪和(afaik)无证的功能:-)
#2
28
In Capistrano, tasks don't get executed once for each server, run executes your command on each server. Here is what you should do instead:
在Capistrano中,每个服务器都不会执行一次任务,run会在每个服务器上执行命令。这是你应该做的事情:
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
The accepted answer will work, but this one lets you access the servers as variables/methods
接受的答案将起作用,但是这个可以让您作为变量/方法访问服务器
#3
3
current_host = capture("echo $CAPISTRANO:HOST$").strip
#4
0
I wanted to know the current server I was deploying to, so that I could send a message to campfire. This is what I was able to figure out, though I'm sure there is a better way
我想知道我正在部署的当前服务器,以便我可以向campfire发送消息。这是我能够弄清楚的,虽然我确信有更好的方法
actions = current_task.namespace.parent.logger.instance_variable_get('@options')[:actions]
message = "I am deploying #{fetch(:latest_release).split('/').last} using cap #{actions.join(' ')}"
so when I deploy it posts this to campfire I am deploying 20121206154442 using cap QA2 campfire:notify deploy deploy:flex_master
因此,当我部署它时将其发布到篝火我使用cap QA2 campfire部署20121206154442:notify deploy deploy:flex_master
#5
0
capistrano (2.13.5) required
需要capistrano(2.13.5)
puts current_task.namespace.logger.instance_variable_get('@base_logger').instance_variable_get('@options')[:actions].join(' ')
figured this out by
想通了
puts current_task.namespace.logger.inspect