我正在准备 capistrano 将 ruby on Rails 应用程序部署到 AWS。应用程序服务器将位于 bastian 主机后面。
我有两台服务器 server1 和 server2。我想在server1上部署和运行puma、nginx,并在server2上运行resque工作程序和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 :puma_nginx_role, 'server1.com'
role :resque_role, 'server2.com'
现在在您的 config/deploy.rb 文件中定义一个 rake 任务,例如:
namespace :git do
desc 'To push the code'
task :push do
execute "git push"
end
end
现在假设上面的示例应该在 server1 上运行,您所要做的就是
namespace :git do
desc 'To push the code'
task :push, :roles => [:puma_nginx_role] do
execute "git push"
end
end
因此,您的 capistrano 配置表明 git:push 应该在角色 :puma_nginx_role 上执行,而该角色又会在 server1 上运行它。 com。您必须修改任务才能运行puma/nginx/resque并根据角色进行更改。
关于ruby-on-rails - 如何配置 capistrano 在一台服务器上部署 puma 和 nginx,并在另一台服务器上部署 resque?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530035/