问题
I'm using Rails 3.2 and Ruby 2.1 with capistrano 3.0.1 deployement, and I'm facing issue with the git:check task :
douglas@bilbo:/var/www/odpf$ cap production git:check --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
INFO [01658950] Running /usr/bin/env mkdir -p /tmp/odpf/ on phisa-odpf-vd.vserver.nimag.net
DEBUG [01658950] Command: /usr/bin/env mkdir -p /tmp/odpf/
DEBUG [01658950] === Lancement de /home/rvm_admin/.bashrc ===
INFO [01658950] Finished in 0.629 seconds with exit status 0 (successful).
cap aborted!
=== Lancement de /home/rvm_admin/.bashrc ===
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-scp-1.1.2/lib/net/scp.rb:392:in `await_response_state'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-scp-1.1.2/lib/net/scp.rb:363:in `block (3 levels) in start_command'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:311:in `call'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:311:in `process'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:222:in `block in preprocess'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:222:in `each'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:222:in `preprocess'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/net-scp-1.1.2/lib/net/scp.rb:279:in `upload!'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:81:in `upload!'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake:14:in `block (3 levels) in <top (required)>'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
The last line of code that the ruby debugger gave is about await_response_state
, so I guess that ssh-kit doesn't get an answer and timed out. I can't figure why though ???
I dug into /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake
and found this at the stucked line 13 :
upload! StringIO.new("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n"), "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
The parameters for this command are like chinese for me and I can't dig deeper.
If anybody could help me on this issue (either with capistrano, or with bash & ruby for the parameters) I would be gratefull.
Thanks
回答1:
Ok I found the solution.
Capistrano use ssh to connect to my server.
Though most people would tell you that when you connect as non-login and non-interactive shell (with a script in ssh) no file will be executed :
This is not always true !
I checked the man page of Bash and found this interesting part :
Bash attempts to determine when it is being run with its standard input connected to a a network connection, as if by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable. It will not do this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rcfile option may be used to force another file to be read, but rshd does not generally invoke the shell with those options or allow them to be specified.
So I checked my ~/.bashrc
file and realize I put some echo commands to check different environnment variable. Nothing harmfull.... at first glance.
I managed to test scp command solo on the bash and it was failing. That was weird because it was working at some point in the past. I searched in google and found a similar issue : SCP is bugged. When your .bashrc output some echo command, it get screwed up.
The cause of all my problems was coming from a bug in scp that is not going to be fixed by the developers. This is unfortunate in my case.
Here it is an inquiry made by someone else on a similar problem : https://unix.stackexchange.com/questions/18231/scp-fails-without-error And here it is the SCP bug dating from year 2000 !!! https://bugzilla.redhat.com/show_bug.cgi?id=20527
To solve it, I commented my "echo commands" at the beginning of my ~/.bashrc
file :
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
#
# These are my echo command checks
#echo '=== Execution of /home/rvm_admin/.bashrc ==='
#[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
#shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'#echo "Agent forwarding ? => SSH_AUTH_SOCK = $SSH_AUTH_SOCK"
#echo '=== End of echo commands by Douglas ==='
回答2:
Adding a check for interactive shell in .bashrc also solves the problem.
Let's say your echo commands are in a function.
function echoCheck()
{
echo '=== Execution of /home/rvm_admin/.bashrc ==='
[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'#echo "Agent forwarding ? => SSH_AUTH_SOCK = $SSH_AUTH_SOCK"
echo '=== End of echo commands by Douglas ==='
}
Add this to your .bashrc and problem will be solved.
[ ! -z "$PS1" ] && echoCheck
来源:https://stackoverflow.com/questions/21076725/net-scp-waiting-until-time-out-in-capistranos-gitwrapper-task