Cannot run Unicorn with Ruby 2.0 - ruby-on-rails

On my ubuntu machine, I can run unicorn on ruby 1.9.3, however, it does not seem to work with ruby 2.0. Any idea why?
root#dev:/home/karan# rvm use 1.9
Using /usr/local/rvm/gems/ruby-1.9.3-p429
root#dev:/home/karan# unicorn -v
unicorn v4.6.3
root#dev:/home/karan# rvm use 2.0
Using /usr/local/rvm/gems/ruby-2.0.0-p195
root#dev:/home/karan# unicorn -v
/usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- unicorn/launcher (LoadError)
from /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /usr/bin/unicorn:3:in `<main>'

Try reinstalling the gem with 2.0.0.
The problem must have been caused by the fact the gem was installed in 1.9.3.

I have the exact same problem when I try to start Unicorn server
Starting Unicorn web server unicorn
/usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- unicorn/launcher (LoadError)
from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/bin/unicorn:3:in `<main>'
Nevertheless, Unicorn works fine when I run it from the rails app folder, simply using "unicorn" command.
I have tried what you suggest, installing the gem unicorn
gem install 'unicorn'
But it does not change the result
I check what gem is installed:
which gem 'unicorn'
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
/usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn
I am running unicorn from a etc/init.d script that you can see here:
http://pastebin.com/qvwdmRJ2
and here for the default configuration:
http://pastebin.com/84FBQjMp
There seems to be some problem with the PATH of the default configuration file:
PATH=/usr/local/rvm/rubies/ruby-2.0.0-p353/bin:/home/unicorn/.rvm/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:$
Because since I updated it with the new installed version I get the error message shown at the top. If I remove it, Unicorn "apparently starts" but the log shows a crazy activity and nginx shows an empty screen.
I am trying to find a solution and will share it here as soon as I find it.
Thanks for your help
* UPDATE *
OK I have found the problems:
1) for the /etc/init.d script:
You need to create a wrapper for Unicorn to work in a init.d type of script:
rvm wrapper 2.0.0 ruby-2.0.0 unicorn
then replace the line
DAEMON=/usr/bin/unicorn
with this one:
DAEMON=/usr/local/rvm/bin/ruby-2.0.0_unicorn
And now the command
service unicorn start
more on rvm wrapper here: https://rvm.io/integration/init-d
2) I also had another issue that was difficult to identify in the log:
I had not created a config/environments/staging.rb file

Related

You have already activated unicorn 5.2.0, but your Gemfile requires unicorn 5.3.0

I have an application running remotely, and I just upgraded rails to version 4.2.8, which upgraded other gems as well. I ran service unicorn restart afterwards, but the log for unicorn gives me this error:
You have already activated unicorn 5.2.0, but your Gemfile requires unicorn 5.3.0. Prepending bundle exec to your command may solve this. (Gem::LoadError)
I have tried gem uninstall unicorn -v 5.2.0, which returned successfully, and then gem install -v 5.3.0, which also returned successfully. Afterwards, I ran service unicorn restart, but the error persists.
I noticed the bundle exec suggestion, but I'm not sure what I should prepend this command to.
Try deleting your gemfile.lock file, and then running bundle install again, which will repopulate it from scratch, that normally sorts out my gem conflicts.
That means that the version of unicorn running on your machine is different than the version specified in your application. service unicorn is probably pointing to unicorn installed on the server/computer not pointing to your apps version of unicorn, right? Then when that starts your application, your app is trying to load a different version of the gem.
You could also run unicorn within the context of your app, like bundle exec unicorn - How to start rails server in production mode using unicorn and config file?.
If you have found a solution, good. If not, next time, create a new rails app using a unique gemset like 2.3.1#myapp.
This way, when you deploy to a remote server you will avoid this type of gems conflicts.
This could be caused by you having two different sources for gems on your machine.
If you use something like RVM with gemsets, make sure you are using the correct gemset. Especially, be sure that your gem install and gem uninstall act upon the application-sepcific gemset and not on the system-wide gems. You can find details at https://rvm.io/gemsets.
Bundler also generates a separate gemset per application. So if you use bundler, you have to run all your commands by prepending them with bundle exec (e.g. bundle exec rspec spec). If you want to remove gems from the bundle, remove it from your Gemfile and run bundle update gem_in_question afterwards (this will also update your Gemfile.lock). You can find more at http://bundler.io/v1.14/guides/using_bundler_in_application.html#executing-commands---bundle-exec.
I hope that this helps to solve your problem.

Rails deployment Capistrano - capistrano/cli (LoadError)

