`puma:restart' invoke twice but i only call it once on my deploy app via Capistrano?

随声附和 提交于 2020-08-23 01:09:45

问题


I tried to deploy Rails app to the server via Capistrano. This is my code on deploy.rb

set :repo_url,        'git@bitbucket.org:varisdaOfficial/insurance_site.git'
set :application,     'insurance_code'
set :user,            'deploy'
set :puma_threads,    [4, 16]
set :puma_workers,    0

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.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.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  # Change to false when not using ActiveRecord
set :linked_dirs, %w(public/uploads)

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 :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      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

  desc 'clear temp cache'
  task :clear_cache do
    on roles(:app) , in: :sequence, wait: 1 do
      execute "rm -rf #{shared_path}/tmp/cache/[^.]*"

    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :clear_cache
  after  :finishing,    :restart
end

So when i ran 'cap production deploy' everything work smoothly my site can be deployed successfully but i got a message after that.

Capistrano tasks may only be invoked once. Since task `puma:restart' was previously invoked, 
invoke("puma:restart") at/Users/manjarb/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/capistrano3-puma-1.2.1/lib/capistrano/tasks/puma.rake:134 will be skipped.
If you really meant to run this task again, first call Rake::Task["puma:restart"].reenable
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686

I just only call restart task once. So how can i fixed this message?

Thanks!


回答1:


I assume you are using the capistrano3-puma gem. That gem automatically restarts puma for you at the conclusion of a successful deployment. So that is the first time the restart task is being called.

Additionally, in your deploy.rb, you've defined your own custom restart task, and you are invoking it after :finishing. That is the source of the second invocation, and thus the warning.

To "fix" this problem, remove the redundant task:

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

And remove this:

after  :finishing,    :restart


来源:https://stackoverflow.com/questions/39810930/pumarestart-invoke-twice-but-i-only-call-it-once-on-my-deploy-app-via-capistr

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