我有一个用于Multistage部署的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($),但这种方式也不行。
答案 0 :(得分:0)
只需将使用:hosts更改为:特定于应用程序的任务上的角色并添加新角色即可解决问题。关键特性是使用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}"
end