【问题标题】:Capistrano: cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on hostCapistrano:上限中止! SSHKit::Runner::ExecuteError:在主机上执行时出现异常
【发布时间】:2014-09-28 22:06:36
【问题描述】:

我正在尝试将带有 Capistrano 3 的代码从 GIT 存储库部署到 Ubuntu 服务器,但出现此错误。

================================================ ============================
这是我的 Gemfile。

gem 'capistrano', '~> 3.1.0'

#//Use unicorn as the app server
gem 'unicorn'

#// Use Capistrano for deployment
group :development do
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rbenv', "~> 2.0"
end

source 'https://rubygems.org'

================================================ ============================ #deploy.rb

lock '3.1.0'

#// Define the name of the application
set :application, 'my_app'

#// Define where can Capistrano access the source repository
#// set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'git@github.com:jaipratik/rw.git'

set :use_sudo, true

set :log_level, :debug

#// Define where to put your application code
set :deploy_to, "/var/www/my_app"

set :pty, true

set :format, :pretty

================================================ ============================ #// 生产.rb

role :app, %w{ubuntu@{IP/Host}}

server '{IP/Host}', user: 'ubuntu', roles: %w{web app}

set :ssh_options, {
keys: %w(/Users/jay/.ssh/id_rsa),
forward_agent: false,
user: 'user'
# auth_methods: %w(password)
}

================================================ ============================ $ bundle exec cap production deploy --trace 的结果

** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
INFO[f8299d4f] Running /usr/bin/env mkdir -p /tmp/my_app/ on {IP/Host}
DEBUG[f8299d4f] Command: /usr/bin/env mkdir -p /tmp/my_app/
INFO[f8299d4f] Finished in 0.723 seconds with exit status 0 (successful).
DEBUGUploading /tmp/my_app/git-ssh.sh 0.0%
INFOUploading /tmp/my_app/git-ssh.sh 100.0%
INFO[b509dfb7] Running /usr/bin/env chmod +x /tmp/my_app/git-ssh.sh on {IP/Host}
DEBUG[b509dfb7] Command: /usr/bin/env chmod +x /tmp/my_app/git-ssh.sh
INFO[b509dfb7] Finished in 0.084 seconds with exit status 0 (successful).
** Execute git:check
DEBUG[9646aea0] Running /usr/bin/env git ls-remote git@github.com:jaipratik/rw.git on {IP/Host}
DEBUG[9646aea0] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/my_app/git-ssh.sh /usr/bin/env git ls-remote git@github.com:jaipratik/rw.git )
DEBUG[9646aea0] c452c845bb80f72d3023557d2ea8f776950c659f
DEBUG[9646aea0]
DEBUG[9646aea0] HEAD
DEBUG[9646aea0]
DEBUG[9646aea0] c452c845bb80f72d3023557d2ea8f776950c659f
DEBUG[9646aea0]
DEBUG[9646aea0] refs/heads/master
DEBUG[9646aea0]
DEBUG[9646aea0] Finished in 0.940 seconds with exit status 0 (successful).
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
INFO[fa4b1f56] Running /usr/bin/env mkdir -pv /var/www/my_app/shared /var/www/my_app/releases on {IP/Host}
DEBUG[fa4b1f56] Command: /usr/bin/env mkdir -pv /var/www/my_app/shared /var/www/my_app/releases
INFO[fa4b1f56] Finished in 0.086 seconds with exit status 0 (successful).
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:updating (first_time)
** Invoke deploy:new_release_path (first_time)
** Execute deploy:new_release_path
** Execute deploy:updating
** Invoke git:create_release (first_time)
** Invoke git:update (first_time)
** Invoke git:clone (first_time)
** Invoke git:wrapper
** Execute git:clone
DEBUG[fa77f295] Running /usr/bin/env [ -f /var/www/my_app/repo/HEAD ] on {IP/Host}
DEBUG[fa77f295] Command: [ -f /var/www/my_app/repo/HEAD ]
DEBUG[fa77f295] Finished in 0.081 seconds with exit status 1 (failed).
DEBUG[0cc407cc] Running /usr/bin/env if test ! -d /var/www/my_app; then echo "Directory does not exist '/var/www/my_app'" 1>&2; false; fi on {IP/Host}
DEBUG[0cc407cc] Command: if test ! -d /var/www/my_app; then echo "Directory does not exist '/var/www/my_app'" 1>&2; false; fi
DEBUG[0cc407cc] Finished in 0.075 seconds with exit status 0 (successful).
INFO[de52ca0e] Running /usr/bin/env git clone --mirror git@github.com:jaipratik/rw.git /var/www/my_app/repo on {IP/Host}`enter code here`
DEBUG[de52ca0e] Command: cd /var/www/my_app && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/my_app/git-ssh.sh /usr/bin/env git clone --mirror git@github.com:jaipratik/rw.git /var/www/my_app/repo )
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host {IP/Host}: git exit status: 1
git stdout: Nothing written
git stderr: Nothing written
/Users/jay/.rvm/gems/ruby-2.1.0/gems/sshkit-1.5.1/

