【问题标题】:cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer帽子流产了! SSHKit::Runner::ExecuteError:在主机 xxx.xxx.xx.xx 上执行时出现异常:部署程序
【发布时间】:2021-04-10 17:55:49
【问题描述】:

我正在尝试使用 capistrano 部署我的 Ruby 应用程序(存储库在 gitlab 上),我收到此错误:

>> cap production deploy 

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Net::SSH::AuthenticationFailed: deployer
/home/deployer/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:179:in `with_ssh'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:131:in `block in _execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `tap'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:128:in `_execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/capistrano-3.2.1/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/deployer/.rvm/gems/ruby-2.1.2/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xx.xx: deployer>

我的~/.ssh/config

Host gitlab.com
  IdentityFile ~/.ssh/id_rsa
  User git
  PreferredAuthentications publickey
  ForwardAgent yes

我的deploy.rb

set :branch, ENV['BRANCH'] || 'master'
set :application, 'example'
set :repo_url, 'ssh://git@gitlab.com/xxxx/xxxxxxxxx.git'
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.1.2'
set :deploy_to, '/home/deployer/example'
set :scm, :git
set :log_level, :debug
set :linked_files, %w{config/database.yml config/initializers/s3.rb config/redis.yml config/skylight.yml config/sunspot.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads solr}
set :keep_releases, 10
set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :whenever_roles, :app
namespace :deploy do
  desc 'Compile assets'
  task :gulp_build do
    on roles(:app) do
      within "#{release_path}/app/assets/javascripts/app" do
        with bower_registry: 'http://registry.bower.io' do
          execute :bower, 'install -s'
        end
      end
      within release_path do
        execute :npm, 'install --silent'
        execute :bundle, 'exec gulp build --production'
      end
    end
  end
  %i(start stop restart force_stop reload).each do |task_name|
    namespace :unicorn do
      task task_name do
        invoke "unicorn:#{task_name}"
      end
    end
  end
  %i(start stop restart).each do |task_name|
    namespace :solr do
      task task_name do
        invoke "solr:#{task_name}"
      end
    end
  end
  after :publishing, 'deploy:gulp_build'
  after :publishing, 'deploy:unicorn:restart'
end
set :unicorn_conf_path, "#{release_path}/config/unicorn/#{fetch(:stage)}.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
namespace :unicorn do
  def run_unicorn
    execute :bundle, 'exec unicorn', '-c', fetch(:unicorn_conf_path), '-E', fetch(:rails_env), '-D'
  end
  desc 'Start unicorn'
  task :start do
    on roles(:app) do
      within current_path do
        run_unicorn
      end
    end
  end
  desc 'Stop unicorn'
  task :stop do
    on roles(:app) do
      within current_path do
        if test "[ -f #{fetch(:unicorn_pid_path)} ]"
          execute :kill, "-QUIT `cat #{fetch(:unicorn_pid_path)}`"
        end
      end
    end
  end
  desc 'Force stop unicorn (kill -9)'
  task :force_stop do
    on roles(:app) do
      within current_path do
        if test "[ -f #{fetch(:unicorn_pid_path)} ]"
          execute :kill, "-9 `cat #{fetch(:unicorn_pid_path)}`"
          execute :rm, fetch(:unicorn_pid_path)
        end
      end
    end
  end
  desc 'Restart unicorn; use this when preload_app: true'
  task :restart do
    on roles(:app) do
      within current_path do
        if test "[ -f #{fetch(:unicorn_pid_path)} ]"
          execute :kill, "-USR2 `cat #{fetch(:unicorn_pid_path)}`"
        else
          run_unicorn
        end
      end
    end
  end
  desc 'Restart unicorn; use this when preload_app: false'
  task :reload do
    on roles(:app) do
      within current_path do
        if test "[ -f #{fetch(:unicorn_pid_path)} ]"
          execute :kill, "-HUP `cat #{fetch(:unicorn_pid_path)}`"
        else
          run_unicorn
        end
      end
    end
  end
end
namespace :solr do
  %i(start stop).each do |task_name|
    desc "Sunspot solr #{task_name}"
    task task_name do
      on roles(:app) do
        within current_path do
          with rails_env: fetch(:rails_env, 'production') do
            execute :bundle, 'exec', :rake, "sunspot:solr:#{task_name}"
          end
        end
      end
    end
  end
  desc "Sunspot solr restart"
  task :restart do
    on roles(:app) do
      within current_path do
        with rails_env: fetch(:rails_env, 'production') do
          execute :bundle, 'exec', :rake, "sunspot:solr:stop"
          sleep 5
          execute :bundle, 'exec', :rake, "sunspot:solr:start"
        end
      end
    end
  end
end

我的production

set :rails_env, :production
set :application, 'example-production'
set :rbenv_ruby, '2.2.10'
set :branch, 'api'
set :deploy_to, '/home/deployer/api'
set :unicorn_conf_path, "#{release_path}/config/unicorn/proapi.rb"
set :unicorn_pid_path, "#{shared_path}/tmp/pids/unicorn.pid"
server 'xxx.xxx.xx.xx', user: 'deployer', roles: %w{web app db}

【问题讨论】:

  • 您似乎正在尝试与用户 deployer 一起部署,但 repo 配置似乎期待用户 git,设置:repo_url,'ssh://git@gitlab.com/ xxxx/xxxxxxxxx.git'

标签: ruby-on-rails ruby deployment gitlab capistrano


【解决方案1】:

感谢您的帮助!

很遗憾,昨天我很累,注意力不集中。问题确实是错误的用户。我用deployer 替换了git,一切都启动了。

【讨论】:

    【解决方案2】:

    尝试将允许的 ssh 密钥添加到您的生产机器/服务器。那就是:

    1. 在本地机器上运行cat ~/.ssh/id_rsa.pub
    2. 然后在您的服务器/生产机器上运行 ~/.ssh/authorized_keys
    3. 将上述步骤 1 的结果复制粘贴到服务器上的 authorized_keys 文件中
    4. 然后再次运行cap production deploy 命令

    如果您在运行 ~/.ssh/authorized_keys 时看不到 authorized_keys 文件 您可以通过运行将上述所有 1 到 3 的命令组合起来 cat ~/.ssh/id_rsa.pub | ssh USER@HOST "mkdir -p ~/.ssh &amp;&amp; cat &gt;&gt; ~/.ssh/authorized_keys".

    【讨论】:

      猜你喜欢
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      相关资源
      最近更新 更多