Not quite a rails question but can anyone advise?


#1

Hey guys!

I’m having a little trouble trying to integrate RMagick with my rails
app.

In the online terminal (on my host’s server) if I write:

export “LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH” before
opening the rails console then I can require “RMagick” no problem.

Without adding usr/local/lib to the LD_LIBRARY_PATH I get the error
message described here:
http://rmagick.rubyforge.org/install-faq.html#loaderror

My question is - where can I edit the LD_LIBRARY_PATH to make this
change permanent - at the moment it only works as long as I’m using
the online terminal window?

Thanks

Gavin


#2

added

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

to my .bash_profile file

Seems to have done the trick.

:slight_smile:


#3

Gavin M. wrote:

added

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

to my .bash_profile file

Seems to have done the trick.

:slight_smile:

I’d revisit that if I were you. In the final deployment, you are likely
going to run the server as someone other than you. And, the .profile is
not always pulled in either.

Before the require, I’d try putting:

ENV[‘LD_LIBRARY_PATH’]="/usr/local/lib:#{ENV[‘LD_LIBRARY_PATH’]}

Perhaps put it in environment.rb


#4

Perry - didn’t realize I could set the environment variable in my app
like that

That’s a great help - thanks

-:slight_smile:

On Apr 20, 1:28 am, Perry S. removed_email_address@domain.invalid


#5

Actually - scrap that

I just tried adding ENV[‘LD_LIBRARY_PATH’]="/usr/local/lib:#{ENV
[‘LD_LIBRARY_PATH’]}"
to the environment.rb file

This doesn’t seem to work

I also added puts ENV[‘LD_LIBRARY_PATH’] to see if it recognised
LD_LIBRARY_PATH

This returned nil

Any ideas on how I can access this from the environment.rb file?

Also, could you please explain why adding the path to .bash_profile is
not best practice? This seems to do the trick, at least through the
console.

Thanks

On Apr 20, 1:28 am, Perry S. removed_email_address@domain.invalid


#6

That is why I have put it into my /etc/bash.bashrc file since it is
common to all users.


#7

Gavin M. wrote:

Actually - scrap that

I just tried adding ENV[‘LD_LIBRARY_PATH’]="/usr/local/lib:#{ENV
[‘LD_LIBRARY_PATH’]}"
to the environment.rb file

This doesn’t seem to work

I also added puts ENV[‘LD_LIBRARY_PATH’] to see if it recognised
LD_LIBRARY_PATH

I think that LD_LIBRARY_PATH is not loaded by the application itself,
but by it’s loader (part of the operating system). Setting this variable
when the application is already started doesn’t work. The loader should
be instructed to load certain libs which (afaik) can only be done by
setting the variable before you start the app. This can be done by
setting it from a .bashrc or .profile (depending on your shell). Note
that these scripts are only used when starting a login shell. A better
way would be to create a shell script that loads the libs first and then
starts your server.

Any ideas on how I can access this from the environment.rb file?

Also, could you please explain why adding the path to .bash_profile is
not best practice? This seems to do the trick, at least through the
console.

If it works, it works :slight_smile: But if you deploy it under a different user, it
breaks. E.g. if you deploy it with phusion passenger and apache, the
user that runs apache should have the path set. You could set this
globally in /etc/ld.so.conf.


#8

Wouter de Bie wrote:

Gavin M. wrote:

Actually - scrap that

I just tried adding ENV[‘LD_LIBRARY_PATH’]="/usr/local/lib:#{ENV
[‘LD_LIBRARY_PATH’]}"
to the environment.rb file

This doesn’t seem to work

I also added puts ENV[‘LD_LIBRARY_PATH’] to see if it recognised
LD_LIBRARY_PATH

I think that LD_LIBRARY_PATH is not loaded by the application itself,
but by it’s loader (part of the operating system). Setting this variable
when the application is already started doesn’t work. The loader should
be instructed to load certain libs which (afaik) can only be done by
setting the variable before you start the app. This can be done by
setting it from a .bashrc or .profile (depending on your shell). Note
that these scripts are only used when starting a login shell. A better
way would be to create a shell script that loads the libs first and then
starts your server.

Any ideas on how I can access this from the environment.rb file?

Also, could you please explain why adding the path to .bash_profile is
not best practice? This seems to do the trick, at least through the
console.

If it works, it works :slight_smile: But if you deploy it under a different user, it
breaks. E.g. if you deploy it with phusion passenger and apache, the
user that runs apache should have the path set. You could set this
globally in /etc/ld.so.conf.

LD_LIBRARY_PATH may not be resampled each time a library is loaded. I’m
not sure. The loader uses it but it gets it from the processes
environment. The question is when.

The definitive test is does it work after a reboot and the application
is automatically deployed by whatever scripts and daemons deploy it.

