ruby-on-rails - 如何配置 capistrano 以在一台服务器上部署 puma 和 nginx 并在另一台服务器上部署 resque?
问题描述
我正在准备 capistrano 将 ruby on rails 应用程序部署到 AWS。应用程序服务器将在 bastian 主机之后。
我有两台服务器 server1 和 server2。我想在 server1 上部署和运行 puma、nginx,并在 server2 上运行 resque worker 和 resque 调度程序。我知道角色,这是我到目前为止的配置:
# deploy/production.rb
web_instances = [web-instance-ip]
worker_instances = [worker-instance-ip]
role :app, web_instances
role :web, web_instances
role :worker, worker_instances
set :deploy_user, ENV['DEPLOY_USER'] || 'ubuntu'
set :branch, 'master'
set :ssh_options, {
forward_agent: true,
keys: ENV['SSH_KEY_PATH'],
proxy: Net::SSH::Proxy::Command.new("ssh -i '#{ENV['SSH_KEY_PATH']}' #{fetch(:deploy_user)}@#{ENV['BASTIAN_PUBLIC_IP']} -W %h:%p"),
}
set :puma_role, :app
我不确定我应该做什么或如何编写任务,方法是确保 puma 启动、重启仅在 server1 上完成,resque、resque 调度程序启动重启等仅在 server2 上处理。虽然在每个实例上都完成了诸如提取最新代码、捆绑安装等常见任务?
解决方案
这可以通过使用role
限制为每个服务器运行的任务和一些挂钩来触发您的自定义任务来实现。您的deploy/production.rb
文件将与此类似。
web_instances = [web-instance-ip]
worker_instances = [worker-instance-ip]
role :app, web_instances
role :web, web_instances
role :worker, worker_instances
set :deploy_user, ENV['DEPLOY_USER'] || 'ubuntu'
set :branch, 'master'
set :ssh_options, {
forward_agent: true,
keys: ENV['SSH_KEY_PATH'],
proxy: Net::SSH::Proxy::Command.new("ssh -i '#{ENV['SSH_KEY_PATH']}' #{fetch(:deploy_user)}@#{ENV['BASTIAN_PUBLIC_IP']} -W %h:%p"),
}
# This will run on server with web role only
namespace :puma do
task :restart do
on roles(:web) do |host|
with rails_env: fetch(:rails_env) do
** Your code to restart puma server **
end
end
end
end
# This will run on server with worker role only
namespace :resque do
task :restart do
on roles(:worker) do |host|
with rails_env: fetch(:rails_env) do
** Your code to restart resque server **
end
end
end
end
after :deploy, 'puma:restart'
after :deploy, 'resque:restart'
查看文档以获取有关设置部署的命令和挂钩的更多信息。
推荐阅读
- qt - 水平布局仅在两个小部件之间平均共享空间
- python - 如何根据条件替换字符串中的字符 - python
- python - 无法将 KerasSurgeon 与 Tensorflow 2.4.1 版本一起使用
- javascript - 当用户在浏览器控制台输入字符串时响应
- ssis - SSIS 序列容器条件失败
- webpack - 如何在 Symfony Bundles 中使用 webpack
- android - 对两个不同的动态功能模块使用相同的库“openCV”
- drop-down-menu - 在 Shopify 主题中自定义单个选项选择器
- ruby-on-rails - 带有 ruby on rails 的电子邮件中的静态图像链接损坏
- node.js - 猫鼬获取不包含子文档中某些项目的集合