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

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.

Related

jruby no such file to load application.rb

I have a project in jRuby that I try to run.
So I'm installling jruby using rvm like this
rvm install jruby-9.1.15.0 (bc thats the version required by the project)
then im making sure that im actually using jruby by typing
ruby -v which shows me that I have jruby
next thing, I want to run the rails server so I'm typing
bundle exec rails server
and unfortunately I get an error:
/Users/foouser/Documents/Projects/fooproject/bin/config/application
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/bin/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:5
I've tried googling that but to no avail. People seem to not encounter this issue at all. I'm sure it's got something to do with my setup because other people are successfully using said project.
Any ideas?
rails version - 4.2
jruby version - 9.1.15.0
EDIT:
after some digging, in bin/rails file the line defining the APP_PATH was like that:
APP_PATH = File.expand_path('../config/application', __FILE__)
which somehow made it looking for application.rb inside fooproject/bin/config instead of fooproject/config
but when I changed the line to
APP_PATH = File.expand_path('../../config/application', __FILE__)
it goes to the correct path where application.rb exist but still reports it as not existing.
the error is nearly the same (apart for path)
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:4
EDIT 2:
requested permissions for application.rb:
-rw-r--r-- 1 foouser staff 5818 20 Jun 15:12 config/application.rb
config.ru:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
So, the solution I have is the "have you tried to turn it off and on again?" type.
I have deleted the whole project and cloned it again from the repo.
Everything is working now, it must have been something with my local env but I can't tell what.
Anyway, if you ever encounter something similar - purge and clone is definitely something you can try.

Rails/Ruby/Postgres - LoadError cannot load such file -- pg_ext

I am trying to call a Ruby script (which connects to a postgres db) using the rails controller below, however it appears it is having problems loading one of the PG gem files. I have set my require statement to require 'pg' and tried the absolute path as well (require /usr/local/rvm/gems/ruby-1.9.3-p194#railsTest/gems/pg-0.14.0/lib/pg/). The file 'pg_ext' is in fact present in the directory. Additionally, I can run the ruby script standalone without any problems (dbrubyscript.rb), however when rails is added to this equation it craps out with a cannot load such file -- pg_ext error.
Any direction here would be much appreciated as I have not been able to find anything online that fixes this issue
Rails controller:
class TestdlController < ApplicationController
def runmyscript
load "/usr/local/rvm/my_app/ruby_scripts/reports/dbrubyscript.rb"
send_file '/usr/local/rvm/tmp/failedtests.csv', :type => 'text/csv', :disposition => 'inline'
flash[:notice] = "Reports are being processed..."
end
end
.rb file (dbrubyscript.rb) has the following:
require 'rubygems'
require 'pg'
connects to (production) database
#conn = PGconn.connect("zzzzz.test.prod", 5432,"","","yyyyy_prod" ,"postgres", "xxxxxx")
.....
Trace Error:
LoadError in TestdlController#runmyscript
cannot load such file -- pg_ext
Rails.root: /usr/local/rvm/my_app Application Trace | Framework Trace
| Full Trace app/controllers/Testdl_controller.rb:3:in `runmyscript'
This error occurred while loading the following files:
/usr/local/rvm/my_app/ruby_scripts/reports/dbrubyscript.rb
/usr/local/rvm/gems/ruby-1.9.3-p194#railsTest/gems/pg-0.14.0/lib/pg/
pg_ext
Try running ruby /usr/local/rvm/gems/ruby-1.9.3-p194#railsTest/gems/pg-0.14.0/lib/pg/ext/extconf.rb and see what errors you get. That helped me determine that in my case, my PostgreSQL client was too old. Your error may be different since you appear to have a current-ish versioninstalled.
I had the same problem.
I have a stand alone ruby script. It connects via pg to postgres and worked if I ran it directly from the shell.
If I tried to run it via rspec I get the Error cannot load such file -- pg.
Solved: The problem for rspec was, the pg gem was not defined in the Gemfile. After put pg into Gemfile, and retestet via rspec, it worked.
Try adding a line to your Gemfile:
gem "pg"
Then run bundler via the command line:
bundle install
Rails uses Bundler to manage your gems and dependencies. You can read a bit more about the idea behind Bundler here: http://gembundler.com/v1.2/rationale.html

"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

gem being loaded by script/console initialization, but not server initialization

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'

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