我有一个用于多阶段部署的Capfile,它需要将代码部署到一个服务器(NFS),最后重新启动几个应用程序服务器。因此,由于deploy:update_code不需要使用应用程序服务器,因此不能轻松地使用角色。我已经想出了一些可能可行的东西,但有一个问题需要解决。
application_servers = nil
task :production do
role :nfs, "nfs.someserver.net"
application_servers = "app.someserver.net"
end
task :staging do
role :nfs, "nfs-staging.someserver.net"
application_servers = "app-staging.someserver.net"
end
desc "tail resin logs #{resin_logs}"
task :tail, :hosts => application_servers do
puts("Server is:"#{application_servers})
stream "tail -f #{resin_logs}"
end并且在运行时:
#$ cap staging tail
* executing `staging'
* executing `tail'
Server is:app-staging.someserver.net
* executing "tail -f /log/resin/*.log"
servers: ["nfs-staging.someserver.net"]
[nfs-staging.someserver.net] executing command
tail: cannot open `/log/resin/*.log' for reading: No such file or directory
tail: no files remaining
command finished
failed: "sh -c 'tail -f /log/resin/*.log'" on nfs-staging.someserver.net当打印任务尾部的application_servers值时,它显示为"app-staging.someserver.net",但在:hosts => application_servers中使用的值为空(这就是为什么它使用角色nfs )。
为什么变量application_server有两个不同的值?是作用域问题吗?我尝试过使用global ($),但它不能很好地工作。
发布于 2010-11-11 01:19:22
通过在特定于应用程序的任务上从使用:hosts更改为:roles并添加新角色,解决了此问题。关键特性是使用no_release,这样代码就不会被部署到应用服务器上。我们只想在这些机器上重新启动树脂实例。
task :production do
role :nfs, "nfs.someserver.net"
role :application, "app.someserver.net", :no_release => true;
end
task :staging do
role :nfs, "nfs-staging.someserver.net"
role :application, "app-staging.someserver.net", :no_release => true;
end
desc "tail resin logs #{resin_logs}"
task :tail, :roles => application_servers do
puts("Server is:"#{application_servers})
stream "tail -f #{resin_logs}"
endhttps://stackoverflow.com/questions/4144811
复制相似问题