As mentioned, there is usually a script involved somewhere in that
process. I would add it to that script and keep that script somewhere
in the project (under the project’s SCM) so they are “tied” together.
The problem you are trying to solve by doing this is to leave yourself
bread crumbs so when it breaks again in the future, you can retrace your
steps and remember “Oh yea! I need to change my load path”

HTH


#9

Perry S. wrote:

LD_LIBRARY_PATH may not be resampled each time a library is loaded. I’m
not sure. The loader uses it but it gets it from the processes
environment. The question is when.

I read some articles about this and ld.so (normally linked by libc.so)
calls_dl_init_paths() when it’s initializing. After this, there are no
more calls to this function. The input is drawn from the environment and
/etc/ld.so.conf. There’s not a lot to do about this, other than setting
it before.
In the question above, I think it shouldn’t be a problem to include
/usr/local/lib in your /etc/ld.so.conf (you need root access of course).

Another dirty hack might be to set the LD_LIBRARY_PATH and then fork.
The new process should load the newly set path, but I’m not sure if you
want to fork a complete rails stack (I’ve done it in the past, but
doesn’t feel very right).


#10

Thanks wouter -

I get the feeling that adding it to the ld.so.conf path is the best
way to go.

… I’m just having trouble finding the thing!!!

I’m running on a shared host.

On my account I have a folder named “etc” but there’s no “ld.so.conf”
in it (I’ve checked the hidden files)

When I try “locate ld.so.conf” in the shell though, it returns

/etc/ld.so.conf
/etc/ld/so.conf.d

Any idea how I can access ld.so.conf and add the path to it?

Thanks

On Apr 20, 7:59 pm, Wouter de Bie removed_email_address@domain.invalid


#11

PS - although adding the path to .bash_profile works in the shell, it
doesn’t work when I start up my app using the facilities provided by
my host

-is that normal?

On Apr 20, 7:59 pm, Wouter de Bie removed_email_address@domain.invalid


#12

Gavin M. wrote:

PS - although adding the path to .bash_profile works in the shell, it
doesn’t work when I start up my app using the facilities provided by
my host

-is that normal?

That’s the kind of thing I was worried about. I would ask your hosting
site how to set the load path.


#13

I’ve been emailing them all night

Their offshore technical support team don’t seem to have a clue what
I’m talking about…

this is gonna be a long night!

Thanks for the help anyway guys
:S

On Apr 21, 1:24 pm, Perry S. removed_email_address@domain.invalid


#14

Okay - my hosting site have replied saying I should set the
LD_LIBRARY_PATH in the .bash_profile file.

As I explained earlier, this works fine when I’m in the console or
when I start rails manually from the remote shell

When I try to use their designated pane to start the app though, I get
the following error in my mongrel.log:

** Daemonized, any open files are closed. Look at log/mongrel.pid and
log/mongrel.log for info.
** Starting Mongrel listening at 0.0.0.0:12008
** Starting Rails with development environment…
/usr/lib/ruby/gems/1.8/gems/rmagick-2.9.1/lib/RMagick2.so:
libMagickCore.so.1: cannot open shared object file: No such file or
directory - /usr/lib/ruby/gems/1.8/gems/rmagick-2.9.1/lib/RMagick2.so
(LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
require' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:153:inrequire’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
active_support/dependencies.rb:521:in new_constants_in' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:153:inrequire’
from /usr/lib/ruby/gems/1.8/gems/rmagick-2.9.1/lib/RMagick.rb:11
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/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/
active_support/dependencies.rb:153:in require' from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/ active_support/dependencies.rb:521:innew_constants_in’

… etc

Anybody have any idea why this is?

Are there any other startup files I could try adding this to?

Ta

Gavin


#15

Gavin M. wrote:

libMagickCore.so.1: cannot open shared object file: No such file or
directory - /usr/lib/ruby/gems/1.8/gems/rmagick-2.9.1/lib/RMagick2.so
(LoadError)

Anybody have any idea why this is?

I bet if you look under a similar path except add in local you will find
the library you are trying to load.

The .bash_profile isn’t going to work and I’m disappointed they
suggested it.

One idea I had is to send them the error that you just pasted. They
should already have local/lib in the load path. Its just a matter of
finding someone who cares and is competent. Why have the RMagic code on
the system except for people to use. They must not know that people
can’t use it.

Are there any other startup files I could try adding this to?

I don’t know if this is going to work but poke around the site looking
for how and where to put an .htaccess file and then see if you can add
to the environment using Apache’s mod_env facility. This might happen
happen before Mongrel or Rails is launched.

http://httpd.apache.org/docs/2.2/mod/mod_env.html

Good luck


#16

Hey Perry

Managed to sort this out.

The solution was to add a symlink to “libMagickCore.so.1” in “/usr/
lib”.

Thanks a lot for your help

:slight_smile: