Ruby on Rails fails on bundle install when using capistrano - ruby-on-rails

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.

Related

How can I precompile assets using Travis CI?

In the rails guides they have an example on how to precompile assets with Capistrano. It is as simple as adding load 'deploy/assets' to the Capfile. I simply want to achieve the same effect, precompiling assets, while using Travis CI instead. This is what I've done so far:
script/travis.sh:
run "bundle exec rake assets:precompile"
.travis.yml:
before_install:
- chmod +x script/travis.sh
script: script/travis.sh
language: ruby
rvm:
- 2.2
deploy:
provider: heroku
When this is built on Travis it fails and I get this from the log:
$ script/travis.sh
script/travis.sh: line 1: run: command not found
The command "script/travis.sh" exited with 127.
I also want to add that my shell script knowledge is very limited.
I'm not entirely sure, but I'm leaning towards the run command not being available in the travis shell, as against Capistrano. I'd say you should probably just leave your travis.sh as:
bundle exec rake assets:precompile
And try again. Let me know the results of that

capistrano 'executing bundle install' not completing

I'm following the instructions of Ryan Bates' Deploy to a VPS Railscast to deploy my app to an ubuntu cloud server on Digital Ocean. After I run cap deploy:cold, a few different commands are executed successfully, but then when it gets to 'executing bundle:install' it stays in 'executing command' mode for a very long time without throwing any kind of error or completing, like this
command finished in 171ms
* 2013-06-27 12:57:07 executing `bundle:install'
* executing "cd /home/michaelj/apps/qbruby2/releases/20130627195707 && bundle install --gemfile /home/michaelj/apps/qbruby2/releases/20130627195707/Gemfile --path /home/michaelj/apps/qbruby2/shared/bundle --deployment --quiet --without development test"
servers: ["192.xxx.xxx.xxx"]
[192.241.129.33] executing command
I looked at some other people's deployments (on Stackoverflow) and saw that this command usually completes in a matter of milliseconds. My whole gemfile has less than 20 gems (i.e. the standard gems plus a few extras), yet deployment has been paused here for more than 20 minutes.
Can you suggest what I might do?
The first step in troubleshooting these issues, is ensuring you can run the commands remotely.
Thankfully, capistrano outputs the commands it's trying to execute. Then you can do copy/paste over to the server.
In my experience, i've seen the ssh server terminating ssh sessions for long running processes. (that is migrations or bundle install for example) For those cases, there are a few options (modifying sshd_config on the server has worked for me)
add these lines to /etc/ssh/sshd_config
ClientAliveInterval 30
ClientAliveCountMax 5

Rubber fails during create_staging Bundler::GemfileNotFound ec2

This is my first time deploying an app to an ec2 instance. It seems most of the process worked but eventually the deploy failed with the following error:
failed: "/bin/bash -l -c 'cd /mnt/depot-production/releases/20130312030226 && bundle install --gemfile /mnt/depot-production/releases/20130312030226/Gemfile --path /mnt/depot-production/shared/bundle --deployment --quiet --without development test staging'" on production.foo.com
I logged into my server and went to the directory and tried to execute the command. The following error was displayed:
Bundler::GemfileNotFound
When I list the contents of the directory, it shows a gemfile. Just could use some help in determining why it is not found and how to fix it.
I'm also not exactly sure how to proceed? I would like to simply fix the error and continue on with the instance that was created but not sure what steps all need to be executed.

Could not find rake on capistrano deploy

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!

Capistrano custom task fails because "Rails requires RubyGems >= 1.3.2"

My custom capistrano task "app:sample" fails with the following error message:
mnylen ilmo-on-rails $ cap app:sample
* executing `app:sample'
* executing "export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10"
servers: ["rails.cs.helsinki.fi"]
* establishing connection to gateway `melkinpaasi.cs.helsinki.fi'
* Creating gateway using melkinpaasi.cs.helsinki.fi
* establishing connection to `rails.cs.helsinki.fi' via gateway
Password:
[rails.cs.helsinki.fi] executing command
*** [err :: rails.cs.helsinki.fi] Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org
command finished
failed: "sh -c 'export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10'" on rails.cs.helsinki.fi
Am I missing something or doing something wrong? The task is:
namespace :app do
desc "Run sample data on production2
task :sample do
run "export RAILS_ENV=production; cd #{current_path}; ruby script/coursegen 10"
end
end
If I run the same command from the actual server, it works fine.
Cap is running the remote command as an unexpected user - and that user does not have the correct path to ruby and gem. Check your settings in your recipe for :user and :use_sudo. Carefully read the cap output to see what user is being connected. I see you are using a :gateway; there can be two users in this case. One to connect to the gateway, and another to actually run commands on the target server.
Okay, solved.
The problem was that there was two Ruby installations on the production server.
The .profile file under my home directory on the production server set the PATH environment variable to point to the correct Ruby version.
run command, it seems, doesn't source the .profile file and thus, running ruby script/coursegen 10 in the task used the wrong Ruby version, which was the reason for the weird error message about RubyGems version. This also explains why it worked when manually running the command from production servers shell.
My solution was to use full path to the Ruby executable in my run task, like this:
run "export RAILS_ENV=production; cd #{current_path}; /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby script/coursegen 10"
Of course, this isn't pretty, but it works. If anyone has any prettier solutions, I'd be more than glad to use those instead. :)
Seems like you should update your RubyGems on the remote server.

Resources