Occasionally, an error will occur during a Capistrano deployment that doesn't provide enough output to troubleshoot. For example:
* executing "cd /apps/my_app/releases/20121019181838 && bundle exec rake RAILS_ENV=dev RAILS_GROUPS=assets assets:precompile"
servers: ["myserver.com"]
[myserver.com] executing command
*** [err :: myserver.com] rake aborted!
*** [err :: myserver.com] Connection refused - connect(2)
*** [err :: myserver.com]
*** [err :: myserver.com] Tasks: TOP => environment
*** [err :: myserver.com] (See full trace by running task with --trace)
command finished in 2388ms
*** [deploy:update_code] rolling back
* executing "rm -rf /apps/my_app/releases/20121019181838; true"
Something went wrong during the rake task, and it looks like it probably has something to do with the DB. But in order to troubleshoot this, I would need to recreate the conditions of the deploy; alas, the conditions have been rm -rf'ed.
Is there some way to make Capistrano drop to a (Cap or bash) shell here using a before or after hook? Is there an easy way to insert a --trace onto that rake task without overriding Capistrano classes? Other ideas?
I handle situations as such in the following ways:
When I can be fast enough I simply hit CTR+Z (it 'pauses' the cap process) and then I investigate things onsite (over ssh, or the cap console).
I set the debug (cap --debug) flag when running the task - which makes cap prompt me before each remote command execution, so I can investigate the situation before/after every step.
Both ways usually are sufficient for me to handle the most situations quite quickly. Hope they will also help you.
Related
I had a rails app that's was running on heroku, I recently got my VPS and trying to move it to my own server.
So, I deleted my heroku, and added an origin.
I did all the setups for deploy.rb(all looks fine)
but when I run cap deploy:setup, I got:
* 2012-11-24 20:35:21 executing `deploy:setup'
* executing "mkdir -p /var/www/sites/phil88530.com /var/www/sites/phil88530.com/releases /var/www/sites/phil88530.com/shared /var/www/sites/phil88530.com/shared/system /var/www/sites/phil88530.com/shared/log /var/www/sites/phil88530.com/shared/pids"
servers: ["phil88530.com"]
[phil88530.com] executing command
*** [err :: phil88530.com]
*** [err :: phil88530.com] ! Invalid path.
*** [err :: phil88530.com]
*** [err :: phil88530.com] ! Syntax is: git#heroku.com:<app>.git where <app> is your app's name.
command finished in 956ms
I don't want heroku exist anymore, why does it ask for heroku?
And I don't understand the invalid path as well, would be nice if I capistrano can get me more informatinos.
http://phil88530.com/ resolves to heroku... so when capistrano connects to servers: ["phil88530.com"], it's connecting to heroku.
You can either set the server to the IP address of your new VPS, or move the DNS over to the new VPS to correct the problem.
I am trying to deploy a rails application to the rackspace server via capistrano. I have deployed many Rails application to Rackspace and Linode server and never encountered such weird issue. The capistrano is not deploying the application and below is the log :
executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/latty39/releases/20121023165957 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["50.56.183.16"]
[50.56.183.16] executing command
** [out :: 50.56.183.16] rake aborted!
** [out :: 50.56.183.16] cannot load such file -- Date
** [out :: 50.56.183.16]
** [out :: 50.56.183.16] (See full trace by running task with --trace)
command finished in 7454ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/latty39/releases/20121023165957; true"
servers: ["50.56.183.16"]
[50.56.183.16] executing command
command finished in 2001ms
failed: "sh -c 'cd /home/deployer/apps/latty39/releases/20121023165957 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on 50.56.183.16
I have no idea why this is failing. I have almost spent 3 hours on this thing and no success so far. Have search stackoverflow and other resources but no help.
Any help to resolve the issue will be highly appreciated
Thanks
I figured it out myself. I was having a custom rake task which was requiring ruby Date Class like:
require 'Date'
Removed it and all fixed. But I do not need to figure out why requiring the date class in production throws error.
EDIT:
The issue here was that I used RVM on my local machine and rbenv on the server. This is highly not recommended, if you're managing several ruby installation (or upgrading your ruby version but do not want to change the system's) use either RVM or rbenv on all environments!
/EDIT
So I'll start with a bit history:
I'm in the process of upgrading our rails2 website to rails3. Most of the things are working properly by now, except Capistrano's deploy script.
The current setup I have is:
RVM (1.14.1) installed locally
ruby-1.9.3-p194 (set to the project's folder)
Capistrano v2.12.0 (upgraded from 2.6.0, but it doesn't work on 2.6.0 as well) installed as an RVM gem
rvm-capistrano (1.2.2), added to the Gemfile (after doing some reading online and on SO)
rbenv (with ruby 1.9.3p194 used globally) installed on the server
(by now if you see anything that doesn't make sense, please let me know)
Nothing changed in the deploy script, yet when I try to deploy to my testing server (let's call it beta) I get this error:
* executing `deploy:restart'
* executing "cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers"
servers: ["208.0..."]
[208.0...] executing command
*** [err :: 208.0...] rake aborted!
*** [err :: 208.0...] no such file to load -- bundler/setup
*** [err :: 208.0...] /home/foo/bar/releases/20120630161947/Rakefile:5
*** [err :: 208.0...] (See full trace by running task with --trace)
** [out :: 208.0...] (in /home/foo/bar/releases/20120630161947)
command finished in 1183ms
failed: "sh -c 'cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers'" on 208.0...
The relevant part on deploy.rb looks like this:
task :restart do
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} queue:restart_workers"
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} db:migrate"
run "touch #{deploy_to}/current/tmp/restart.txt"
end
Needless to say, rake RAILS_ENV=beta queue:restart_workers' works perfectly when run manually on the server. Also, the application gets deployed (the code was copied from git, it's just the last part of the deploy fails).
Lastly, the error didn't change since before I installed rvm-capistrano and added to the Gemfile, so I'm not even sure it's related to rvm, I'm just guessing from looking online.
Thanks
In order to work correctly, rbenv must override all the ruby and gem-related executables with the shims it provides.
Usually this is done with a startup script (this is why it works when you login to your server) but Capistrano logs in without shell and thus does not run those scripts.
You must add the following to your deploy.rb :
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
and do not use anything rvm related on your server, rbenv and rvm really do not like each other
PS : a little more explanation on this topic : http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/
I'm getting this error when running this capistrano task (my own - cap deploy:show_pointers):
* executing `deploy:show_pointers'
* executing "cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers"
servers: ["mydomain.net"]
[mydomain.net] executing command
** [out :: mydomain.net] (in /home/mydomain/public_html/site_folders/rails/releases/20120521025150)
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
command finished in 1584ms
failed: "sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers'" on mydomain.net
However when I run
sh -c 'cd /home/mydomain/public_html/site_folders/rails/current; rake app:show_pointers
manually from the same dir that capistrano logs into, it works. I have capistrano set to NOT USE sudo, so that shouldn't be the issue, but it sounds like it might be, since the above command fails with sudo. I think this is a user issue, or maybe an environment var issue. Or I'm not sure what.
Any suggestsions. This is a task that is already a rake task, but it will help me not to have to log into the server every time I run it (and about 10 more like it).
Appreciate any help on this.
manually from the same dir that capistrano logs into, it works.
That doesn't say anything, Capistrano creates a non-login tty, which means that your profile, dot-files, etc are not run.
ssh root#example.de -t /bin/sh
This is a more reliable way to compare environments to Capistrano, (although, even this is a little more full-featured than what Capistrano is using.
Given these error messages, I have a couple ideas:
** [out :: mydomain.net] Could not find rake-0.9.2 in any of the sources
** [out :: mydomain.net] Try running `bundle install`.
The app can't find the rake command. Have you tried to run bundle install on the remote machine as its recommending?
Another option might be to change the command to
cd /home/mydomain/public_html/site_folders/rails/current; bundle exec rake app:show_pointers
Using bundle exec might be recommended in front of the command depending on the ruby environment on the remote servers.
#dbra over on stack overflow has pointed out that I need the full path to rake.
I am running into an issue when trying to run migrations from capistrano (cap deploy:migrate).
latest => /var/www/site/releases/20110108002015
* executing "cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate"
servers: ["www.site.com"]
[www.site.com] executing command
** [out :: www.site.com] (in /var/www/site/releases/20110108002015)
** [out :: www.site.com] Could not find treetop-1.4.9 in any of the sources
** [out :: www.site.com] Try running `bundle install`.
command finished
failed: "sh -c 'cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate'" on www.site.com
The facts;
Rails 3.0.0
Ruby 1.9.2 via rvm
The treetop gem is installed, and if I ssh into the remote server and run the command that capistrano is attempting manually, it works without issue.
Anyone else run into this or a similar issue?
When you ssh onto the server and run the command, is it using the same user capistrano is deploying as? Often issues like this are due to the deploy users path not including the same folders as your path might.
Try using cap shell to run the command, then you can test it under the same conditions cap is under.