Hosting Help- Custom Gems on DreamHost - ruby-on-rails

I am attempting to deploy a RoR app using Passenger onto my DreamHost hosting account, but am having trouble getting it up and running.
My application requires two custom gems 'amazon-ecs' and 'nokogiri.' As per the instructions on the DreamHost wiki (http://wiki.dreamhost.com/Freezing_Gems) I froze the gems to vendors by coding them into my config file (config.gem "nokogiri") and then used the rake gems:unpack command to build them into vendor.
I then froze the rails gems using rake rails:freeze:gems, and uploaded it to my subdomain.
The last seven lines of my backtrace go as follows:
0 /home/rclosner/demo.spubooks.com/vendor/rails/railties/lib/initializer.rb 336 in `abort'
1 /home/rclosner/demo.spubooks.com/vendor/rails/railties/lib/initializer.rb 336 in `check_gem_dependencies'
2 /home/rclosner/demo.spubooks.com/vendor/rails/railties/lib/initializer.rb 170 in `process'
3 /home/rclosner/demo.spubooks.com/vendor/rails/railties/lib/initializer.rb 113 in `send'
4 /home/rclosner/demo.spubooks.com/vendor/rails/railties/lib/initializer.rb 113 in `run'
5 ./config/environment.rb 9
6 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb 31 in `gem_original_require'
7 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb 31 in `require'
My config file looks like this:
RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.gem "nokogiri"
config.gem "amazon-ecs"
config.time_zone = 'UTC'
end
Did I miss a step with the gems? Am I on the right track?

Any gem that has native extensions can't be vendored with your app, and there's a good bet that on DH, config.gem won't work right either. You have to install your own rubygems and make your app use it. I recommend taking a look at this:
http://railstips.org/2008/11/24/rubygems-yours-mine-and-ours
It has great instructions for setting up your environment on DH. I just had to do this last week after a server upgrade, and it still applies.

so /vendor/rails and /vendor/plugins/nokogiri and amazon-ecs exist and look alright to you? You could try again and this time specifying the exact version of the gem in your config like this
config.gem "nokogiri", :version => "1.0"
or if the gem is on Github
config.gem "tenderlove-nokogiri", :version => "1.0", :lib => "nokogiri", :source => "http://gems.github.com"
The backtrace doesn't look very helpfull, what is going on exactly? :-)

I got the same backtrace (on a Passenger error page) with an app I deployed recently. It turned out that it wasn't able to find one of the gems I was depending on (config.gem)... despite the fact that rake gems said it was there ([I] test-unit = 1.2.3).
Dreamhost support suggested that I try freezing/unpacking my gems. That probably would have worked (it didn't have a problem finding any of my other gems, which were frozen), but for some reason rake gems:unpack wasn't doing anything for me, so I ended up just commenting out that config.gem line since I didn't need it in production anyway, and that worked!
So if anyone else is getting this error, it strongly indicates that one of your gems isn't being found. Try commenting out your config.gem lines, one at a time until it starts working or giving a different error?

I had an issue on DreamHost last week where my working Rails apps suddenly stopped working because of missing gems. I contacted support and here was their response:
It looks like some changes were made
to your server and most of the
system-installed rubygems were not
reinstalled like they should have
been. I manually installed the sqlite3
gem for you, but our admin who handles
this will have to take a look at this
to figure out why they weren't
installed. If you have a couple more
that you see not working I can look at
potentially installing them as a stop
gap in the mean time.
It's possible you're being affected by the same thing. Try contacting support to find out.

Related

Bundled Gems won't load libxml using the require parameter in rails 2.3.18

I'm currently moving a site onto bundler to make the gem requirements easier to manage, aid in deployment, and speed up developer setup. I'm running into one gem I can't seem to remove from the environment.rb file.
In environment.rb
config.gem 'libxml-ruby', :version => '1.1.4', :lib => 'libxml'
In Gemfile
gem 'libxml-ruby', '1.1.4', :require => 'libxml'
If I leave the reference in the environment.rb file everything works. I'd like to not have to leave that line though.
Note: the error I get if I don't leave it in environment.rb is
activesupport-2.3.18/lib/active_support/dependencies.rb:131:in `const_missing': uninitialized constant BaseSaxParser::XML (NameError)
Looking through the stack trace, it seems like a plugin "activemq_xml_parser.rb" is looking for it before it's loaded. Any thoughts on that?
Help is greatly appreciated!
note: I know specifying exact versions in the Gemfile isn't the best idea. My idea is to get it working, then tweak to clean things up.

Rails does not load gems from vendor/gems

I have strange old buggy project on Rails 2.
It have gem's dependencies in config/environment.rb like
config.gem "andand"
config.gem "json"
config.gem "chronic"
config.gem "mini_fb"
all those gems are located in vendor/gems/
andand-1.3.3/
chronic-0.6.7/
json-1.7.3/
mini_fb-1.1.7/
rbet-1.0.3/
redis-3.0.1/
responsys_client-0.0.1/
but when i start unicorn server with this app it always complain that it can't find this gems. Why?
UPDATE
After building and installing gem from vendor/gems rails still complain about it.
I have tweake mini_fb gem into custom mini_fb_custom gem. Changed all references in gemspec and other files from mini_fb to mini_fb_my, installed it and it is shown in gem list as mini_fb_my. But it fails to load from config/environment.rb and complains that
Missing these required gems:
mini_fb_my >= 0
maybe i should rename lib/mini_fb.rb to lib/mini_fb_my.rb
i'll check it.
UPDATE 2
Yes, renaming files rocks!
You still need to install them from those folders, or unicorn will not know where to look for them.
Just install the gems from that directory and unicorn should pick them up.
UPDATE
You can install your gems locally with this command
gem install --local vendor/gems/gem/gem-name.gem
On more recent versions of rails you just specify path on the Gemfile
gem "gem-name", path: "path/to/gem"
My advice: replace the obsolete gem configuration with bundler (it works fine with rails 2, there should be a tutorial for rails 2 available on their website).
Configuration through gem command, freezing gems, etc. is just pain in the a** and it seemed kinda buggy to me when I'd used it (long time ago).

How to freeze Facebooker gem?

I tried rake gems:unpack, it worked for most gems, but facebooker gem doesn't get frozen.
How to freeze it?
Thanks
The answer is simple...
Apparently when in your environment.rb you included several gems, and one of the gems is broken or included with wrong syntax (perhaps it needs lib options for example config.gem "ruby-openid", :lib => "openid") all the gems below that gem won't be unpacked. Funny though how Rails doesn't return an error when you ruby script/server it.

Unpacking gems [Rails 2.3.5]

I have the following gems defined in my environment.rb file:
config.gem "authlogic"
config.gem "paperclip"
config.gem "pauldix-feedzirra", :lib => "feedzirra", :source => "http://gems.github.com"
config.gem 'whenever', :lib => false, :source => 'http://gemcutter.org/'
I have them installed on my local computer and everything is working well.
Since I am working on a shared-server (DreamHost), I need to unpack those gems to get them to work (can't install them as I did on my own computer to get them to work).
Before uploading, I ran the following on my local machine:
rake gems:unpack
This created the following folders in /vender/gems:
authlogic-2.1.3, paperclip-2.3.1.1, pauldix-feedzirra-0.0.18, whenever-0.4.1
So it looks like they're all there.
When I run rake db:migrate on the server, though, I get these following error:
Missing these required gems:
pauldix-feedzirra
For some reason, the feedzirra unpacked gem is not detected. Could anybody offer a clue as to why this is happening and a potential solution?
Thanks!
EDIT: Thanks, but the code to put in environment.rb doesn't work, and bundler won't install properly on my server. Any other suggestions?
This isn't exactly an answer, but since I could never get config.gem to work properly, I recommend using Bundler whenever I can. It just works and it handles interdependencies between gems well. It also replaces config.gem in Rails 3 from what I understand.
I notice two things about feedzirra: first, it depends on 3 other gems, and at least one of those build native extensions. And I'm going to call it "feedzirra" - I'm not a fan of github's ill-considered autopackaging fiasco.
If it were only the former, then rake gems:unpack:dependencies would do the trick.
However, at least curb (which feedzirra depends on) is building extensions, and those can't simply be unpacked. You could either get Dreamhost to install them (good luck) or install them into your user's local gem directory.
To do that, you'll need to update your .gemrc and be sure that it includes a line like:
:user_install: true
Then rake gems:install
Unless your deployment environment won't let you build executables, in which case you'll need to shell out for a less restricted package - I know for a fact that Dreamhost does provide packages that will allow for extension-gems.
(And there's the separate issue of libcurl being deployed...)
Try Following.put this code in envoirment.rb
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end
Don't know if my hints are useful, because feedzirra is compiled extension (against CURL i think). Better solution is to normally install feedzirra gem (it will compile itself) on your server.
You have not installed (unpacked) feedzirra gem, but pauldix-feedzirra. Probably you need feedzirra unpacked too.
Try to add
config.gem feedzirra
into environment.rb and run locally
rake gems:install
rake gems:unpack
It looks like feedzirra unpacked gem is missing in /vendor/plugins. Look if feedzirra will be copied there after those commands...

Does Rails 2.3.4 by default hinder exceptions related to gems in development mode?

I have an app that I run in three different environments, so sometimes when I pull it from github, I'll get the default rails "Oops, there was a problem with the server" page instead of the stack trace page. This seems to only happen when there's a problem related to a gem.
I remember maybe 6 months or a year ago when developing, if I had a missing gem, it'd show me the no such file to load -- mysql stack trace page.
This is mostly out of curiosity, but this actually does slow me down a bit as I have to tail the log to find what's broke on me.
You should add your gems in your environment.rb file.
For example if your application requires redcloth, you add in the environment file (the global one or any environment specific one).
config.gem 'RedCloth',
:lib => 'redcloth',
:version => '>= 4.2.2'
Your application won't load until you install that gem. And it'll display you a message asking you to install it.
You'll find more informations here.
Which server are you using to run your app?
Passenger runs in production mode unless explicitly told otherwise in the passenger configuration.
Any chance either of these lines appear uncommented in config/environemnt.rb?
ENV['RAILS_ENV'] ||= 'production'
ENV['RAILS_ENV'] = 'production'

Resources