gem being loaded by script/console initialization, but not server initialization - ruby-on-rails

I'm moving a rails app from my desktop to a shared host, and I'm running into trouble with a gem dependency.
I have this declared in my environment.rb:
config.gem "icalendar"
When I first tried starting a console for the app, I got error messages requesting that I rake:install the gem. I used the shared hosting gem install process to install the gem in ~/ruby/gems and confirmed that the gem was there.
ls -rlt ~ruby/gems/gems/icalendar-1.1.0/
total 64
drwxr-xr-x 4 user user 4096 Dec 12 13:15 docs/
drwxr-xr-x 3 user user 4096 Dec 12 13:15 ../
drwxr-xr-x 5 user user 4096 Dec 12 13:18 test/
drwxr-xr-x 3 user user 4096 Dec 12 13:18 lib/
(I replaced the actual user/group here manually)
I then added this to my environment.rb:
ENV['GEM_PATH'] = "/home/USER/ruby/gems"
(Again, actual user replaced)
The next time I ran script/console, the app loaded fine. I then tried to start up the server, and got this error:
Missing these required gems:
icalendar
You're running:
ruby 1.8.7.22 at /usr/bin/ruby
rubygems 1.3.5 at /home/USER/ruby/gems, /usr/lib/ruby/gems/1.8
I tried tweaking the path a bit, but that didn't have any effect. I poked around a bit here and on google at large and didn't see anything that directly addressed this problem--I would think that the console and server would both use the GEM_PATH in the environment config. Doesn't look like a permissions issue either. Any ideas? Thanks for the help with this.

Be sure to set the environment variable before the initializer block:
ENV['GEM_PATH'] = '...'
Gem.clear_paths
Rails::Initializer.run ...

If you are using Passenger, you should use a small trick to get the GEM_PATH environment variable working.
Follow this tutorial.

in the similar situation (when the server started, some pathes were not included in LOAD_PATH variable)
adding
require 'rubygems'
before including other gems helped me.
or you can manually add path to your gem
$LOAD_PATH << '/home/USER/ruby/gems/gems/icalendar-1.1.0/lib'

Related

where's the Gemfile in a rails 1 application

Where's the Gemfile located in a rails version 1 application?
I looked in the root of the app, it has Rakefile but not Gemfile.
try searching for "gemfile" from your root folder. I have never used rails 1 before, so no idea!

ar_sendmail - "Could not find RubyGem cyu-ar_mailer" when it is installed

