程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了RoR Puma:启动请求重复得太快大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决RoR Puma:启动请求重复得太快?

开发过程中遇到RoR Puma:启动请求重复得太快的问题如何解决?下面主要结合日常开发的经验,给出你关于RoR Puma:启动请求重复得太快的解决方法建议,希望对你解决RoR Puma:启动请求重复得太快有所启发或帮助;

我在 aws ec2 上的生产服务器上遇到了一个非常复杂的问题。

当我尝试启动 puma 服务时,它返回一个错误,并且 journalctl -e 向我显示:

ubuntu : TTY=pts/0 ; PWD=/home/ubuntu ; USER=root ; COMMAND=/bin/systemctl daemon-reload
pam_unix(sudo:session): session opened for user root by ubuntu(uID=0)
Reloading.
pam_unix(sudo:session): session closed for user root
Received disconnect from my-ip port 63644:11:  [preauth]
disconnected from authenticating user root my-ip port 63644 [preauth]
  ubuntu : TTY=pts/0 ; PWD=/home/ubuntu ; USER=root ; COMMAND=/bin/systemctl start puma-website.service
pam_unix(sudo:session): session opened for user root by ubuntu(uID=0)
Started Puma http Server.
pam_unix(sudo:session): session closed for user root
Puma starting in single mode...
* Version 4.3.5 (ruby 2.7.1-p83),codename: MysterIoUs Traveller
* Min threads: 5,max threads: 5
* Environment: production
* Listening on tcp://0.0.0.0:3000
/home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/launcher.rb:216:in `initialize
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/launcher.rb:216:i
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/launcher.rb:216:i
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/launcher.rb:105:i
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/single.rb:103:in 
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/launcher.rb:172:i
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/lib/puma/cli.rb:80:in `run
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/gems/puma-4.3.5/bin/puma:10:in `<top (requ
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/bin/puma:23:in `load'
        from /home/ubuntu/apps/my-project/shared/bundle/ruby/2.7.0/bin/puma:23:in `<main>'
puma-website.service: Main process exited,code=exited,status=1/FAILURE
puma-website.service: Failed with result 'exit-code'.
puma-website.service: Service hold-off time over,scheduling restart.
puma-website.service: Scheduled restart job,restart counter is at 1.
Stopped Puma http Server.
Started Puma http Server.

我在项目中的 puma.rb:

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count,max_threads_count

port        ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
pIDfile ENV.fetch("PIDfile") { "tmp/pIDs/server.pID" }

plugin :tmp_restart

我的 deploy.rb:

set :rbenv_ruby_string,'2.7.1'

set :application,"my-project"
set :repo_url,"git@my-repo"

shared_path = "/home/ubuntu/apps/my-project/shared"
release_path = "/home/ubuntu/apps/my-project"

set :user,'ubuntu'
set :puma_threads,[4,16]
set :puma_workers,0

set :linked_files,%w{config/master.key}


namespace :puma do
  desc 'Create DirectorIEs for Puma PIDs and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pIDs -p"
    end
  end

  before 'deploy:starting','puma:make_dirs'
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do

      # Update this to your branch name: master,main,etc. Here it's main
      unless `git rev-parse head` == `git rev-parse origin/master`
        puts "WARNING: head is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart','puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
    task :restart do
      on roles(:app),in: :sequence,wait: 5 do
        invoke 'puma:restart'
      end
  end

  before :starting,:check_revision
  after  :finishing,:cleanup
end

set :pty,true
set :use_sudo,false
set :stage,:production
set :deploy_via,:remote_cache
set :deploy_to,"/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,"unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,"#{shared_path}/tmp/pIDs/puma.state"
set :puma_pID,"#{shared_path}/tmp/pIDs/puma.pID"
set :puma_access_log,"#{release_path}/log/puma.access.log"
set :puma_error_log,"#{release_path}/log/puma.error.log"
set :ssh_options,{ forward_agent: true,user: fetch(:user),keys: %w(~/.ssh/ID_rsa.pub) }
set :puma_preload_app,true
set :puma_worker_timeout,nil
set :puma_init_active_record,true 

还有我的 puma 服务:

[Unit]
Description=Puma http Server
After=network.target


[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
# Preferably configure a non-privileged user
User=ubuntu
Group=ubuntu
# Specify the path to your puma application root
WorkingDirectory=/home/ubuntu/apps/my_project/current
# Helpful for deBUGging socket activation,etc.
Environment=RAILS_ENV=production


# The command to start Puma
ExecStart=/home/ubuntu/.rbenv/shims/bundle exec puma -C /home/ubuntu/apps/my_project/current/config/puma.rb

Restart=always


[Install]
WantedBy=multi-user.target

我的 Nginx 运行正常。但是只有我的 puma 服务上不去。

在路径“.rbenv/shims/我没有看到美洲狮,我不知道为什么:

RoR Puma:启动请求重复得太快

请,如果有人知道如何帮助我,我非常感谢,因为这个问题在我的生产中发生。

提前致谢!!

解决方法

好的,解决了;事情是在上面和 Gemfile 中安装相同的 puma 版本(这可以防止在 puma.service 启动和挂起后立即出错)。所以,看看你的 /var/syslog 是否有错误。克。

大佬总结

以上是大佬教程为你收集整理的RoR Puma:启动请求重复得太快全部内容,希望文章能够帮你解决RoR Puma:启动请求重复得太快所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: