Deploying Torquebox app on EC2 with Capistrano - ruby-on-rails

I'm running a rails app using JRuby 1.7.1 with Torquebox and trying to deploy on EC2 but I'm seeing the following error when I run 'cap deploy':
* 2013-10-08 21:28:55 executing `deploy'
* 2013-10-08 21:28:55 executing `deploy:update'
** transaction: start
* 2013-10-08 21:28:55 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote https://github.com/mygithubhandle/myreponame.git master"
command finished in 503ms
* executing "if [ -d /opt/apps/myappname/shared/cached-copy ]; then cd /opt/apps/myappname/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean -d -x -f; else git clone -b master /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi"myappname/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean -d -x -f; else git clone -b master https://github.com/mygithubhandle/myreponame.git /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi"
servers: ["XX.XXX.XXX.XX"]
[ec2-user#XX.XXX.XXX.XX] executing command
** [XX.XXX.XXX.XX :: out] sh: git: command not found
command finished in 268ms
*** [deploy:update_code] rolling back
* executing "rm -rf /opt/apps/pickemup-api/releases/20131009042856; true"
servers: ["XX.XXX.XXX.XX"]
[ec2-user#XX.XXX.XXX.XX] executing command
command finished in 259ms
failed: "env JRUBY_OPTS=--1.9 PATH=/opt/torquebox/current/jboss/bin:/opt/torquebox/current/jruby/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/root/bin sh -c 'if [ -d /opt/apps/myappname/shared/cached-copy ]; then cd /opt/apps/myappname/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 3c4a0fa3d6d2d67979b117439092d652896b3e44 && git clean -d -x -f; else git clone -b master https://github.com/mygithubhandle/myreponame.git /opt/apps/myappname/shared/cached-copy && cd /opt/apps/myappname/shared/cached-copy && git checkout -b deploy 3c4a0fa3d6d2d67979b117439092d652896b3e44; fi'" on ec2-user#XX.XXX.XXX.XX
My deploy.rb file:
require 'torquebox-capistrano-support'
require 'bundler/capistrano'
set :ssh_options, {:forward_agent => true}
server "ec2-user#XX.XXX.XXX.XX", :web, :app, :primary => true
set :repository, "https://github.com/mygithubhandle/mygithubrepo.git"
set :branch, "master"
set :user, "torquebox"
set :scm, :git
set :scm_verbose, true
set :use_sudo, false
set :deploy_via, :remote_cache
default_run_options[:pty] = true
ssh_options[:auth_methods] = ["publickey"]
ssh_options[:keys] = ["path/to/my/pem/key"]
set :deploy_to, "/opt/apps/myappname"
set :torquebox_home, "/opt/torquebox/current"
set :jboss_init_script, "/etc/init.d/jboss-as-standalone"
set :rails_env, 'production'
set :app_context, "/"
set :app_ruby_version, '1.9'
set :application, "myappname"
set :jruby_home, '/usr/local/jruby'
default_environment['JRUBY_OPTS'] = '--1.9'
default_environment['PATH'] = '/opt/torquebox/current/jboss/bin:/opt/torquebox/current/jruby/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/root/bin'
after 'deploy:update_code', 'deploy:assets:precompile'
after 'deploy:update', 'deploy:resymlink'
before 'deploy:finalize_update', 'deploy:assets:symlink'
namespace :deploy do
desc "relink db directory"
#if you use sqlite
task :resymlink, :roles => :app do
run "mkdir -p #{shared_path}/db; rm -rf #{current_path}/db && ln -s #{shared_path}/db #{current_path}/db && chown -R torquebox:torquebox #{current_path}/db"
end
# This is a weird part. I've found that asset complation with JRuby can really hog up the memory, which can cause the application to crash
# when doing a deploy. So, I like to compile the assets locally and SCP them to the server instead.
# Just make sure you've commented out the load deploy/assets in your Capfile.
namespace :assets do
# If you want to force the compilation of assets, just set the ENV['COMPILE_ASSETS']
task :precompile, :roles => :web do
force_compile = ENV['COMPILE_ASSETS']
begin # on first deploys, there is no current_revision so an error gets raised. in this case we want to just compile assets and upload them.
from = source.next_revision(current_revision)
rescue
force_compile = true
end
if ( force_compile) or (capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 )
run_locally("rake assets:clean && rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
end
Any ideas on what could be going wrong here?

Git client isn't installed on the box you are deploying to. You can fix it by logging in as root to your ec2 instance and installing get. (yum install git or apt-get install git)
Or you can change your deployment strategy to copy, which is slower than :remote_cache. Copy will checkout on your local machine and scp/sftp all the files over to the server being deployed to.
set :deploy_via, :copy

You need "git" in your system. apt-get install git should do the trick. However, there are a few more possible issues you can stumble upon. I have written an article on my company's blog to document my struggle and solution.

Related

How to setup a server for deployment and to do a cold deploy with Capistrano?

What is the proper way to deploy:setup and to do a cold deploy with Capistrano?
Using
this deploy.rb
Capistrano v2.14.2
Vagrant to virtualize my server,
this is my scenario:
when running deploy:setup, Capistrano makes use of root privileges to prepare the directory structure for deployment:
$ cap deploy:setup
* 2013-02-28 14:50:21 executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids"
servers: ["example.com"]
[example.com] executing command
command finished in 29ms
* executing "sudo -p 'sudo password: ' chmod g+w /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids"
servers: ["example.com"]
[example.com] executing command
command finished in 11ms
yet upon deploy:cold Capistrano attempts to checkout (from git in this case) and write as the vagrant user – the user specified in deploy.rb:
$ cap deploy:cold
* 2013-02-28 14:50:47 executing `deploy:cold'
* 2013-02-28 14:50:47 executing `deploy:update'
** transaction: start
* 2013-02-28 14:50:47 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:mariusbutuc/realtime-faye.git master"
command finished in 2360ms
* executing "if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q git#github.com:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi"
servers: ["example.com"]
[example.com] executing command
** [example.com :: out] fatal: could not create work tree dir '/home/vagrant/example/shared/cached-copy'.: Permission denied
command finished in 26ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/vagrant/example/releases/20130228195049; true"
servers: ["example.com"]
[example.com] executing command
command finished in 7ms
failed: "sh -c 'if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q git#github.com:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi'" on example.com
Of course, the deploy:check report bares no surprises: the vagrant user cannot write in the directories created during deploy:setup since the two users belong to different groups – root:root versus vagrant:vagrant:
$ cap deploy:check
[...]
The following dependencies failed. Please check them and try again:
--> You do not have permissions to write to `/home/vagrant/example'. (example.com)
--> You do not have permissions to write to `/home/vagrant/example/releases'. (example.com)
--> `/home/vagrant/example/shared' is not writable (example.com)
What is the reasoning behind this, and what prerequisite is not satisfied yet so the deployment passes this issue?
The deploy:setup task probably should not be using sudo to create the app directory, since that is likely causing it to be owned by root.
You can turn that off in your deploy.rb file with:
set :use_sudo, false
Since there are no group setting in Capistrano my workaround is to extend such a setting, for example:
set :user, 'vagrant'
set :group, 'vagrant'
and then create a task to "fix" the ownership after running deploy:setup:
after "deploy:setup", :setup_ownership
task :setup_ownership do
run "#{sudo} chown -R #{user}:#{group} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
But the only thing better than fixing an issue is not having it in the first place, so Stuart's answer is both wiser and more elegant.

Issue with Capistrano deployment from Windows permission denied Privatekey

I am really stuck with this deployment, I am using Ryan Bates code from railcasts on deploying with capistrano.
Here is my deploy
require "bundler/capistrano"
load "config/recipes/base"
load "config/recipes/nginx"
load "config/recipes/unicorn"
load "config/recipes/postgresql"
load "config/recipes/nodejs"
load "config/recipes/rbenv"
load "config/recipes/check"
server "37.188.126.99", :web, :app, :db, primary: true
set :user, "deployer"
set :application, "TWL"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
#set :repository, "git#github.com:acooperman/#{application}.git"
set :repository, "git#github.com:acooperman/TWL.git"
#set :repository, "https://github.com/acooperman/TWL.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
And here is the result :
$ cap deploy:update
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:acooperman/TWL.git master"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/TWL/releases/20120611173529; true"
servers: ["37.188.126.99"]
Password:
[37.188.126.99] executing command
command finished in 340ms
Command git ls-remote git#github.com:acooperman/TWL.git master returned status code pid 3500 exit 128
If I swap the comments on the line
set :repository, "git#github.com:acooperman/TWL.git"
#set :repository, "https://github.com/acooperman/TWL.git"
I get the following :
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote https://github.com/acooperman/TWL.git master"
Username for 'https://github.com':
Password for 'https://acooperman#github.com':
command finished in 7893ms
* executing "if [ -d /home/deployer/apps/TWL/shared/cached-copy ]; then cd /home/deployer/apps/TWL/shared/cached-copy && git
fetch -q origin && git fetch --tags -q origin && git reset -q --hard 418c9e9b1d7b37427a76e6bf98a17722f3a9e863 && git clean -q
-d -x -f; else git clone -q https://github.com/acooperman/TWL.git /home/deployer/apps/TWL/shared/cached-copy && cd /home/depl
oyer/apps/TWL/shared/cached-copy && git checkout -q -b deploy 418c9e9b1d7b37427a76e6bf98a17722f3a9e863; fi"
servers: ["37.188.126.99"]
Password:
[37.188.126.99] executing command
** [37.188.126.99 :: out] error: The requested URL returned error: 401 while accessing https://github.com/acooperman/TWL.git/
info/refs
**
** fatal: HTTP request failed
command finished in 1590ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/TWL/releases/20120611173441; true"
servers: ["37.188.126.99"]
[37.188.126.99] executing command
command finished in 331ms
failed: "sh -c 'if [ -d /home/deployer/apps/TWL/shared/cached-copy ]; then cd /home/deployer/apps/TWL/shared/cached-copy && gi
t fetch -q origin && git fetch --tags -q origin && git reset -q --hard 418c9e9b1d7b37427a76e6bf98a17722f3a9e863 && git clean -
q -d -x -f; else git clone -q https://github.com/acooperman/TWL.git /home/deployer/apps/TWL/shared/cached-copy && cd /home/dep
loyer/apps/TWL/shared/cached-copy && git checkout -q -b deploy 418c9e9b1d7b37427a76e6bf98a17722f3a9e863; fi'" on 37.188.126.99
Git works fine from my new vps and does not require a password.
I really am stuck here and any help would be appreciated, I am completely new to capistrano and fairly new to rails so this really does have me stumped.
Thanks for any help :)
Adam
looks like your ssh key is not in the default location, try setting a pass to your ssh key manually
ssh_options[:keys] = ["PATH TO SSH/id_rsa]

speed up deploys with capistrano in rails 3.1

I have uploaded a app in production mode to linode.
I want make changes in local app in css, javascript, controllers, models, or any file that I need change or update code and after deploy in my remote app.
I use capistrano, and I have this recipe in deploy.rb file.
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load pathe
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, 'ruby-1.9.2-p318#global'
set :rvm_type, :user
set :application, "app.com"
set :user, 'myuser'
set :repository, "#{user}#ip.ip.ip.ip:~/app"
ssh_options[:forward_agent] = true
set :scm, :git
set :use_sudo, false
set :keep_releases, 1
set :deploy_to, "~/#{application}"
#set :deploy_via, :copy
set :deploy_via, :remote_cache
role :web, "ip.ip.ip.ip" # Your HTTP server, Apache/etc
role :app, "ip.ip.ip.ip" # This may be the same as your `Web` server
role :db, "ip.ip.ip.ip", :primary => true # This is where Rails migrations will run
load 'deploy/assets'
The problem is that when I run cap deploy the process is very very slow take a 5 or 6 minutes in deploy If I want change 2 files or add a gem I want update only those files that have changed.
How can I speed up the deploy with capistrano. With git I go very fast but I have that enter more command, git add . git commit...
Note**
I have check with set :deploy_via, :remote_cache but I get errors with permissions in log of capistrano :O.
Log capistrano after cap deploy
[ip.ip.ip.ip] executing command
[ip.ip.ip.ip] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.2-p318#global' -c 'if [ -d ~/app.com/shared/cached-copy ]; then cd ~/app.com/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e142768dc6351878cb45712dca8d31ead4ffb40c && git clean -q -d -x -f; else git clone -q myuser#ip.ip.ip.ip:~/app ~/app.com/shared/cached-copy && cd ~/app.com/shared/cached-copy && git checkout -q -b deploy e142768dc6351878cb45712dca8d31ead4ffb40c; fi'
** [ip.ip.ip.ip :: err] Permission denied, please try again.
** [ip.ip.ip.ip :: err] Permission denied, please try again.
** [ip.ip.ip.ip :: err] Permission denied (publickey,password).
** [ip.ip.ip.ip :: err] fatal: The remote end hung up unexpectedly
command finished in 1337ms
*** [deploy:update_code] rolling back
* executing "rm -rf ~/app.com/releases/20120325150641; true"
servers: ["ip.ip.ip.ip"]
[ip.ip.ip.ip] executing command
[ip.ip.ip.ip] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.2-p318#global' -c 'rm -rf ~/app.com/releases/20120325150641; true'
command finished in 702ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.2-p318#global' -c 'if [ -d ~/app.com/shared/cached-copy ]; then cd ~/app.com/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e142768dc6351878cb45712dca8d31ead4ffb40c && git clean -q -d -x -f; else git clone -q myuser#ip.ip.ip.ip:~/app ~/app.com/shared/cached-copy && cd ~/app.com/shared/cached-copy && git checkout -q -b deploy e142768dc6351878cb45712dca8d31ead4ffb40c; fi'" on 109.74.195.41
After create cached-copy directory
myuser#myuser:~/app.com/current$ if [ -d ~/app.com/shared/cached-copy ];
> then cd ~/app.com/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e142768dc6351878cb45712dca8d31ead4ffb40c && git clean -q -d -x -f; else git clone -q myuser#ip.ip.ip.ip:~/app ~/app.com/shared/cached-copy && cd ~/app.com/shared/cached-copy && git checkout -q -b deploy e142768dc6351878cb45712dca8d31ead4ffb40c; fi
myuser#ip.ip.ip.ip's password:
myuser#ip.ip.ip.ip:~/app.com/shared/cached-copy$
Thank you very much!
The first thing I would suggest to speed it up is getting the deploy_via :remote_cache working. You need to make sure that the remote user can authenticate to your git repo, which means configuring your SSH key on the remote server to connect.
Try setting this:
ssh_options[:forward_agent] = true
Github has a great help article on getting it working:
http://help.github.com/deploy-with-capistrano/
If you're only updating a couple of files, you often don't need to deploy your entire application. Capistrano has a deploy:upload task for exactly this purpose:
cap deploy:upload FILES=file1,file2,file3
Since it expects the files in an environment variable, it's kind of a pain to upload multiple files with it. I wrote this script to make it a little easier to use:
#!/bin/bash
cap deploy:upload FILES=`perl -le 'print join "," => #ARGV' $#`
Save that somewhere in your path, and you can just pass paths as command line arguments. Then restart your application:
upload app/models/{user,product}.rb config/application.rb
cap deploy:restart

ssh problems during deploy with capistrano

I'm getting permissions errors while trying to deploy my rails app to a friend's server. I'm running rails 3.1.3, ruby-1.9.2-p290, capistrano 2.11.2, Mac OS 10.6.8, and we have ssh keys set up. However, we can't figure out where the permission issues are coming from. We think it might be that capistrano is trying to push the code from the git repo AS THE GIT USER to the deploy directory, or something like that. But this is our first deploy attempt, so we're not sure. Any help would be hugely appreciated!
Oh, and here's some more details that my friend told me to specify:
appsrv-04.example.ca is the canonical FQDN of the host, and project.example.ca is a CNAME pointing to the A record of appsrv-04.example.ca. The known_hosts file for the git and deploy users contains all of appsrv-04, appsrv-04.example.ca, project, and project.example.ca.
Below is the output from running cap deploy:update.
[user#workstation]~/Code/projectapi $ cap deploy:update
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://git#appsrv-04.example.ca/usr/local/git_root/projectapi.git master"
Enter passphrase for key '/Users/user/.ssh/id_rsa':
command finished in 4478ms
* executing "if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://git#appsrv-04.example.ca/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi"
servers: ["project.example.ca"]
Enter passphrase for /Users/user/.ssh/id_dsa:
[project.example.ca] executing command
** [project.example.ca :: err] Permission denied, please try again.
** [project.example.ca :: err] Permission denied, please try again.
** [project.example.ca :: err] Permission denied (publickey,password).
** [project.example.ca :: err] fatal: The remote end hung up unexpectedly
command finished in 650ms
*** [deploy:update_code] rolling back
* executing "rm -rf /usr/local/www/sites/project.example.ca/public/releases/20120222225453; true"
servers: ["project.example.ca"]
[project.example.ca] executing command
command finished in 465ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2-p290#project' -c 'if [ -d /usr/local/www/sites/project.example.ca/public/shared/cached-copy ]; then cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e71d220f299271522517f7b4f028a9275d53326a && git clean -q -d -x -f; else git clone -q ssh://git#appsrv-04.example.ca/usr/local/git_root/projectapi.git /usr/local/www/sites/project.example.ca/public/shared/cached-copy && cd /usr/local/www/sites/project.example.ca/public/shared/cached-copy && git checkout -q -b deploy e71d220f299271522517f7b4f028a9275d53326a; fi'" on project.example.ca
And here's my deploy file:
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :application, "Project"
set :scm, "git"
set :repository, "ssh://git#appsrv-04.example.ca/usr/local/git_root/project.git"
set :user, "deploy"
#set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_ruby_string, "1.9.2-p290#project"
ssh_options[:forward_agent] = true
set :branch, "master"
set :deploy_via, :remote_cache
set :deploy_to, "/usr/local/www/sites/project.example.ca/public/"
set :use_sudo, false
set :domain, 'project.example.ca'
role :app, domain
role :web, domain
role :db, domain, :primary => true
You've almost certainly diagnosed this issue correctly; you're trying to check out the github repository as the deploy user and the forwarded key isn't being set up correctly. It looks like you have forward_agent turned on in Capistrano... are you adding your key to your agent so that it gets forwarded correctly?
Try doing that with ssh-add ~/.ssh/id-rsa and deploying again.
Problem solved. The virtual host was created by cloning an existing one and changing the IP. I updated the /etc/hosts file to use the new hostname, but apparently not the new IP. So when the deploy user was trying to ssh as the git user... it was failing because there is no git user on the IP it was using.

Cap Deploy Issues with Rails 3.1.1 and Site5

I have a Rails 3.1.1 app that I am trying to deploy via Capistrano. This is my first attempt at this and I have worked through several issues by doing a lot of research, but I have hit a wall that I can not figure out a way to scale.
I can run cap deploy:setup and cap deploy:check without incident. When I try and run cap deploy this is what I get see bottom (separated text concerning the rake 0.9.2.2 and the failed line at the bottom)
Aaron-Johnsons-Macbook-Pro:webd2 aaronjohnsonis$ cap deploy *
executing deploy' * executingdeploy:update' ** transaction:
start * executing deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.com:webdsquared/webd2.git master"
command finished in 2351ms * executing "if [ -d /home/webdsqua/apps/webd2/shared/cached-copy ]; then cd
/home/webdsqua/apps/webd2/shared/cached-copy && git fetch origin &&
git fetch --tags origin && git reset --hard
28e67c5f7e1ed4612dffd2ac4fb287356f51ce3b && git submodule init && for
mod ingit submodule status | awk '{ print $2 }'; do git config -f
.git/config submodule.${mod}.urlgit config -f .gitmodules --get
submodule.${mod}.url&& echo Synced $mod; done && git submodule sync
&& export GIT_RECURSIVE=$([ ! \"git --version\" \\< \"git version
1.6.5\" ] && echo --recursive) && git submodule update --init $GIT_RECURSIVE && git clean -d -x -f; else git clone --depth 1
git#github.com:webdsquared/webd2.git
/home/webdsqua/apps/webd2/shared/cached-copy && cd
/home/webdsqua/apps/webd2/shared/cached-copy && git checkout -b deploy
28e67c5f7e1ed4612dffd2ac4fb287356f51ce3b && git submodule init && git
submodule sync && export GIT_RECURSIVE=$([ ! \"git --version\" \\<
\"git version 1.6.5\" ] && echo --recursive) && git submodule update
--init $GIT_RECURSIVE; fi"
servers: ["webdsquared.com"] Password:
[webdsquared.com] executing command ** [webdsquared.com :: out] HEAD is now at 28e67c5 initial commit
command finished in 2428ms
copying the cached version to /home/webdsqua/apps/webd2/releases/20111104183017 * executing "cp
-RPp /home/webdsqua/apps/webd2/shared/cached-copy /home/webdsqua/apps/webd2/releases/20111104183017 && (echo
28e67c5f7e1ed4612dffd2ac4fb287356f51ce3b >
/home/webdsqua/apps/webd2/releases/20111104183017/REVISION)"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
command finished in 2997ms * executingdeploy:finalize_update'
triggering before callbacks for deploy:finalize_update' * executingdeploy:assets:symlink' * executing "rm -rf
/home/webdsqua/apps/webd2/releases/20111104183017/public/assets &&\\n
mkdir -p /home/webdsqua/apps/webd2/releases/20111104183017/public
&&\\n mkdir -p /home/webdsqua/apps/webd2/shared/assets &&\\n
ln -s /home/webdsqua/apps/webd2/shared/assets
/home/webdsqua/apps/webd2/releases/20111104183017/public/assets"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
command finished in 1104ms * executing "chmod -R g+w /home/webdsqua/apps/webd2/releases/20111104183017"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
command finished in 119ms * executing "rm -rf /home/webdsqua/apps/webd2/releases/20111104183017/log
/home/webdsqua/apps/webd2/releases/20111104183017/public/system
/home/webdsqua/apps/webd2/releases/20111104183017/tmp/pids &&\\n
mkdir -p /home/webdsqua/apps/webd2/releases/20111104183017/public
&&\\n mkdir -p
/home/webdsqua/apps/webd2/releases/20111104183017/tmp &&\\n ln
-s /home/webdsqua/apps/webd2/shared/log /home/webdsqua/apps/webd2/releases/20111104183017/log &&\\n ln
-s /home/webdsqua/apps/webd2/shared/system /home/webdsqua/apps/webd2/releases/20111104183017/public/system &&\\n
ln -s /home/webdsqua/apps/webd2/shared/pids
/home/webdsqua/apps/webd2/releases/20111104183017/tmp/pids"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
command finished in 3136ms
triggering after callbacks for deploy:update_code' * executingdeploy:assets:precompile' * executing "cd
/home/webdsqua/apps/webd2/releases/20111104183017 && rake
RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
** [out :: webdsquared.com] (in /home/webdsqua/apps/webd2/releases/20111104183017) ** [out >::
webdsquared.com] Could not find rake-0.9.2.2 in any of the sources
command finished in 1108ms
* [deploy:update_code] rolling back * executing "rm -rf /home/webdsqua/apps/webd2/releases/20111104183017; true"
servers: ["webdsquared.com"]
[webdsquared.com] executing command
**command finished in 113ms failed: "sh -c 'cd /home/webdsqua/apps/webd2/releases/20111104183017 && rake
RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on
webdsquared.com**
My deploy.rb file looks like this...
set :application, "app"
set :repository, "git#github.com:webdsquared/app.git"
set :scm, "git"
set :deploy_to, "/home/username/apps/#{application}"
set :user, "username"
set :use_sudo, false
set :deploy_via, :remote_cache
set :keep_releases, 3
set :normalize_asset_timestamps, false
set :git_enable_submodules, 1
set :branch, "master"
set :git_shallow_clone, 1
set :scm_verbose, true
role :web, "webdsquared.com"
role :app, "webdsquared.com"
role :db, "webdsquared.com", :primary => true
after "deploy", "deploy:restart"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
The Capfile looks like this...
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
Any advice would be most appreciated. Has anyone experienced the same thing and found a solution?
Thanks in advance.
What version of capistrano are you running? Are you using bundler in your application? The problem is that capistrano is not using bundle exec when running commands... It should be running bundle exec rake... not just rake...

Resources