I'm trying to test emailing on our staging server. We use ar_sendmail and i'm sure it has worked on this server in the past. Now though it complains about a missing gem which is actually there:
$ sudo /etc/init.d/ar_sendmail start
Starting ar_sendmail: /usr/lib/ruby/1.8/rubygems.rb:827:in `report_activate_error': Could not find RubyGem cyu-ar_mailer (>= 0) (Gem::LoadError)
from /usr/lib/ruby/1.8/rubygems.rb:261:in `activate'
from /usr/lib/ruby/1.8/rubygems.rb:68:in `gem'
from /usr/local/bin/ar_sendmail:18
$ gem list | grep ar_mailer
cyu-ar_mailer (1.4.8.1, 1.4.7)
what-the? Anyone know what might be going wrong here? I tried reinstalling the gem just in case and get the same error. This is the content of the file which is blowing up (/usr/local/bin/ar_sendmail)
1 #!/usr/bin/ruby
2 #
3 # This file was generated by RubyGems.
4 #
5 # The application 'cyu-ar_mailer' is installed as part of a gem, and
6 # this file is here to facilitate running it.
7 #
8
9 require 'rubygems'
10
11 version = ">= 0"
12
13 if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
14 version = $1
15 ARGV.shift
16 end
17
18 gem 'cyu-ar_mailer', version
19 load 'ar_sendmail'
grateful for any advice - max
I fixed this by starting it like so:
/opt/ruby-enterprise-1.8.7-2010.02/bin/ruby /usr/local/bin/ar_sendmail -e staging -d --batch-size 100 --delay 150
where 'staging' is the name of my staging environment. I think that it wasn't getting the right environment before which is why it was blowing up thinking the gem wasn't there.

"uninitialized constant Etc" when running Ruby application

A few applications on my server relying on Ruby and Ruby On Rails seem to have stopped working. Or atleast partially so. I managed to get the web gui of the application in question to start functioning again by reinstalling different part of Ruby. But I most likley broke something else in the process.
I have managed to track it down using some tests and it seems like Etc is somehow not found by the program when it runs.
I tested by
ruby -e 'puts Etc.getpwnam("apache").uid'
and got
uninitialized constant Etc
If I instead tested
ruby -r etc -e 'puts Etc.getpwnam("apache").uid'
I get the correct answer
48
This is running on an Amahi6 server (running Fedora Core 14 64bit).
Example on the code in question in the actual application that fails is
#!/usr/bin/env ruby
# Amahi Home Server
# Copyright (C) 2007-2010 Amahi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v3
# (29 June 2007), as published in the COPYING file.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# file COPYING for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Amahi
# team at http://www.amahi.org/ under "Contact Us."
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/runner'
require 'optparse'
# switch to apache:users first
uid = Etc.getpwnam("apache").uid
gid = Etc.getgrnam("users").gid
Process.gid = gid
Process.egid = gid
Process.uid = uid
Process.euid = uid
...
this fails with the same
uninitialized constant Etc
Clarification: I have NOT changed this code at all and it has worked in it's current state before
What could it be that I have messed up? :)
UPDATE:
Ruby installed now is version 1.8.7
UPDATE 2:
If I try to manually add a require for rubygems and etc it fails, but complains about another package. So I think there is something fundamentally messed up with the core of my ruby.
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55:
uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support.rb:56
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from
/usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record.rb:25
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
gem_original_require'
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from /var/hda/platform/html/script/install-app:70
Ended up being that the versions of rails and gems were to new. Downgraded to gems 1.3.7 and rails 2.3.8.
gem update --system 1.3.7
gem uninstall rails
gem install rails --version 2.3.8
You seem to be missing require 'rubygems' and require 'etc' (put them below require 'optparse')
remember about 'rubygems',
commandline:
ruby -rubygems -e 'puts Etc.getpwnam("apache").uid'
script:
require 'rubygems'
puts Etc.getpwnam("apache").uid

Rails/Passenger: no such file to load -- money (MissingSourceFile)

I am attempting to deploy a Rails application (which works fine in development) onto a production server. I have installed and configured Apache, Passenger, and the necessary gems. After I restart apache and navigate to the server, I get the following error:
Exception PhusionPassenger::UnknownError in PhusionPassenger::Railz::ApplicationSpawner (no such file to load -- money (MissingSourceFile))
gem list money shows:
*** LOCAL GEMS ***
money (3.0.5)
An irb session on the server:
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'money'
=> true
The gem is required in config/environment.rb:
require 'money'
What's going on here?
Edit: The gem was installed as root:
# ls -l /usr/lib/ruby/gems/1.8/gems/money-3.0.5/lib
total 8
drwx------ 2 root root 4096 Sep 2 10:26 money
-rw-r--r-- 1 root root 1284 Sep 2 10:26 money.rb
Edit 2: After having no success with that roadblock, I realized that Passenger is sort of made to go along with Ruby Enterprise Edition, so I tried installing that. Afterwards, I used Ruby Enterprise's version of gem to install all the required gems. Now when I restart apache and navigate to my server, I get:
Exception LoadError in PhusionPassenger::Railz::ApplicationSpawner (no such file to load -- logger)
I have no problem requiring logger in either the old or new versions of Ruby:
# which irb
/usr/bin/irb
# irb
irb(main):001:0> require 'logger'
=> true
irb(main):002:0> exit
# /opt/ruby-enterprise-1.8.7-2010.02/bin/irb
irb(main):001:0> require 'logger'
=> true
Something must be going on with paths or permissions, but I followed the instructions in both the Passenger and Ruby Enterprise Edition installers exactly. Any other ideas?
Apache/Passenger runs the ruby process as root (or www-data), make sure you didn't install the Gem in a local repository.
You probably need to become superuser before installing the gem.
Answer 2:
The correct way to require a Gem is not using require, but using
config.gem "money"
are you using the same version of ruby for both?
Thanks all for your help. We investigated some more and found some of the required files (the gems themselves, I believe) were installed with the wrong permissions (not readable by the user that runs Apache/Passenger). I'm not sure why that happened, as they were installed the normal way as root (maybe some non-standard umask was the issue?), but changing permissions on those files fixed the problem.

Hosting Help- Custom Gems on DreamHost

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.

Resources