rake aborted! no such file to load -- bundler/setup - ruby-on-rails-3

I run a rake task every night via cron (as root), when it runs it gives the error:
rake aborted!
no such file to load -- bundler/setup
which I get in an email
When I run it manually (as root), it runs just fine.
I am running rvm if that helps.
I am not really sure what to add to help, but here are a few things.
# ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
# rails -v
Rails 3.0.9
# gem -v
1.8.5

try to set up your cron task like this
* * * * * /bin/bash -l -c 'rake blah:blah'

Related

How to debug RVM setup from Chef and Vagrant?

I got RVM setup with Chef-solo on a Vagrant VM just fine, however I am confused on why bundler can not be found in the rails project.
So, after provisioning I see:
Last login: Thu Oct 4 15:23:58 2012 from 10.0.2.2
vagrant#vm:~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
vagrant#vm:~$ gem list
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.3.2)
daemon_controller (1.1.1)
fastthread (1.0.7)
io-console (0.3)
json (1.5.4)
minitest (2.5.1)
passenger (3.0.18)
rack (1.5.2)
rake (10.0.3, 0.9.2.2)
rdoc (3.9.4)
rubygems-bundler (1.1.1)
rvm (1.11.3.6)
Going to the project directory I see:
vagrant#vm:~$ cd /www/vm/rails/current/
==============================================================================
= NOTICE =
==============================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands. =
= =
= Examine the contents of this file carefully to be sure the contents are =
= safe before trusting it! ( Choose v[iew] below to view the contents ) =
==============================================================================
Do you wish to trust this .rvmrc file? (/www/vm/rails/current/.rvmrc)
y[es], n[o], v[iew], c[ancel]> y
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327#vm': Permission denied
gemset vm is not existing, creating.
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327#vm': Permission denied
mkdir: cannot create directory `/usr/local/rvm/gems/ruby-1.9.3-p327#vm': Permission denied
But now, bundle can not be found anymore, and I also have problems to activate RVM... any ideas how to debug this?
$ rvm use ruby-1.9.3-p327
Please note that `rvm gem ...` was removed, try `gem ` or `rvm all do gem ` instead. ( see: 'rvm usage' )
PS my node json is basically this: https://github.com/mulderp/chef-rails-stack
For debugging I use https://github.com/mpapis/rvm-binary/blob/master/cookbooks/binary/recipes/default.rb#L11 :
class Chef::Resource::Script
def log_code command
if Chef::Config[:log_level] == :debug
code "{ #{command}; _ret=$?; echo \"Exit status was $_ret.\"; exit $_ret; } 2>&1 |
tee /var/log/#{#command.to_s.gsub(/ /,"_")}.log; exit ${PIPESTATUS[0]}"
else
code command
end
end
end
and then instead of code use log_code, it will save logs in /var/log/#{#command.to_s.gsub(/ /,"_")}.log
as for easy integration of RVM with Chef check https://gist.github.com/sevos/5076747 :
deploy_user = node[:deploy][:user]
deploy_user_home = File.join('/', 'home', deploy_user)
rvm_version = "head"
execute "install_rvm_for_deploy_user" do
user deploy_user
command "curl -L https://get.rvm.io | bash -s #{rvm_version}"
environment "HOME" => deploy_user_home
creates "#{deploy_user_home}/.rvm"
end
node['buildpack']['ruby_versions'].each do |ruby_version|
execute "install_rvm_ruby_#{ruby_version}" do
user deploy_user
environment "HOME" => deploy_user_home
command "#{deploy_user_home}/.rvm/bin/rvm install #{ruby_version} --autolibs=3"
end
end
file "#{deploy_user_home}/.rvmrc" do
content 'export rvm_trust_rvmrcs_flag=1'
owner deploy_user
mode 0644
end

cron with whenever gem not running

I am using thinking sphinx for search.It searches properlt but the problem was whenever i add new records i have to do rake thinking_sphinx:index manually.So to run it automatically i am using whenever gem with cron but still its not happening automatically,Either i have to do
rake thinking_sphinx:index
or
whenever -w to create index automatically
Following is the code of config/schedule.rb :
every 10.minutes do
rake "thinking_sphinx:index", :environment => :development
end
every :reboot do
rake "thinking_sphinx:start",:environment => :development
end
when i do crontab -l i get following :
# Begin Whenever generated tasks for: store
#reboot /bin/bash -l -c 'cd /home/user/newsvn/alumnicell && RAILS_ENV=development bundle exec rake thinking_sphinx:start --silent'
0,10,20,30,40,50 * * * * /bin/bash -l -c 'cd /home/user/newsvn/alumnicell && RAILS_ENV=development bundle exec rake thinking_sphinx:index --silent'
# End Whenever generated tasks for: store
What and where is the problem that this not working?
Also i changed environment to development.by default it was production.what is the difference in these 2?
You can assign log file to track errors, then post it here.
Also I advise to set :environment globally.
Try this code:
set :environment, :development
set :output, 'tmp/whenever.log'
every 10.minutes do
rake "thinking_sphinx:index"
end
every :reboot do
rake "thinking_sphinx:start"
end
I will advise you to use thinking sphinx's delta indexes instead of using whenever cron jobs to rebuild thinking sphinx every 10 minutes.
As it's described here you should just add a boolean column delta to your model, set set_property :delta => true in your define_index block and run rake ts:rebuild
That's it.

Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory

When using the 'whenever gem', I get an error in the log:
/usr/bin/env: ruby: No such file or directory
It works when I run the job manually. I've installed everything with RVM.
I've used the which command to find where my Ruby installation is, and I get:
kevin#lovely:/opt/personal$ which ruby
/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
and I've checked my $PATH variable, where it returns:
kevin#lovely:/opt/personal$ echo $PATH
/home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290#global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?
If you're interested, this is what my whenever crontab output is:
# Begin Whenever generated tasks for: rss
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'
You're probably long past this issue but for future reference:
I had a similar problem only I was getting
/usr/bin/env: ruby: No such file or directory
It turned out the first line of the file script\rails was #!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explained here. But it should have been #!/usr/bin/env ruby1.9.3 since that was the version I had installed.
Hope this helps someone in the future :)
My issue was that ruby is in /usr/local/bin which is not in the path of a headless bash. So I just made my rake task line in schedule.rb:
job_type :rake, "cd :path && PATH=/usr/local/bin:$PATH RAILS_ENV=:environment bundle exec rake :task :output"
I am successfully using whenever with RVM and bundler in production. Here are the relevant pieces of my capistrano setup that may help you:
# rvm and bundler integration
require 'rvm/capistrano'
require 'bundler/capistrano'
# RVM environment
set :rvm_ruby_string, "ruby-1.9.2#mygemset"
# crontab
set :whenever_roles, :cron
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require 'whenever/capistrano'
The :whenever_environment setting is because I am using a multi-stage deployment setup. You can ignore that or set it to a string that matches your setup if needed.
Most of this information can be found at the whenever github page under the "Capistrano integration" and "RVM Integration" section headers in the README.
I hope that helps.
I solved the problem about the same as Duke. Except I figure out that $PATH variable is not working for me.
sys_path = '/home/[user]/.rbenv/versions/[ruby_version]/bin'
job_type :runner, "cd :path && PATH=#{sys_path} bin/rails runner -e :environment ':task' :output"
job_type :rake, "cd :path && PATH=#{sys_path} :environment_variable=:environment bin/bundle exec rake :task --silent :output"
If none of these worked for you, try:
gem install rails
This did the job for me, hope it helps!

"uninitialized constant Encoding" using rvm, ruby 1.9.2, bundler and passenger

I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue.
I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions.
$ `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ `which bundle` -v
Bundler version 1.0.15
$ `which rails` -v
Rails 3.0.9
Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode method it:
NoMethodError: undefined method `encode' for "foobar":String
encode should be defined but it is not! Encoding is found if I try in irb:
$ irb
ruby-1.9.2-p180 :001 > Encoding
=> Encoding
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
=> "foobar"
But if I try using the rails console through bundle exec, Encoding is not found:
$ bundle exec rails c staging
Loading staging environment (Rails 3.0.9)
ruby-1.9.2-p180 :001 > Encoding
NameError: uninitialized constant Encoding
from /[REDACTED]/shared/bundle/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from (irb):1
ruby-1.9.2-p180 :002 > "foobar".encode('utf-8')
NoMethodError: undefined method `encode' for "foobar":String
Obviously the setup is not loading something correctly but I am not sure where to look to figure it out. What am I missing here?
UPDATE 6/19/2011
As Ryan Bigg pointed out, it is curious that the directory path for the gems is 1.8. However, running bundle exec shows that bundler is using the correct ruby and rails versions:
$ bundle exec which ruby
/path/to/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
$ bundle exec `which ruby` -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
$ bundle exec which rails
/path/to/shared/bundle/ruby/1.8/bin/rails
$ bundle exec `which rails` -v
Rails 3.0.9
Clearly something is wonky here… I just don't know what.
UPDATE 6/26/2011
Seamus asked for the $LOAD_PATH…
UPDATE 6/26/2011 (later)
Seamus asked for the Gemfile.lock and the pp ENV… In the ENV output, I found that the GEM_PATH was not correct. In my staging.rb environment file, I have:
GEM_HOME = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]"
GEM_PATH = "/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#[REDACTED]:/home/[REDACTED]/.rvm/gems/ruby-1.9.2-p180#global"
…which is obviously not being honored. Nowhere else in my code is there a mention of GEM_HOME or GEM_PATH
UPDATE 6/27/2011
Seamus asked for the .bundle/config contents…
UPDATED same idea (that GEM_HOME is messed up), but more suggestions
Your GEM_HOME is messed up, possibly because your PATH is messed up. You could try setting the following environment variable in your shell
$ export PATH=[your current path but with rvm's ruby 1.9 at the front]
Then run
$ bundle install
If that doesn't work, try also setting this in your shell
$ export GEM_HOME=[your ruby 1.9 gem home]
and then re-run
$ bundle install
New ideas from this answer: Using RVM, bundler does not install in proper gemset when gems are installed in a different ruby version

jruby pass jvm arguments to rake task

How do i pass jvm arguments like Xmx to a rake task in jruby?
Am using rvm and running the rake task "rake db:migrate".
Thanks!
Rather that put the entire path, if jruby is already the Ruby you're using (for example, with rvm) such that just typing rake would be using jruby, you can use a double dash to send the arguments to the jvm.
Examples:
bundle exec rake -- -J-Xmx1024m (if you're using bundler)
rake -- -J-Xmx1024m
Found it!
jruby -J-Xmx2048m -S /home/prats/.rvm/gems/jruby-1.6.1#myapp/bin/rake db:migrate