Capistrano不会创建puma.pid文件

bor*_*ano 2 capistrano pid ruby-on-rails puma server

我使用Capistrano部署我的Rails应用程序。但是,当我部署我的应用程序时,puma.pid没有创建文件,这导致一个问题-我无法使用capistrano重新启动服务器或部署新版本-capistrano 无法停止puma,因为puma.pid它没有溢出,并且假定没有puma进程运行。ADDRESS ALREADY IN USE当capistrano尝试运行另一个版本的puma时,我得到了错误。

这是我的 deploy.rb

lock '3.4.0'

set :application, 'appname'
set :repo_url, 'giturl'
set :deploy_to, '/home/user/appname'
set :pty, false
set :linked_files, %w(config/application.yml config/database.yml)
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, '2.3.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" # accept array for multi-bind
set :puma_conf, "#{shared_path}/config/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, 1
set :puma_workers, 1
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, true

set :sidekiq_config, 'config/sidekiq.yml'
set :sidekiq_log, '/dev/null'
set :sidekiq_processes, 1

set :clockwork_file, "clock.rb"

namespace :deploy do

  desc 'Recompile all enterprise themes'
  task :recompile_themes, [:command] => 'deploy:set_rails_env' do |task, args|
    on primary(:app) do
      within current_path do
        with :rails_env => fetch(:rails_env) do
          rake 'themes:recompile'
        end
      end
    end
  end

  after :finishing, "deploy:recompile_themes"
end

require 'appsignal/capistrano'
Run Code Online (Sandbox Code Playgroud)

例如,当我尝试停止运行Puma时,出现以下错误:

...
DEBUG [37113fcf] Running [ -f /home/user/appname/shared/tmp/pids/puma.pid ] as user@server
DEBUG [37113fcf] Command: [ -f /home/user/appname/shared/tmp/pids/puma.pid ]
DEBUG [37113fcf] Finished in 0.273 seconds with exit status 1 (failed).
WARN Puma not running
Run Code Online (Sandbox Code Playgroud)

实际上,/home/user/appname/shared/tmp/pids/puma.pid文件不存在。我需要手动创建它吗?可以在同一目录中找到也以相同方式创建的sidekiq.pid,因此我认为这不是权限问题。

有关如何处理此问题的任何建议?

Mat*_*son 8

我认为您正在使用capistrano3-puma gem。这是该宝石的工作原理:各种puma_*设置对Puma没有直接影响。这些设置不会从Capistrano传递到Puma。Puma从config/puma.rb文件中获取所有设置。为了使puma_*设置生效,您必须显式运行:

cap production puma:config
Run Code Online (Sandbox Code Playgroud)

这将采用puma_*您在Capistrano中指定的设置,config.rb使用这些值构建适当的文件,然后将其上传到服务器。具体来说,将其放在中#{shared_path}/config/puma.rb

你应该添加config/puma.rb在你的:linked_files,让每一个部署得到对这种共享的配置链接。

换句话说,解决方案是config/puma.rb从源代码存储库中删除,而是依靠cap production puma:config为您生成合适的代码。