Capistrano 任务未在给定范围内执行。

发布于 2025-01-02 19:57:39 字数 509 浏览 1 评论 0原文

我已经构建了一些需要在定义的 :app 角色中运行的 capistrano 任务。这是我到目前为止所拥有的:

desc "Stop unicorn"
task :stop, :roles => :app do
  logger.info "Stopping unicorn server(s).."
  run "touch #{unicorn_pid}"
  pid = capture("cat #{unicorn_pid}").to_i
  run "kill -s QUIT #{pid}" if pid > 0
end

据我所知,这应该在 :app 角色中给定的服务器上运行给定的命令,对吧?但事实是它以 :db 角色在服务器上运行命令。

任何人都可以深入了解这个问题吗?或者有没有办法强制 Capistrano 遵守 :roles 标志?

提前致谢

//埃米尔

I have build some capistrano tasks which I need to run on within the defined :app roles. This is what I have so far:

desc "Stop unicorn"
task :stop, :roles => :app do
  logger.info "Stopping unicorn server(s).."
  run "touch #{unicorn_pid}"
  pid = capture("cat #{unicorn_pid}").to_i
  run "kill -s QUIT #{pid}" if pid > 0
end

As far as I know, this should run the given commands on the servers given in the :app role, right? But the fact of the matter is that it's running the commands on the servers in the :db role.

Can anyone give some insight into this problem? Or is there a way to force Capistrano to adhere to the :roles flag?

Thanks in advance

// Emil

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

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

发布评论

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

评论(1

遗弃M 2025-01-09 19:57:39

使用 Capture 将导致任务仅在列出的第一台服务器上运行。

从文档中:

捕获助手将在第一个匹配的服务器上执行给定的命令,并将命令的输出作为字符串返回。

https://github.com/capistrano/capistrano/wiki /2.x-DSL-Action-Inspection-Capture

不幸的是,我面临着类似的问题,find_servers解决方案可能有效,但它很hacky,并且运行N x N次,其中N在您拥有的服务器数量。

Using Capture will cause the task to be run only on the first server listed.

From the documentation:

The capture helper will execute the given command on the first matching server, and will return the output of the command as a string.

https://github.com/capistrano/capistrano/wiki/2.x-DSL-Action-Inspection-Capture

Unfortunately I am facing a similar issue, the find_servers solution may work, but it's hacky, and runs N x N times, where N in the number of servers you have.

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