我正在使用Capistrano将我的Rails 5应用程序部署到AWS EC2实例。当我输入以下命令时:
cap production deploy
一切进展顺利,部署成功。然而,重新启动 Puma 的过程并未奏效。我看到的最后一个任务是:
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未运行。有趣的是,下面的echo可以完美地运行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
我花了几个小时来查找问题所在。我可以通过每次部署时启动Puma服务器而不是重启或分阶段重启任务来解决此问题。但是是什么导致了这个问题?两周前我部署了一个类似的应用程序(它只是一个 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}
My 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
我真的被困住了。即使经过几个小时的研究,我也找不到一个有效的解决方案!