Running a cron job via Whenever gem where rake "ts:index" is set to run at a certain frequency, the sphinx_index.log is returning an odd error (the only info in the log):
Your Ruby version is 1.9.3, but your Gemfile specified 2.2.3
if bundle exec rake ts:rebuild is run on the server manually, the process executes properly. (I have yet to test whether the indexing does actually occur and picks up changes). The Ubuntu server does have 2.2.3 installed, though it may have had 1.9.3 natively installed.
Why is this occurring and what is its consequence?
It sounds like cron isn't picking up your preferred Ruby version. If you're using RVM, then https://stackoverflow.com/a/24092907/54500 might be helpful? I'm not sure what's needed for other Ruby version managers.
Pat's answer is the correct thread of investigation.
Ben Scheirman's solution works as described for applications using the whenever gem. To use the proper ruby versions, rbenv's shims folder needs to be declared to the PATH.
Related
Ubuntu 20 > Apache 2.4 > Passenger 6 > ruby 2.7.4 > Rails 6.1 > `ruby script`
I'm invoking a ruby script via backticks from within a Rails controller (and collecting a return integer).
In production, somwhere in this chain, something is insisting on trying to run the ruby script with ruby 2.7.0 (the native system version) and complaining that it should be 2.7.4 (which it should).
The Rails app itself runs fine until I invoke a script.
When invoking the script, Passenger (I think?) is logging in the Apache error.log with
/home/rcm/.rbenv/versions/2.7.4/lib/ruby/2.7.0/bundler/definition.rb:495:in `validate_ruby!':
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.4 (Bundler::RubyVersionMisMatch)
I have searched and tried numerous suggestions (most of which were already done).
All scripts use: #!/usr/bin/env ruby
$PATH includes /home/rcm/.rbenv/shims:/usr/local/sbin:... and the usual suspects (I see that's rather explicit with /home/rcm/.rbenv instead of ~/.rbenv --- does it matter?)
The apache .conf file has: PassengerRuby /home/rcm/.rbenv/versions/2.7.4/bin/ruby
I have .ruby-version files at every layer I can think of specifying 2.7.4
I have used rbenv to declare global 2.7.4.
I have updated bundler.
I have run bundle install.
Restarted apache, rebooted the system, etc.
I can't figure out where in the chain anything could be trying to run the script with 2.7.0.
It all works fine in dev mode on macOS and Ubuntu, and even works fine running the project in e -production mode with the built in Puma on both macOS and Ubuntu. Only in the full Apache > Passenger production mode is there a problem. So, I'm thinking it has to be Passenger that's confused, but it's running the Rails app itself just fine -- which makes me confused.
The screwy part is, this was all working fine, and "all of a sudden" I'm getting this failure. (No idea which bit I twiddled.)
Would appreciate any ideas to give me something new to chase. Thanks.
ruby is not necessarily the same as the ruby running Rails. It will run whatever the first one it finds in its PATH. Since this is running on a webserver, this will be different from the PATH of your own user.
Use bundle exec ruby to run the Ruby associated with the application.
The best thing to do is to not run a script, instead incorporate the script code as a class in your Rails project. This is faster and easier to test.
Forgive me if there's a duplicate, but I'm honestly not sure what to search for. I'm working on a project with Ruby on Rails, and I get this message when doing anything related (ie: rake, rails, rspec, etc.):
Your Ruby version is 2.1.5, but your Gemfile specified 2.2.3
Now, I've installed RVM and I can fix this issue by issuing the command
bash --login
edit for clarity
running the above command does use Ruby 2.2.3 to execute the commands.
/edit
Then those given commands work. What I would like to do is to remove version 2.1.5 entirely -- leaving only 2.2.3. I've gone about this so many different ways, but Ruby is pretty foreign territory to me so I'm not sure what to do about this. I'm sure I have at least three installations of Ruby on my machine - possibly two duplicates of the two versions I know I have - and I would like only one version and to avoid needing to enter the bash --login command in order to run my project.
I'm running Ubuntu 15.10 and have at least some knowledge of how this works. If somebody could walk me through removing everything related to Ruby & Ruby on Rails, then installing only Ruby 2.2.3 and Rails 4.2.4, I would greatly appreciate that. Let me know if this isn't the proper exchange for this question. It didn't quite seem to fit into Ubuntu or Sysadmin.
What you need to do is not try to remove ruby 2.1.5.
You have RVM, so, use that to get the new version you want.
After this, you now have two options:
1) make the newly installed version the global default version on your machine,
or
2) create a gemset for your project, and specify the needed ruby version for the project.
Either of these will fix your problem.
You have to modify the Gemfile.
http://bundler.io/v1.3/gemfile_ruby.html
What does this mean? Is my system set for UTF when it should be ASCII or something?
This problem has been nagging me on one of my machines for the past year, and I only solved it just now. The machine in question is an old ASUS laptop running 32-bit Ubuntu 12.04, Ruby 1.9.3, and RVM. I had the same problem running gem update, but only with rake 0.8.7
Sadly, I'm a bit of a newb at this stuff, so I can't quite work it all out, but I ran into two separate issues - inability to update rake beyond 0.8.7, and inability to get the documentation to process correctly. The second problem is the more difficult to understand, but, as I understand it, it results from one particular version of rdoc relying on SourceIndex, which was deprecated in November, 2011.
Both problems are gem-related - character sets in the OS, to name one potential cause, don't seem to be an issue. As best as I can tell, my version of the problem was that my paths weren't correctly set to update the gem program. I'd type "gem update --system" from the prompt and gem would tell me that it was up-to-date, but rake wouldn't update and the characters wouldn't be correctly installed in the documentation for rake, either.
In retrospect, what apparently happened was that the path was set up so that gem update would affect a different version of Ruby than the one I was using under RVM. So, the key is to update the gems you're using by running the update program without having to rely on the path.
The solution has four parts. The first is to uninstall rake.
The second is to update the gems (this also makes it possible to update rake). Usually, this can be done by just typing gem update --system Since I'm using RVM, I did this by going into ~/.rvm/gems/ruby-1.9.3-p194/bin and ran update_rubygems. I suspect that my system fell out of configuration between the path and multiple versions of Ruby. By going directly to the ~/.rvm/gems/ruby-1.9.3-p194/bin directory and running the update_rubygems command,the system was able to update both the correct rdoc gem so it correctly translated the characters, and the correct rake gem, both of which are gems in the rvm-managed version of Ruby.
The third stage is to reinstall rake.
The fourth is the usual suite of testing and hygiene commands - gem clean, gem update, gem list, etc.
I regret not having a better handle on this, but hope this helps.
says if i develop a Ruby on Rails application using Rails 2.3.2, will that usually be compatible with Passenger on my hosting company?
If i ssh to my hosting company and type rails -v, i get 2.2.2... so looks like they might be using Rails 2.2.2.
So if i develop a Rails app on my Macbook and ftp all files over there, will the Passenger there usually work well with the generated code with the current version of Rails?
Freeze rails into vendor/rails using the built in rake task. That way your app will ue the version of rails you want it to no matter where you deploy it.
rake rails:freeze:gems
And the easiest way to do a specific version I know of.
rake rails:freeze:edge RELEASE=2.3.2.1
Now your version of rails will go with you where you send your app.
You can unpack other gem dependencies into vendor/gems for any gem you are using and want to be sure that it is available where ever you deploy the application.
rake gems:unpack
And to ensure their dependencies go to:
rake gems:unpack:dependencies
I would also suggest that you verify that they are running the latest version of passenger.
I would verify the version of Passenger they have installed (or confirm they have it installed at all). I would also suggest you freeze your version of Rails.
Just second something for railsninja's answer .
First say, it won't work straightaway.
Is that host a vps to you or have sudo access somehow?
If yes, I suggest you to do rake gems:install instead of gems:unpack, because some of gems are os dependent e.g (Rcov, RedCloth...etc.)
I will ask the hosting company of their passenger's configuration, the important question will be if they use RailsSpawnMethod: smart or smart-lv2(default).If they use the smart method, then it is a better idea to freeze your gems and rails otherwise will have the compatible issue as you can find reference from passenger user manual about the RailsSpawnMethod.
It will be nearly 100% compatible if you freeze your gems(all the gems need to be declared correctly in the environment.rb with config.gem, e.g(config.gem 'will_paginate',:source=>"http://gems.github.com")) and RAILS!!!!!
Having the same problems as this post, except I don't think the solution is the same unfortunately.
I'm getting this error message:
Rails requires RubyGems >= 0.9.4. Please install RubyGems
when I run a script/runner job in Cron, but it works perfectly fine when I run it in a terminal on the same server.
The rails server also runs fine. I only have trouble running script/runner's in cron. It seems to want to have a terminal attached...
Try which ruby and which gem from your cron job and also from the terminal. Are you accessing different binaries? You didn't mention which OS and which shell, but you may have a different $PATH when running headless.
The selected answer is completely correct, but something I'd suggest is to NOT use script/runner. The resources required to load the entire stack of your rails application is pretty intense for something to run regularly.
In my past experience, any cron jobs generally only have to deal with data (as opposed to say, generate static files, etc). In this case, you can very simply just load your models up, and since you've written your models the correct way (fat models), you can easily do your data processing with a few model methods.
Of course, all the above depends completely on your task, so take it with a grain of salt :)
I suppose this was a sort of answer to a problem that may not exist, and wasn't asked here, but just thought I'd throw my two cents in ;)
You wouldn't happen to be working on OSX? You should be installing a newer ruby rails and gems off macports instead. Google for the instructions...
As indicated by earlier posts, your Cron is using a different gem command source — also try which gem and gem -v. You may have a library set in your .bash_profile (or similar shell configuration or perhaps by other means, setting proper Ruby/Rails environment (i.e., Locomotive or other all-in-one environment).
To update your gem setup:
gem update --system
More information here - http://www.rubygems.org/read/book/1