我正在使用Capistrano将我的Rails 5应用程序部署到AWS EC2实例。当我输入:
cap production deploy
事情进展顺利,部署成功。但是,重启美洲狮的过程无效。我看到的最后一项任务是:
puma:restart
01 ~/.rvm/bin/rvm ruby-2.4.0 do bundle exec pumactl -S /home/deploy/myapp/shared/tmp/pids/puma.state -F /home/deploy/myapp/s…
01 Command restart sent success
然而,当我访问我的网站时,我看到:
502 Bad Gateway
nginx/1.4.6 (Ubuntu)
做cap production puma:status
警告我Puma没有跑。有趣的是,cap production puma:start
与以下回声完美配合:
puma:start
using conf file /home/deploy/myapp/shared/puma.rb
01 ~/.rvm/bin/rvm ruby-2.4.0 do bundle exec puma -C /home/deploy/myapp/shared/puma.rb --daemon
01 Puma starting in single mode...
01
01 * Version 3.9.1 (ruby 2.4.0-p0), codename: Private Caller
01
01 * Min threads: 0, max threads: 8
01
01 * Environment: production
01
01 * Daemonizing...
01
我花了几个小时试图找出问题所在。我可以通过每次部署而不是restart或phased_restart任务来启动Puma服务器来解决这个问题。但是可能导致这种情况呢?我在2周前部署了一个类似的应用程序(它是一个仅限API的应用程序),它没有任何问题。
这是我的deploy.rb:
lock "3.8.2"
set :application, "myapp"
set :repo_url, "git@bitbucket.org:myorg/myapp.git"
# set :branch, :master
set :branch, :release
set :deploy_to, '/home/deploy/myapp'
set :pty, true
set :linked_files, %w{config/database.yml config/application.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.4.0'
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
我的config / deploy / production.rb:
server 'myapp.com', user: 'deploy', roles: %w{web app db}
我的puma.rb:
#!/usr/bin/env puma
directory '/home/deploy/myapp/current'
rackup "/home/deploy/myapp/current/config.ru"
environment 'production'
daemonize true
tag ''
pidfile "/home/deploy/myapp/shared/tmp/pids/puma.pid"
state_path "/home/deploy/myapp/shared/tmp/pids/puma.state"
stdout_redirect '/home/deploy/myapp/shared/log/puma_error.log', '/home/deploy/myapp/shared/log/puma_access.log', true
threads 0,8
bind 'unix:///home/deploy/myapp/shared/tmp/sockets/puma.sock'
workers 0
prune_bundler
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = "/home/deploy/myapp/current/Gemfile"
end
我真的被困在这里了。即使经过数小时的研究,我也找不到有效的解决方案!
答案 0 :(得分:1)
正如马特的评论所指出的,这似乎是一个报道的错误。我有一只猴子修补了美洲狮:重启任务作为临时解决方案,直到这个问题得到解决。
我创建了/lib/capistrano/tasks/overwrite_restart.rake:
namespace :puma do
Rake::Task[:restart].clear_actions
desc "Overwritten puma:restart task"
task :restart do
puts "Overwriting puma:restart to ensure that puma is running. Effectively, we are just starting Puma."
puts "A solution to this should be found."
invoke 'puma:stop'
invoke 'puma:start'
end
end
作为替代方案,我想我们可以覆盖capistrano-puma gem中的:register_hooks方法,并将puma:restart
替换为puma:stop
和puma:start
。
答案 1 :(得分:0)
我遇到了 Capistrano Puma 基本任务没有显示的问题(重启、停止、启动)。发生这种情况是因为在 Capistrano Puma 5.0 中,任务被移到了服务管理器模块中,
之后
require "capistrano/puma"
install_plugin Capistrano::Puma
请务必添加:
install_plugin Capistrano::Puma::Daemon
请注意,这与 Puma 5+ 不兼容,因为删除了守护程序支持。
来源:https://github.com/seuros/capistrano-puma/issues/310
或者如果你使用 Systemd
install_plugin Capistrano::Puma::Systemd
那么所有任务现在都应该显示出来,Puma 应该在部署后重新启动。