Can't use 'require' with mod_ruby?

When trying to execute this one line ruby cgi file with mod_ruby:

raise ‘postgres’ unless require ‘postgres’

I get this error to appear in Apache’s error_log

[Mon Sep 01 13:11:45 2003] [error] mod_ruby: error in ruby
/usr/www/apache/ruby/error_handler.rb:1: postgres (RuntimeError)
from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:70:in load' from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:70:inhandler’

When trying to execute this:

require ‘dbi’
conn = DBI.connect(‘dbi:Pg:site_db’,‘www’,’*****’)

I get:

[Mon Sep 01 13:13:11 2003] [error] mod_ruby: error in ruby
/usr/local/lib/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:109:in initialize': uninitialized constant DBI::DBD::Pg::Database::PGError (NameError) from /usr/local/lib/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:55:innew’
from /usr/local/lib/ruby/site_ruby/1.8/DBD/Pg/Pg.rb:55:in connect' from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:567:inconnect’
from /usr/local/lib/ruby/site_ruby/1.8/dbi/dbi.rb:367:in connect' from /usr/www/apache/ruby/error_handler.rb:7 from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:70:inload’
from /usr/local/lib/ruby/1.8/apache/ruby-run.rb:70:in `handler’

Presumably because it’s trying and failing to “require ‘postgres’” too.
Both work fine outside of mod_ruby. I thought that maybe it had
something to do with paths and permissions but I can require 'termios’
which is in the same place and has the same permissions as postgres.so.
I’ve also check the libs that postgres links to. They all have rx
permissions for all. Also I have set my safe level to 0 in the httpd.conf.

versions:
ruby-postgres-0.7.1
ruby-dbi-all-0.0.20
(PostgreSQL) 7.3.4
ruby 1.8.0 (2003-08-04) [i686-linux]
mod_ruby-1.0.6
Linux 2.4.20-13.9 #1 Mon May 12 11:03:52 EDT 2003 i686 athlon i386 GNU/Linux

Can anyone give me a hint or lead on this?

TIA,
Michael

Two things:

1)  mod_ruby keeps the same interpreter around for each invocation;
    you don't get a new one (so previously required stuff is still
    loaded)

2)  require returns false if you try and require something that's
    already been required

This should make what’s happening clear, I hope. :wink:

···

On Tue, 2 Sep 2003 04:25:04 +0900 mgarriss mgarriss@earthlink.net wrote:

When trying to execute this one line ruby cgi file with mod_ruby:

raise ‘postgres’ unless require ‘postgres’


Ryan Pavlik rpav@mephle.com

“Speaking in very broad terms… yes, your statement is correct.” - 8BT

Ryan Pavlik wrote:

···

On Tue, 2 Sep 2003 04:25:04 +0900 >mgarriss mgarriss@earthlink.net wrote:

When trying to execute this one line ruby cgi file with mod_ruby:

raise ‘postgres’ unless require ‘postgres’

Two things:

  1. mod_ruby keeps the same interpreter around for each invocation;
    you don’t get a new one (so previously required stuff is still
    loaded)

  2. require returns false if you try and require something that’s
    already been required

This should make what’s happening clear, I hope. :wink:

YES! I’m a bit slow sometimes, ugh, I need this kind of push every so
often. The postgres.so lib was linking to some pg libs that where
hidden to the world. I changed that awhile ago but never restarted
apache. Thank you so much!

Michael