Capistrano不会创建puma.pid文件

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

这是我的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' 

例如,当我试图停止运行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 

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

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

我假设你正在使用capistrano3-puma gem 。 以下是gem的工作原理: 各种puma_*设置对Puma没有直接影响。 这些设置不会从Capistrano传递给Puma。 Puma从config/puma.rb文件中获取所有设置。 为了使您的puma_*设置产生任何效果,您必须明确运行:

 cap production puma:config 

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

您应该在您的:linked_files添加config/puma.rb ,以便每个部署都链接到此共享配置。

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

我设法通过编辑config/puma.rb文件并添加以下行来解决此问题:

 # Store the pid of the server in the file at "path". pidfile '/home/user/appname/shared/tmp/pids/puma.pid' # Use "path" as the file to store the server info state. This is # used by "pumactl" to query and control the server. state_path '/home/user/appname/shared/tmp/pids/puma.state' 

但当然这远非理想的解决方案,因为它会造成重复,所以我在等待来自SO社区的其他更优雅的解决方案