I followed this tutorial.
https://gorails.com/deploy/ubuntu/14.04#capistrano
Now i am stuck at this
I ran this command after set Adding The Nginx Host
cap production deploy
and ran into this, now no idea what to do.
/home/deploy/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- capistrano/cli (LoadError)
from /home/deploy/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/bin/cap:3:in `'
I solve this problem by remove old Capistrano gem.
# remove all old versions of the gem
gem cleanup rjb
I have the same error and it's because I installed this Gem and upgraded my ruby from 2.0.0 to 2.1.9. Reinstallation resolves my issue.
Hope this can help you.
If you still have this problem, I highly recommend you use bundler and
bundle exec cap <args>

Can't launch rails app via unicorn due to kgio_ext (LoadError)

I am trying to run a rails app via
unicorn -c config/environments/<env>/unicorn.rb -e <env>
but I keep getting this error.
<app_root>/vendor/bundle/ruby/1.9.1/gems/kgio-2.7.4/lib/kgio.rb:21:in `require': cannot load such file -- kgio_ext (LoadError)
Any ideas?
I am running unicorn (4.3.1) with kgio (2.7.4) in a rails (3.2.3) app.
Are you running on a Mac with Lion or Mountain Lion? If so, make sure you have the entire xcode installed, not JUST the command line tools. KGIO requires this. After that, be sure to run bundle install.
In my case the problem was that i updated rvm and the unicorn couldn't find so files.
I deleted the gemset and created a new one and after bundle install everything worked.
Looks like you are using Ruby 1.9.1, may be incompatible. Try switching Ruby version.
I had the same issue and it seems that Bundler with RVM is not integrating well with gems that use native extensions. I've changed to Thin and hit a similar issue with eventmachine. My question for unicorn here and Thin here
I've worked around the problem with the solution in my Thin question.
Regards,
Nuno Valente.

Installing a forked github gem of Toto

