require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }require 'rvm/capistrano'
set :rvm_type, :system
set :application, 'odpf'
set :repo_url, 'g...@github.com:mycount/mygitrepo.git'
set :branch, 'production_1.01'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# Reference : http://www.modrails.com/documentation/Users%20guide%20Apache.html#_redeploying_restarting_the_ruby_on_rails_application
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Reference : http://guides.rubyonrails.org/v3.2.14/command_line.html#tmp
within release_path do
execute :rake, 'tmp:cache:clear'
end
end
end
after :finishing, 'deploy:cleanup'
endset :stage, :production
server 'myserver.net', user: 'rvm_admin', roles: %w{web app db}
set :ssh_options, {
forward_agent: false,
port: 8888
}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:wrapperupload! 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 action invoked while the state machine remains in the "await
# response" state. As long as there is no data ready to process, the
# machine will remain in this state. As soon as the server replies with
# an integer 0 as the only byte, the state machine is kicked into the
# next state (see +await_response+). If the response is not a 0, an
# exception is raised.
389>def await_response_state(channel)
390> return if channel[:buffer].available == 0
391> c = channel[:buffer].read_byte
392> raise "#{c.chr}#{channel[:buffer].read}" if c != 0
393> channel[:next], channel[:state] = nil, channel[:next]
394> send("#{channel[:state]}_state", channel)
395>end--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/70ad39fc-df36-4db4-9940-99efd9f0745b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
require 'rvm/capistrano'
set :rvm_type, :system
set :application, 'odpf'
set :repo_url, 'g...@github.com:mycount/mygitrepo.git'
set :branch, 'production_1.01'
set :deploy_to, '/var/www/odpf'
set :pty, false
set :scm, :git
set :format, :pretty
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Reference : http://guides.rubyonrails.org/v3.2.14/command_line.html#tmp
within release_path do
execute :rake, 'tmp:cache:clear'
end
end
end
after :finishing, 'deploy:cleanup'
end desc "Check if ssh connexion is interactive"
task :query_interactive do
on roles(:all) do |host|
info capture("[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'") + " on #{host}"
end
end
desc "Check if ssh connexion is Login shell"
task :query_login do
on roles(:all) do |host|
info capture("shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'") + " on #{host}"
end
enddouglas@bilbo:/var/www/odpf$ bundle exec cap production test_odpf:query_login
DEBUG [92119b95] Running /usr/bin/env shopt -q login_shell && echo 'Login shell' || echo 'Not login shell' on phisa-odpf-vd.vserver.nimag.net
DEBUG [92119b95] Command: shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
DEBUG [92119b95] === Lancement de /home/rvm_admin/.bashrc ===
DEBUG [92119b95] Not login shell
DEBUG [92119b95] Finished in 0.638 seconds with exit status 0 (successful).
INFO === Lancement de /home/rvm_admin/.bashrc ===
Not login shell on myserver.net
douglas@bilbo:/var/www/odpf$
douglas@bilbo:/var/www/odpf$ bundle exec cap production test_odpf:query_interactive
DEBUG [1275aad9] Running /usr/bin/env [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive' on phisa-odpf-vd.vserver.nimag.net
DEBUG [1275aad9] Command: [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
DEBUG [1275aad9] Finished in 0.617 seconds with exit status 0 (successful).
DEBUG [1275aad9] === Lancement de /home/rvm_admin/.bashrc ===
DEBUG [1275aad9] Not interactive
DEBUG [1275aad9] Finished in 0.617 seconds with exit status 0 (successful).
INFO === Lancement de /home/rvm_admin/.bashrc ===
Not interactive on myserver.net
--You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/516fa71c-f42a-462b-a837-8045bfd776f6%40googlegroups.com.
My server is a standard Debian :rvm_admin@myserver.net:~$ cat /etc/debian_version
7.3I looked into the man page of bash and it says this :Bash attempts to determine when it is being run with its standard input connected to a network connection, as whenexecuted by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash determines it is beingrun in this fashion, it reads and executes commands from ~/.bashrc and ~/.bashrc, if these files exist and arereadable. 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 withthose options or allow them to be specified.I added some echo commands to my .bashrc to do some checks :This is the begining of my /home/rvm_admin/.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 ==='
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
...As you can see the original standard .bashrc file will do nothing if the shell is a non-intercative one.
I made two more tests :
1 - standard login ssh connection
2 - execute a custom capistrano's taskHere it is the output of my first test :
=== Lancement du script /etc/profile.d/rvm.sh ===
=== Execution of /home/rvm_admin/.bashrc ===
Interactive
Login shell
Agent forwarding ? => SSH_AUTH_SOCK = /tmp/ssh-KayxUr7HFP/agent.12938
=== End of echo commands by Douglas === desc "Check if agent forwarding is working"
task :forwarding do
on roles(:all) do |h|
if test("env | grep SSH_AUTH_SOCK")
info "Agent forwarding is up to #{h}"
else
error "Agent forwarding is NOT up to #{h}"
end
end
enddouglas@bilbo:/var/www/odpf$ bundle exec cap production test_odpf:forwarding
DEBUG [592e7884] Running /usr/bin/env env | grep SSH_AUTH_SOCK on myserver.net
DEBUG [592e7884] Command: env | grep SSH_AUTH_SOCK
DEBUG [592e7884] === Execution of /home/rvm_admin/.bashrc ===
DEBUG [592e7884] Not interactive
DEBUG [592e7884] Not login shell
DEBUG [592e7884] Agent forwarding ? => SSH_AUTH_SOCK =
DEBUG [592e7884] === End of echo commands by Douglas ===
DEBUG [592e7884] Finished in 0.612 seconds with exit status 1 (failed).
ERROR Agent forwarding is NOT up to myserver.netdouglas@bilbo:/var/www/odpf$ ssh -p 8888 -A rvm_admin@myserver.net 'git ls-remote g...@github.com:mycount/myapp.git'
Host key fingerprint is 83:50:33:be:08:34:e6:f4:00:68:ac:57:d0:74:c0:a8
+--[ RSA 2048]----+
| .X=C.. |
| o .+.. |
| D ...OE |
| o....* |
| ..S = . |
| . - . |
| . . |
| |
| |
+-----------------+
=== Execution of /home/rvm_admin/.bashrc ===
Not interactive
Not login shell
Agent forwarding ? => SSH_AUTH_SOCK = /tmp/ssh-dJ9dOKEhxE/agent.13224
=== End of echo commands by Douglas ===
e415894551dc656f79e95cdf3051223123553d40 HEAD
d872b0402c015ee40ac469e24ac78c1cffd6b8c4 refs/heads/xxxxxx
6a0f8618f17aabbe1e801be9f9a57f55dd84f6b4 refs/heads/xxxxxx
a81b96a9362ad28bd3aef3d6014e6e6791ee3a6c refs/heads/xxxxxx
0d097d9f87f8516bfec3985b6c8b1b5ed011c7b2 refs/heads/xxxxxx
0116b9fd3cd8b38e932832baf68f926be2513618 refs/heads/xxxxxx
e415894551dc656f79e95cdf3051223123553d40 refs/heads/xxxxxx
dafa8fd1c86426b2ced0f4a47c9bc7e8172540f8 refs/heads/xxxxxx
e33a87233763e7b4a1deb3c552fe02cbe18f3501 refs/heads/xxxxxx
696a9f5f79e01f1c1e0f29b6f8cb512519b489f1 refs/heads/xxxxxx
f337186b34723b3b9d1beb71f16161086ea30f44 refs/heads/xxxxxx
e415894551dc656f79e95cdf3051223123553d40 refs/heads/xxxxxx
e3d0196766ffacccce698817dfee4fea17f0ed9f refs/heads/xxxxxx
1e4c3c504a64699d8518ab67bca8f67e3bbcab51 refs/heads/xxxxxx
700ab704ec38a99fea44b013ccac97eb9168b866 refs/heads/xxxxxx
09496198b4dc93cffeaf7137c8f94aafa36e7148 refs/heads/xxxxxx--
You received this message because you are subscribed to the Google Groups "Capistrano" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/0f513186-7594-4695-bb61-1721731c8211%40googlegroups.com.
desc "Display env variables"
task :display_env do
on roles(:all) do |h|
test "env"
end
endbundle exec cap production test_odpf:display_env
DEBUG [43cb0660] Running /usr/bin/env env on myserver.net
DEBUG [43cb0660] Command: /usr/bin/env env
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
Enter passphrase for /home/douglas/.ssh/id_rsa:
DEBUG [43cb0660] === Execution of /home/rvm_admin/.bashrc ===
DEBUG [43cb0660] Not interactive
DEBUG [43cb0660] Not login shell
DEBUG [43cb0660] Agent forwarding ? => SSH_AUTH_SOCK =
DEBUG [43cb0660] === End of echo commands by Douglas ===
DEBUG [43cb0660] Finished in 14.070 seconds with exit status 0 (successful).
DEBUG [43cb0660] SHELL=/bin/bash
DEBUG [43cb0660] SSH_CLIENT=212.41.220.177 37118 7001
DEBUG [43cb0660] USER=rvm_admin
DEBUG [43cb0660] MAIL=/var/mail/rvm_admin
DEBUG [43cb0660] PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
DEBUG [43cb0660] PWD=/home/rvm_admin
DEBUG [43cb0660] LANG=fr_CH.UTF-8
DEBUG [43cb0660] SHLVL=1
DEBUG [43cb0660] HOME=/home/rvm_admin
DEBUG [43cb0660] LANGUAGE=fr_CH:fr
DEBUG [43cb0660] LOGNAME=rvm_admin
DEBUG [43cb0660] SSH_CONNECTION=my_ip 37118 server_ip ssh_prot
DEBUG [43cb0660] _=/usr/bin/env
DEBUG [43cb0660] Finished in 14.070 seconds with exit status 0 (successful).# ~/.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 ==='
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
...douglas@bilbo:/var/www/odpf$ cap production git:check --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
INFO [bfe4332e] Running /usr/bin/env mkdir -p /tmp/odpf/ on myserver.net
DEBUG [bfe4332e] Command: /usr/bin/env mkdir -p /tmp/odpf/
INFO [bfe4332e] Finished in 0.555 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/odpf/git-ssh.sh 0.0%
INFO Uploading /tmp/odpf/git-ssh.sh 100.0%
INFO [8763305f] Running /usr/bin/env chmod +x /tmp/odpf/git-ssh.sh on myserver.net
DEBUG [8763305f] Command: /usr/bin/env chmod +x /tmp/odpf/git-ssh.sh
INFO [8763305f] Finished in 0.072 seconds with exit status 0 (successful).
** Execute git:check
DEBUG [bfda396c] Running /usr/bin/env git ls-remote git@github.com:mycount/myrepo.git on myserver.net
DEBUG [bfda396c] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/odpf/git-ssh.sh /usr/bin/env git ls-remote git@github.com:mycount/myrepo.git )
DEBUG [bfda396c] Permission denied (publickey).
DEBUG [bfda396c] fatal: The remote end hung up unexpectedly
DEBUG [bfda396c] Finished in 1.135 seconds with exit status 128 (failed).set :ssh_options, { forward_agent: true, port: 8888 }cap production git:check --trace# For Capistrano 2.x
require 'rvm/capistrano'# For Capistrano 3.x
require 'capistrano/rvm'