首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >问题:主机

问题:主机
EN

Stack Overflow用户
提问于 2010-11-10 21:14:21
回答 1查看 58关注 0票数 0

我有一个用于多阶段部署的Capfile,它需要将代码部署到一个服务器(NFS),最后重新启动几个应用程序服务器。因此,由于deploy:update_code不需要使用应用程序服务器,因此不能轻松地使用角色。我已经想出了一些可能可行的东西,但有一个问题需要解决。

代码语言:javascript
复制
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

并且在运行时:

代码语言:javascript
复制
#$ 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 ($),但它不能很好地工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-11 01:19:22

通过在特定于应用程序的任务上从使用:hosts更改为:roles并添加新角色,解决了此问题。关键特性是使用no_release,这样代码就不会被部署到应用服务器上。我们只想在这些机器上重新启动树脂实例。

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4144811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档