Question

I have my deploy.rb:

require 'net/ssh/proxy/command'

set :application, 'my app name'
set :repo_url,    'my github url'
set :scm,         :git
set :scm_verbose, true
set :use_sudo,    false
set :port,        ENV['SSH_PORT'] # will give the port number, for example: 3029

set :ssh_options, proxy: Net::SSH::Proxy::Command.new("ssh -i ~/.ssh/nh -p #{fetch(:port)} #{roles(:app)}") # I just wanna make use of my public key, for example: nh in .ssh directory to connect to server(s).

task :execute_on_server do
  on roles(:app) do
    puts "Running onto server from hello!"
    execute "#{sudo} cp ~/hello /home/username/hello"
  end
end

And deploy/production.rb:

set :stage, :production
set :branch,'production'
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
set :production_app_ip, "#{ENV['CAP_PRODUCTION_USER']}@#{ENV['CAP_PRODUCTION_IP']}"
set :production_web_ip, "#{ENV['CAP_PRODUCTION_USER']}@#{ENV['CAP_PRODUCTION_IP']}"
set :production_db_ip, "#{ENV['PRODUCTION_USERNAME']}@#{ENV['PRODUCTION_HOST']}"

role :app, [fetch(:production_app_ip)]
role :web, [fetch(:production_web_ip)]
role :db,  [fetch(:production_db_ip)]

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server ENV['CAP_PRODUCTION_IP'], user: ENV['CAP_PRODUCTION_USER'], roles: %w{web app}, my_property: :my_value

When I run: $ cap production execute_on_server, it throws this error:

[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.
Running onto server from hello!
 INFO [6d724595] Running /usr/bin/env sudo on 198.343.661.910
DEBUG [6d724595] Command: /usr/bin/env sudo
Pseudo-terminal will not be allocated because stdin is not a terminal.
ssh: Could not resolve hostname []: Name or service not known
cap aborted!
connection closed by remote host
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/server_version.rb:50:in `negotiate!'
org/jruby/RubyKernel.java:1517:in `loop'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/server_version.rb:45:in `negotiate!'
org/jruby/RubyKernel.java:1517:in `loop'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/server_version.rb:43:in `negotiate!'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/server_version.rb:32:in `initialize'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:78:in `initialize'
org/jruby/ext/timeout/Timeout.java:105:in `timeout'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:78:in `initialize'
/home/surya/.rvm/gems/jruby-1.7.6/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/connection_pool.rb:25:in `create_or_reuse_connection'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:173:in `ssh'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:126:in `_execute'
org/jruby/RubyKernel.java:1889:in `tap'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/surya/.rvm/gems/jruby-1.7.6/gems/capistrano-3.0.1/lib/capistrano/dsl.rb:26:in `sudo'
/home/surya/Desktop/surya/work/codes/projects/job/resolutions/config/deploy.rb:56:in `(root)'
org/jruby/RubyBasicObject.java:1565:in `instance_exec'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/surya/.rvm/gems/jruby-1.7.6/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `execute'
Tasks: TOP => hello
(See full trace by running task with --trace)

Please note that I am using Ruby: jruby 1.7.6 (1.9.3p392) 2013-10-22 6004147 on OpenJDK 64-Bit Server VM 1.6.0_27-b27 [linux-amd64], capistrano version: 3.0.1, and rails version: 4.0.2

Was it helpful?

Solution

The issue was in my deploy/production.rb, I had to mention the ssh port when defining the server. So, this will look like this:

set :stage,  :production
set :branch, 'production'
set :user,   ENV['CAP_PRODUCTION_USER']
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
set :production_app_ip, "#{ENV['CAP_PRODUCTION_USER']}@#{ENV['CAP_PRODUCTION_IP']}"
set :production_web_ip, "#{ENV['CAP_PRODUCTION_USER']}@#{ENV['CAP_PRODUCTION_IP']}"
set :production_db_ip, "#{ENV['PRODUCTION_USERNAME']}@#{ENV['PRODUCTION_HOST']}"

role :app, [fetch(:production_app_ip)]
role :web, [fetch(:production_web_ip)]
role :db,  [fetch(:production_db_ip)]

# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server ENV['CAP_PRODUCTION_IP'], user: ENV['CAP_PRODUCTION_USER'], roles: %w{web app}, port: ENV['SSH_PORT'], primary: true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top