问题描述
我使用Capistrano部署我的Rails应用程序.但是,当我部署应用程序时,未创建puma.pid
文件,这会导致问题-我无法使用capistrano重新启动服务器或部署新版本-capistrano无法停止puma
,因为puma.pid
不会t表示错误,并且假定没有正在运行的puma进程.当capistrano尝试运行另一个版本的puma时,出现ADDRESS ALREADY IN USE
错误.
I use Capistrano to deploy my Rails app. However, when I deploy my application, puma.pid
file is not being created, which leads to a problem - I can't restart server or deploy new version with capistrano - capistrano fails to stop puma
, because puma.pid
don't exests and it assumes no puma processes is running. And I get ADDRESS ALREADY IN USE
error when capistrano tries to run another version of 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'
例如,当我尝试停止运行Puma时,出现以下错误:
And when I try to stop running Puma, for example, I get the following error:
...
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,因此我认为这不是权限问题.
And indeed, /home/user/appname/shared/tmp/pids/puma.pid
file don't exists. Do I need to create it manually or something? sidekiq.pid that is also being created the same way can be found in the same directory, so I don't think it's a permissions issue.
有关如何处理此问题的任何建议?
Any advices on how to approach this?
推荐答案
我假设您正在使用 capistrano3-美洲豹宝石.宝石的工作方式如下:各种puma_*
设置直接对Puma没有影响.这些设置不会从Capistrano传递给Puma. Puma从config/puma.rb
文件获取所有设置.为了使puma_*
设置生效,您必须显式运行:
I assume you are using the capistrano3-puma gem. Here's how that gem works: The various puma_*
settings have no effect on Puma directly. These settings aren't passed from Capistrano to Puma. Puma gets all of its settings from the config/puma.rb
file. In order for your puma_*
settings to have any effect, you must explicitly run:
cap production puma:config
这将采用您在Capistrano中指定的puma_*
设置,使用这些值构建适当的config.rb
文件,然后将其上传到服务器.具体来说,它将其放置在#{shared_path}/config/puma.rb
中.
This takes the puma_*
settings you've specified in Capistrano, builds an appropriate config.rb
file using those values, and uploads it to the server. Specifically, it places it in #{shared_path}/config/puma.rb
.
您应该在:linked_files
中添加config/puma.rb
,以便每个部署都针对此共享配置进行链接.
You are supposed to add config/puma.rb
in your :linked_files
, so that every deploy gets linked against this shared config.
换句话说,解决方案是从源代码存储库中删除config/puma.rb
,而是依靠cap production puma:config
为您生成合适的代码.
In other words, the solution is to remove config/puma.rb
from your source code repository, and instead rely on cap production puma:config
to generate an appropriate one for you.
这篇关于Capistrano不会创建puma.pid文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!