Capistrano doesn't create puma.pid file

故事扮演 提交于 2020-01-04 05:39:09

问题


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.

Here is my 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'

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

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?


回答1:


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

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.

You are supposed to add config/puma.rb in your :linked_files, so that every deploy gets linked against this shared 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.




回答2:


I managed to workaround this by editing config/puma.rb file and adding this lines:

# 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'

But of course this is far from ideal solution, as it creates duplication, so I am waiting for other, more elegant solutions from the SO community



来源:https://stackoverflow.com/questions/39544627/capistrano-doesnt-create-puma-pid-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!