【问题讨论】:

  • 如果我将目标文件夹更改为 ## set :deploy_to, "/home/ubuntu/tempsite" ,这将得到解决。仍然想知道为什么它在原始位置不起作用?

标签: capistrano3


【解决方案1】:

只需在控制台中编写命令:

 ssh-add

如果这不起作用,请在控制台中编写以下命令:

 ssh-add ~/.ssh/id_rsa

然后重新运行命令(即cap production deploy),它肯定会工作。

【讨论】:

  • 我喜欢你对“它肯定会起作用”的信心
【解决方案2】:

Capistrano 无法在 ec2 上创建文件夹。一旦我创建了文件夹,它就像一个魅力。

因此,如果您也有类似问题,请尝试在 ec2 上创建文件夹,然后执行 cap 生产部署。

【讨论】:

  • 嗨 JP,我们应该在哪里创建文件夹?
  • 随心所欲,但只要确保该位置的权限良好,这样当您对该文件夹进行调用时,它就可以正常工作。
【解决方案3】:

如果上述所有解决方案都不适合您,请试试这个。这个对我有用。加油。

ssh-add ~/.ssh/your_private_id_rsa
and run
eval `ssh-agent`

参考:http://mjacobus.github.io/2015/08/20/solving-weird-capistrano-problems-with-ssh-authentication.html

【讨论】:

    【解决方案4】:

    那么/var/www/my_app 在你的远程机器上的权限是什么?确保它们归您在此配置选项中指定的同一用户所有:

    set :user, "mydeployuser"
    

    如果不是,我相信 Capistrano 默认使用您在客户端计算机上运行“cap”命令的用户。确保它有权修改/创建/var/www/my_app

    因为你有:

    set :use_sudo, true
    

    sudo 可能没有像 Cap 3 docs 中建议的那样设置为无密码 sudo

    【讨论】:

    • 如果该位置不允许使用 sudo,我该如何让它使用?
    • 我认为您可能没有无密码 sudo 设置,并且 cap 默认为登录用户。
    • 我认为你是对的,我使用的是 ec2,我从来不用为 sudo 输入密码,那么解决方案是什么?
    • 在此处查看“授权”部分:capistranorb.com/documentation/getting-started/…
    【解决方案5】:

    我在尝试使用 CapistranoRails 应用程序部署到服务器时遇到了这个问题。

    当我运行命令cap deploy 时,我得到了错误:

    SSHKit::runner::ExecuteError: Exception while executing as deploy
    

    这是我的修复方法

    问题是我尝试部署到的服务器没有授权我的 SSH 密钥。我必须执行以下操作:

    在我的本地机器上生成一个新的 SSH 密钥:

    ssh-keygen
    

    显示公共文件的内容。就我而言,我的是id_rsa.pub

    cat ~/.ssh/your-public-file
    

    登录到您要将应用部署到的服务器:

    ssh your-username@server-ip-address
    

    将公共文件的内容粘贴到~/.ssh/authorized_keys 文件中换行

    就是这样。

    我希望这会有所帮助

    【讨论】:

      【解决方案6】:

      我遇到了同样的问题。原来我忘记将我的 Gitlab 实例 SSH 密钥(“运行器”)添加到服务器的 ~/.ssh/authorized_keys 文件中。

      【讨论】:

      • 如何获取Gitlab实例SSH密钥?
      猜你喜欢
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      • 2015-09-15
      • 2021-04-10
      • 1970-01-01
      相关资源
      最近更新 更多