gpt4 book ai didi

ruby-on-rails - Capistrano puma :restart not working, 但 puma:start 是

转载 作者:行者123 更新时间:2023-12-04 00:05:56 33 4
gpt4 key购买 nike

我正在使用 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 没有运行。有趣的是, 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 服务器而不是重启或 phased_restart 任务来解决这个问题。但什么可能导致这种情况?两周前我部署了一个类似的应用程序(它是一个只有 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

我的配置/部署/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

我真的被困在这里了。即使经过数小时的研究,我也找不到有效的解决方案!

最佳答案

正如 Matt 在评论中指出的那样,这似乎是一个已报告的错误。我已经猴子修补 puma:restart 任务作为临时解决方案,直到这个问题得到解决。

我已经创建了/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:restartpuma:stoppuma:start .

关于ruby-on-rails - Capistrano puma :restart not working, 但 puma:start 是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763777/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com