Could not find rake on capistrano deploy - ruby-on-rails

So I am attempting to get a capistrano deployment setup with an nginx/unicorn server, using RVM.
The deploy works, but when I attempt to interact with unicorn via capistrano i get an error like:
[~/source/quibbler/config]
$ cap unicorn:start
* executing `unicorn:start'
* executing "cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D"
servers: ["wwwtestvm.whf.app"]
[wwwtestvm.whf.app] executing command
** [out :: wwwtestvm.whf.app] Could not find rake-0.9.2 in any of the sources
command finished in 553ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.2-p290#quibbler' -c 'cd /u/apps/quibbler/current && bundle exec unicorn_rails -c /u/apps/quibbler/current/config/unicorn-production.rb -E production -D'" on wwwtestvm.whf.app
I have searched the interwebs all night and can not find the solution. If I copy paste the command into my shell it works so I am 99% sure it has to do with the RVM environment not being correct.
I have created a gist of my deploy and unicorn configs:
https://gist.github.com/1375736#file_deploy.rb
https://gist.github.com/1375736#file_unicorn_production.rb
Any help or guidance would be appreciated.

Thanks to sannankhalid answer on this other question i was able to resolve it.
Short answer: add rake to your Gemfile, make sure you run bundle install so your Gemfile.lock gets updated, then deploy to your server, ayay!

Related

Issue with running bundle using Capistrano

I've seen this issue in a few other questions/Github issues, but they haven't been able to shed enough light to lead to the solution.
The error:
bash: bundle: command not found
SSHKit::Runner::ExecuteError: Exception while executing as my-user#my-IP-address: cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production exit status: 127
cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stdout: Nothing written
cd /path-to-my-app/current ; bundle exec unicorn -D -c config/unicorn.rb -E production stderr: bash: bundle: command not found
I'm using the latest version of Capistrano on my rails app. Specifically, it's a Rails 4.2.0 app with the gems capistrano-rails and capistrano-rvm.
I have a pretty standard config/unicorn.rb file, which is how I start unicorn while logged into my server. I first kill the current PID with:
kill -9 PID
Then I start unicorn with:
bundle exec unicorn -D -c /path-to-my/config/unicorn.rb -E production
This works great, but obviously I need capistrano to do that, so I essentially have those tasks in my deploy.rb file, however I get that error mentioned above. Here are the two tasks I have in deploy.rb:
namespace :deploy do
namespace :unicorn do
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute "kill -s USR2 `cat /path-to-my/tmp/pids/app-name.pid`"
end
end
desc 'Start unicorn'
task :start do
on roles(:app), in: :sequence, wait: 5 do
execute "cd #{current_path} ; bundle exec unicorn -D -c config/unicorn.rb -E production"
end
end
end
end
I have a similar task to restart DelayedJob, which throws the same error. The command is execute "cd #{current_path} ; RAILS_ENV=production bin/delayed_job -n2 restart". Like I mentioned above, when logged into the server with my user (same user I use for Capistrano), all of these tasks work as expected.
Every other built-in task works great with Capistrano, like precompiling assets, migrating my database, etc. It is the custom tasks I've added that are getting the error.
Let me know if I can add anything to help solve the problem.
Look at output of Capistrano carefully. Such commands as bundle assets:precompile makes initialization of required ruby version:
cd /<app path>/20150301211440 && ( RAILS_ENV=staging /usr/local/rvm/bin/rvm 2.1.5 do bundle exec rake assets:precompile )
Seems like you don't do it. So, probably you a using system ruby by default and it doesn't have a bundler gem.
Try to specify ruby version use RVM in your commands too. I think it should fix your problem.

Ruby on Rails fails on bundle install when using capistrano

I have not much knowledge of Ruby. I have to host a Ruby website. When I make deploy setup and check, is everything ok. But when I cap deploy I get the following error.
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/lpavisit/releases/20131009211837; true"
servers: ["x.xx.xx.xxx"]
[5.56.61.183] executing command
command finished in 209ms
failed: "sh -c 'cd /var/www/lpavisit/releases/20131009211837 && bundle install --without development test'" on x.xx.xx.xxx
Thanks!!
Setting up a Capistrano-based deploy system is a bit complex. You might want to give Heroku a try until you're more familiar with Ruby. But to continue with Capistrano, first ask it if it has everything it needs to deploy:
$ cap deploy:check
You want to see it say, You appear to have all necessary dependencies installed. Yours probably won't. In that case, you should look for a good capistrano book or online tutorial.

capistrano command works on server, but not locally

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.

Why do I get failed: "sh -c 'cd /var/www/releases...'" when deploying a Rails app?

I'm deploying to a Debian 6 server, with Apache, Passenger, Ruby1.9.1
When I run "cap deploy" or "cap deploy:migrations" I get this error:
[out :: ip.address] Could not find multi_json-1.0.3 in any of the sources
** [out :: ip.address] Run `bundle install` to install missing gems.
** [out :: ip.address]
command finished in 1037ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/releases/20111208004427; true"
servers: ["ip.address"]
[ip.address] executing command
command finished in 489ms
failed: "sh -c 'cd /var/www/releases/20111208004427 && /usr/bin/rake1.9.1 RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on ip.address
Note the run bundle install to install missing gems and failed sh -c ... part.
I already tried this export PATH=/var/lib/gems/1.9.1/bin:${PATH} and tried many other possible solutions but nothing seems to work.
By the way, NO rvm.
Make sure that your config/deploy.rb file is including Bundler's capistrano tasks with this line:
require 'bundler/capistrano'
This will tell it to run bundle install after updating your code, but before it runs other tasks like rake assets:precompile.
For reference for everybody else getting the same error. Found answer: http://www.pastbedti.me/2011/06/change-path-environment-with-rails-and-capistrano/

Could not find treetop-1.4.9 in any of the sources - cap deploy:migrate

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.

Resources