Ok, this is probably simple, but I'm having a bit of a pain trying to get it to work.
So I was using the gem "Toto", which I installed using "sudo gem install toto", but I recently found a fork of the gem I would rather use here https://github.com/evaryont/toto.
I tried specifying the gem url with --source, but I guess github doesn't support gems anymore aside from "the list". I then tried downloading the forked source and running "rake build" and "rake install" which seemed to create a gem just fine, but when I plug it back into the same application which comes with the gem, it fails to load.
It dies like this.
computer:myblog User$ thin start -R config.ru
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- toto (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from config.ru:2
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/rack-1.3.0/lib/rack/builder.rb:51:in `initialize'
from config.ru:1:in `new'
from config.ru:1
Sample Toto Application
git clone git://github.com/cloudhead/dorothy.git myblog
I'm also a little discouraged about building the gem like this because I'm hosting on Heroku, and I would like to make sure that I can use this gem on there as well. I suppose I may have to unpack this gem and commit it to my source?
Update
I also tried using bundler with the following in my Gemfile, and I get the same error, would this mean its just an incompatibility in the sample code and the forked gem?
gem "toto", :git => "git://github.com/evaryont/toto.git"
Are you running in a context where the gem exists? Bundler handles :git-installed gems by cloning the source and storing it in a special directory for bundled gems. It's not actually installed to your system, and won't run unless bundler is running first.
Try this:
bundle exec thin start -R config.ru

Rails 2.x mongrel won't start after upgrading to rails 3. -- mongrel_rails (MissingSourceFile)

After upgrading my Rails install to Rails 3 on OS X, I’ve had problems running my Rails 2.x development sites with Mongrel. WEBrick seems to work, but I really would like to have the nice output of Mongrel for debugging.
After running $ script/server I get this:
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load': no such file to load -- mongrel_rails (MissingSourceFile)
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'
So far, here’s what I’ve tried:
$ sudo gem update system
$ sudo gem update
$ sudo gem uninstall mongrel
$ sudo gem install mongrel --include-dependencies
$ which mongrel_rails
→ /usr/bin/mongrel_rails
$ mongrel_rails start
→ Success, but no stdout
$ which mongrel_rails
→ /usr/bin/mongrel_rails
$ rails _2.0.2_ test
→ Fresh application has same problem.
OS: OS X.6.x
Rails: 3.0.5 (problems are with Rails 2.x apps)
gem -v: 1.6.1
Mongrel: mongrel (1.1.5)
I’ve read EVERY Google result on "-- mongrel_rails (MissingSourceFile)"; there aren’t many.
Can anyone here tell me how to proceed in debugging this? Thanks!
UPDATE:
I’ve now tried installing older versions of the gem and specifying those in my Rails 2.x site’s config/environment.rb file. I’ve tried 1.1.5, 1.1.4, and 1.2.0pre.
None of these makes the slightest bit of difference.
Since the executable in in usr/bin I’m wondering if it’s a file ownership issue that got screwed up on my Rails 3 install and if one of the files isn’t getting my paths when it runs?
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb
is owned by admin / root, so that should be OK, right?
Could it be a problem with active_support!?
Here’s the code from dependencies.rb that’s throwing the error:
484 class Object
485
486 alias_method :load_without_new_constant_marking, :load
487
488 def load(file, *extras) #:nodoc:
489 Dependencies.new_constants_in(Object) { super(file, *extras) }
490 rescue Exception => exception # errors from loading file
491 exception.blame_file! file
492 raise
493 end
...
This is getting a file not found error, so it’s not looking where I know the file to be…
Running mongrel_rails on command line works…
Which mongrel_rails shows it in usr/bin,
So what’s the problem?
I have got the same problem and found the reason.
This happens because new version of RubyGems(1.6.2) does not add 'any_gem/bin' to ruby load path ($LOAD_PATH) when you require "any_gem".
For example in RubyGems version = 1.4.1 this works fine. After I require 'mongrel' I can see in load path next:
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/bin
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext
With new version (1.6.2) I can see only:
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext
That's why ruby cannot find 'mongrel_rails'.
You need to add "/usr/bin" to your load path. Perhaps something broke in it?
The best way to fix it is to add:
$:.push("/usr/bin/")
Somewhere before it breaks. Probably by itself in a config/preinitializer.rb file if you don't have one.
OK, here's ONE answer. I got mongrel to boot...but it's hacky, and doesn't solve the real problem...but at least for NOW I can get back to work on this project.
Here's what I did...YES..it's HACKY.
I edited the file throwing the error...dependencies.rb
I added a hook to call out the specific path to mongrel rails if that was the file it was trying to load.
def load(file, *extras) #:nodoc:
if file == "mongrel_rails"
file ="/usr/bin/mongrel_rails"
end
Dependencies.new_constants_in(Object) { super(file, *extras) }
rescue Exception => exception # errors from loading file
exception.blame_file! file
raise
end
Again, I would really like to fix the underlying problem here...but this at least let me boot up.
I would definitely look in to using RVM for running multiple gem versions simultaneously locally. I ran into a lot of quirks when I was attempting to run multiple versions like you are with sudo gem installs of everything.
Now it's as simple as rvm ree#my_app_1, and installing completely separate gems there, then switching to a different app and using rvm ree#my_app_2
ree is an alias for my install of ruby enterprise version, you could just as easily do it with ruby 1.9, 1.8.x, etc.
In each of my application's root directories I have a .rvmrc file that reads simply:
rvm ree#my_app --create
So that every time I switch to that directory, the gemset is automatically swapped for me.
I wasn't aware there was Rails 3 mongrel support.
Most people use Thin (you can enable it by specifying gem 'thin' in your Gemfile then launching rails server thin / Webrick these days.
If this is for hosting then there's nginx and Passenger that'll help with that.
I ran into the same problem -- got my app going by running "mongrel_rails" from the project directory (instead of "script/server").
This is the thread where you are able to find the best answer to the mongrel_rails (MissingSourceFile) error. I just want to conclude here how I solved the problem, using stuff in this thread.
The simplest solution I could figure out how to do was to downgrade RubyGems by typing
(sudo) gem update --system 1.4.1
This lets me run the old 2.1.0 app (thanks Max Shytikov), but there's probably a lot of bugfixes that I'm missing by running the old version of rubygems. The error is probably a blunder by the mongrel gem developers (I guess).
Anyway if you just want to run your app using mongrel do it like this. If you insist on having the newest version of rubygems, you can just run your app with
script/server webrick
But I've found that webrick is a fair bit slower, so I prefer mongrel. If anyone has got a better solution for this problem, please let me know.
I ran into the same error. The fix is to add the mongrel "bin" directory to the $LOAD_PATH. Other posts describe how to do it by modifying source code, but since I share source code with other developers, I prefer to set the RUBYLIB environment variable instead.
$ export RUBYLIB=/Users/edwingo/.rvm/gems/ruby-1.8.7-p302#junction/gems/mongrel-1.1.5/bin
This causes the MRI ruby runtime to prepend that to the $LOAD_PATH.
Detailed explanation: MRI is unable to find 'mongrel_rails' because it is not on the $LOAD_PATH. I am using RVM and when I installed mongrel into a gemset, for some reason the $LOAD_PATH does not include the corresponding "bin" directory where 'mongrel_rails' lives. When not using RVM and after installing mongrel into the system gems, the "bin" directory does appear on the $LOAD_PATH so it all works.

Resources