【问题标题】:`puma:restart' invoke twice but i only call it once on my deploy app via Capistrano?`puma:restart' 调用了两次,但我只通过 Capistrano 在我的部署应用程序上调用了一次?
【发布时间】:2016-10-01 20:00:32
【问题描述】:

我尝试通过 Capistrano 将 Rails 应用程序部署到服务器。 这是我在 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

因此,当我运行“cap production deploy”时,一切正常,我的站点可以成功部署,但之后我收到了一条消息。

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

我只调用一次重启任务。 那么我该如何修复这个消息呢?

谢谢!

【问题讨论】:

    标签: ruby-on-rails capistrano


    【解决方案1】:

    我假设您正在使用 capistrano3-puma gem。成功部署后,该 gem 会自动为您重新启动 puma。所以这是第一次调用重启任务。

    此外,在您的 deploy.rb 中,您已经定义了自己的自定义重启任务,并且您正在调用它after :finishing。这是第二次调用的来源,也是警告的来源。

    要“修复”这个问题,请删除多余的任务:

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

    然后删除这个:

    after  :finishing,    :restart
    

    【讨论】:

    • 马特的答案是正确的。但是对于需要 Capistrano 任务运行两次的人,您可以使用 invoke 调用该任务!而是。
    • 我发现如果我跳过第二次重启任务,应用程序实际上无法启动。有没有办法跳过第一个而只保留第二个?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    相关资源
    最近更新 更多