帽子流产! SSHKit :: Runner :: ExecuteError:在主机上执行时发生异常

时间:2014-09-28 22:06:37

标签: capistrano3

我正在尝试使用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

=============================================== ===========================     #// production.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/

6 个答案:

答案 0 :(得分:8)

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

import os, re, termios
import threading, os, re, sys, select, math, binascii, errno, time
from ctypes import *
import errno

class pty():
    def __init__(self, n="undef"):
        self.cmds = {}
        self.createpty()
        self.name = n
        self.goon = 1
        self.input = ""
        self.output = []

    def createpty(self):

        self.fd3 = os.open("/dev/ptmx", os.O_RDWR | os.O_NONBLOCK);
        if self.fd3 < 0:
            print("Couldn't open output /dev/ptmx\n")
        libc = cdll.LoadLibrary(None)
        libc.grantpt(self.fd3);
    libc.unlockpt(self.fd3);
        libc.ptsname.restype = c_char_p
        self.slave = libc.ptsname(self.fd3)
        print("Use: " + self.slave);

        self.old = termios.tcgetattr(self.fd3)
        n = termios.tcgetattr(self.fd3)

        n[3] = n[3] & ~(termios.ECHO|termios.ICANON) # c_lflag
        n[3] = n[3] & 0

#define VTIME 5
#define VMIN 6
#struct termios
#  {
#    tcflag_t c_iflag;      /* input mode flags */
#    tcflag_t c_oflag;      /* output mode flags */
#    tcflag_t c_cflag;      /* control mode flags */
#    tcflag_t c_lflag;      /* local mode flags */
#    cc_t c_line;           /* line discipline */
#    cc_t c_cc[NCCS];       /* control characters */
#    speed_t c_ispeed;      /* input speed */
#    speed_t c_ospeed;      /* output speed */
##define _HAVE_STRUCT_TERMIOS_C_ISPEED 1
##define _HAVE_STRUCT_TERMIOS_C_OSPEED 1
#  };

        n[4+1] = n[4+1] & 0xffff0000;
    #ioc.c_cc[VMIN] = 0;  # byte 6 + 7
    #ioc.c_cc[VTIME] = 0;

        termios.tcsetattr(self.fd3, termios.TCSANOW, n)

        #self.io = os.fdopen(self.fd3, "r+");


#       fd3io = fdopen (fd3, "r+");
#       fflush (fd3io);
#       setbuf (fd3io, NULL);
#     }


#typedef long int __fd_mask;
#define __NFDBITS   (8 * (int) sizeof (__fd_mask))
#define __FD_ELT(d) ((d) / __NFDBITS)
#define __FD_MASK(d)    ((__fd_mask) (1UL << ((d) % __NFDBITS)))

__FD_SETSIZE=1024

def fdmask():
    l = __FD_SETSIZE/64
    r = (c_ulong*l)()
    for i in range(l):
        r[i] = 0;
    return r

def fdset(a,b):
    a[b>>6] = a[b>>6] | (1 << (b % 64))

def fdisset(a,b):
    return (a[b>>6] & (1 << (b % 64)))

def setset(b, a):
    for i in a:
        fdset(b, i)

def setget(b, a):
    return [ i for i in a if fdisset(b,i) ]

class timeval(Structure):
    _fields_ = [("tv_sec", c_long), ("tv_usec", c_long)]

def cselect(r,w,x,timeout):

    libc = cdll.LoadLibrary(None)

    ra = fdmask();
    wa = fdmask();
    xa = fdmask();
    m = max(r+w+x)
    setset(ra, r),
    setset(wa, w),
    setset(xa, x),
    tv = timeval()
    tv.tv_sec = int(timeout)
    tv.tv_usec = int(1000000.0 * (timeout%1.0))
    ret = libc.select(m+1, ra, wa, xa, pointer(tv));
    if (ret < 0):
        print ("Error %d" %(ret));
    elif (ret == 0):
        return ([],[],[])
    else:
        return (setget(ra,r),setget(wa,w),setget(xa,x))

def main():
    if sizeof(c_ulong) != 8:
        raise("64bit os expected with long int = 64bit")
    a = pty();
    while True:
        try:
            (r,w,x) = cselect([a.fd3],[],[a.fd3],1)
            if (len(x) > 0):
                time.sleep(0.1);
                print("x");
                continue
            if (len(r) > 0):
                # implement an echo-server:
                v = os.read(a.fd3, 1)
                print (".");
                os.write(a.fd3,v)
        except pty as e:
            print (str(e));
            raise(e)

if __name__ == "__main__":
    main()

,然后重新运行命令(即 ssh-add ),它肯定可以工作。

答案 1 :(得分:4)

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

因此,如果您也遇到类似问题,请尝试在ec2上创建文件夹,然后执行cap production deploy。

答案 2 :(得分:2)

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

set :user, "mydeployuser"

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

的权限

因为你有:

set :use_sudo, true

有可能sudo可能没有像Cap 3 docs

中建议的那样设置为无密码sudo

答案 3 :(得分:0)

如果上述所有解决方案均不适合您,请尝试此操作。它对我有用。加油。

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 :(得分:0)

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

答案 5 :(得分:0)

我在尝试使用 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 文件中另起一行

仅此而已。

我希望这会有所帮助