Capistrano 多服务器:如何在部署过程中引用当前服务器?

发布于 2025-01-05 01:16:48 字数 726 浏览 1 评论 0原文

一些背景知识,我运行的是 capistrino 2.9.0 和 capistrano-ext 1.2.1。多阶段部署正在按预期工作。与将服务器阵列添加到角色一样。

INSTANCES = ["this.server.com", "that.server.com"]
role(:web) {INSTANCES}  

我一直在尝试使 :deploy_to 根据正在部署的服务器的名称生成一个路径,如下所示:

set :deploy_to, lambda { "/var/www/application/$HOSTNAME" }

这工作得很好,除了 this.server.com 和 that.server.com 实际上是同一主机。在此示例中,它没有根据我的deploy/stage.rb 文件中定义的服务器名称创建两个部署文件夹,而是仅生成一个 /var/www/application/server.com/

我一直在寻找一个 /var/www/application/server.com/方法可以在 capistrano 级别注入它或引用将保留这些详细信息的 shell 变量。似乎需要托管具有应用程序的多个实例的应用程序服务器是很常见的。

我真正需要的是:

set :deploy_to, lambda { "/var/www/application/$SERVER_NAME_CAP_IS_USING" }

Some background, I am capistrino running 2.9.0 and capistrano-ext 1.2.1. Multistage deployment is working as expected. As is adding arrays of server to the roles.

INSTANCES = ["this.server.com", "that.server.com"]
role(:web) {INSTANCES}  

I've been trying to make :deploy_to produced a path based on the name of the server being deployed, like so:

set :deploy_to, lambda { "/var/www/application/$HOSTNAME" }

This is working pretty well, except this.server.com and that.server.com are actually the same host. In this example, instead of having two deploy folders based off the server names defined in my deploy/stage.rb file, it just produces the one /var/www/application/server.com/

I've been digging around looking for a way to either inject this at the capistrano level or reference a shell variable that would retain these details. It seems like needing to host an application server with multiple instances of an app would be common.

What I really need is:

set :deploy_to, lambda { "/var/www/application/$SERVER_NAME_CAP_IS_USING" }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

银河中√捞星星 2025-01-12 01:16:48

也许有帮助。您可以定义特定的 ServerDefinition 对象并根据任务或其他方式调用这些对象:

set(:boss_host, {
  Capistrano::ServerDefinition.new('boss.reservoir.dogs', {
    :user => 'boss',
    :port => 2222,
    :ssh_options => {
      :keys => './keys/boss.pem'
    }
})

run("date", :hosts => [ :boss_host ]

Maybe this helps. You can define specific ServerDefinition objects and call to those per task or whatever:

set(:boss_host, {
  Capistrano::ServerDefinition.new('boss.reservoir.dogs', {
    :user => 'boss',
    :port => 2222,
    :ssh_options => {
      :keys => './keys/boss.pem'
    }
})

run("date", :hosts => [ :boss_host ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文