Ruby 问题:主机
我有一个用于多级部署的Capfile,它需要将代码部署到一个服务器(NFS),最后重新启动几个应用程序服务器。由于部署:更新\u代码不需要使用应用程序服务器,因此无法轻松使用角色。我想出了一些可能有效的办法,但有一个问题需要解决Ruby 问题:主机,ruby,capistrano,Ruby,Capistrano,我有一个用于多级部署的Capfile,它需要将代码部署到一个服务器(NFS),最后重新启动几个应用程序服务器。由于部署:更新\u代码不需要使用应用程序服务器,因此无法轻松使用角色。我想出了一些可能有效的办法,但有一个问题需要解决 application_servers = nil task :production do role :nfs, "nfs.someserver.net" application_servers = "app.someserver.net" end ta
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
在task tail中打印应用程序_服务器的值时,会显示“app staging.someserver.net”,但在:hosts=>application_服务器中使用的值为空(这就是为什么它使用角色nfs)
为什么变量应用程序服务器有两个不同的值?是范围问题吗?我尝试过使用全局($),但效果不太好。仅通过在特定于应用程序的任务中从使用:主机更改为:角色,并添加了一个新角色,就解决了此问题。关键特性是使用no_版本,这样代码就不会部署到应用服务器。我们只想在这些机器上重新启动树脂实例
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}"
end