Setting an environment variable

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting an environment variable

Håvard Olerud Eriksen
I'm currently in the process of migrating a Jetty system to a new computer
and I've run into problems getting Jetty to serve Perl scripts that use
Sybase::CTlib.
The error message that I'm getting is:
Can't load
'/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/Sybase/CTlib/CT
lib.so'
for module Sybase::CTlib: libct_r.so: cannot open shared object file:
No such file or directory at
/usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
 at scriptname.cgi line 16
Compilation failed in require at scriptname.cgi line 16.
BEGIN failed--compilation aborted at scriptname.cgi line 16.
HTTP ERROR: 500
Failed to exec CGI
RequestURI=/cgi/ledger_rules.cgi

I know that this error occurs when the environment variable LD_LIBRARY_PATH
is not set as I got the same problem when running the Perl script from the
command line earlier.
After reading through some old posts ("CGI problem with inet_aton()") from
the mailing list as well as the FAQ on CGIs, I found out that environment
variables can be set via the <Put name="ENV_*" attribute. I've tried this,
however, but the variable doesn't seem to "stick", ie. I still get the same
error. I've also tried this:

<Call name="addContext">
    <Arg>/cgi/*.cgi</Arg>
    <Arg><SystemProperty name="LD_LIBRARY_PATH"
value="opt/sybase/OCS-12_5/lib" /></Arg>

but then the logger tells me that:
java.io.IOException: Jetty configuration problem:
org.xml.sax.SAXParseException: Attribute "value" must be declared for
element type "SystemProperty".

Is there anyone out there able to help me? I've been stuck with this for a
while now and I'm starting to go nuts :-)

Cheers,
Håvard



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Setting an environment variable

Anthony Cook-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Greetings,

See below...

Håvard Olerud Eriksen wrote:
| The error message that I'm getting is:
| Can't load [needed lib.so file...]
| I know that this error occurs when the environment variable
| LD_LIBRARY_PATH is not set as I got the same problem when running the
| Perl script from the command line earlier.
|

How is your Jetty started, by script?  If so, then you can try adding a
line like the following to your Jetty start script:

...
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sybase/OCS-12_5/lib
...

If the above doesn't help, then add the above line to the .bashrc file
of the user which runs Jetty; i.e. if a user 'jetty' runs the server and
has its home dir at $JETTY_HOME then add the above line to
$JETTY_HOME/.bashrc.

Alternatively, add the needed directory to all users' lib path by either:

A) create a login profile script which does the above and place it under
/etc/profile.d/jetty.sh; or

B) add the above directory to the /etc/ld.so.conf file.

| <Call name="addContext">
|     <Arg>/cgi/*.cgi</Arg>
|     <Arg><SystemProperty name="LD_LIBRARY_PATH"
| value="opt/sybase/OCS-12_5/lib" /></Arg>
|

There are several things incorrect with the above.  First, note again
that the Jetty configuration spec is a thin wrapper around the Jetty
API: meaning the above is analogous to calling the following in a Java app:

...
org.mortbay.http.HttpServer server = new org.mortbay.http.HttpServer();
String virtHost = "/cgi/*.cgi";
String contextPath = System.getProperty( "LD_LIBRARY_PATH",
"opt/sybase/OCS-12_5/lib" );
server.addContext( virtHost, contextPath );
...

The method 'addContext' takes as parameters the name of the "virtual"
(or real) host that will service the request, and the path that will
serve as the context root.  In this case, you're passing what should be
the context path as the host part, and the value bound to the Java
system property "LD_LIBRARY_PATH" as the context path.

However, your use of the SystemProperty tag presupposes to /set/ the
system property, rather than retrieve it as the above code snippet does.

Refer to the HTTP 1.1 protocol specification, and the Java and Jetty API
docs for further details.

| but then the logger tells me that:
| java.io.IOException: Jetty configuration problem:
| org.xml.sax.SAXParseException: Attribute "value" must be declared for
| element type "SystemProperty".
|

Correct, because the use of SystemProperty in your configuration is
incorrect.  As shown above, the SystemProperty tag is a wrapper around
the Java method System.getProperty.  This method allows for a 'default'
value to be provided in case the property is not found in the system
properties object.  This again is a 'getter' and not a 'setter'.
Therefore, there is no "value" attribute defined for the tag in the
Jetty configuration DTD.  Though, there is a /'default'/ attribute
defined for it, and which more closely (and correctly) matches the Java
API call which the tag wraps.

| Is there anyone out there able to help me? I've been stuck with this for a
| while now and I'm starting to go nuts :-)
|

Hopefully, the above helps. :)

| Cheers,
| Håvard
|

Regards,

Anthony
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCsEMw8KND+nha8AoRAmOZAJ0eqUYnNq4ZpdmeYKtrduh34mzmZACghDi8
mCPHHt14KVF/QFzWgIZryI0=
=nvq/
-----END PGP SIGNATURE-----


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

RE: Setting an environment variable

Håvard Olerud Eriksen
Thanks for a long and informative reply Anthony.

>
> How is your Jetty started, by script?  If so, then you can
> try adding a line like the following to your Jetty start script:
Yes, it is started by a jetty.sh script.

>
> ...
> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sybase/OCS-12_5/lib
> ...
>
> If the above doesn't help, then add the above line to the
> .bashrc file of the user which runs Jetty; i.e. if a user
> 'jetty' runs the server and has its home dir at $JETTY_HOME
> then add the above line to $JETTY_HOME/.bashrc.
>
> Alternatively, add the needed directory to all users' lib
> path by either:
>
> A) create a login profile script which does the above and
> place it under /etc/profile.d/jetty.sh; or
>
> B) add the above directory to the /etc/ld.so.conf file.


Thanks. I've now tried to add it to the script, as well as .bashrc for the
user who runs jetty. I've also tried to add it to /etc/profile and to the
/etc/ld.so.conf file you mentioned. Just for good measure I restarted the
server as well, but still no dice.



> Correct, because the use of SystemProperty in your
> configuration is incorrect.  As shown above, the
> SystemProperty tag is a wrapper around the Java method
> System.getProperty.  This method allows for a 'default'
> value to be provided in case the property is not found in the
> system properties object.  This again is a 'getter' and not a
> 'setter'.
Right, I've misunderstood it then. Thanks for clearing it up!


> Hopefully, the above helps. :)

It certainly cleared a lot up for me in regards to how jetty works but I'm
still stuck :-(
Is it possible to change the CGI.java file and add an
env.set("LD_LIBRARY_PATH", "/path");?

Cheers,
Håvarfd



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Setting an environment variable

Anthony Cook
Håvard Olerud Eriksen wrote:
> Thanks. I've now tried to add it to the script, as well as .bashrc for the
> user who runs jetty. I've also tried to add it to /etc/profile and to the
> /etc/ld.so.conf file you mentioned. Just for good measure I restarted the
> server as well, but still no dice.
>

Odd.  Adding it to ld.so.conf should definitely have made it [globally]
available. :-/  Is that library on your new system and in the path
specified?  Does your Jetty run in a 'chroot' environment?

> It certainly cleared a lot up for me in regards to how jetty works but I'm
> still stuck :-(
> Is it possible to change the CGI.java file and add an
> env.set("LD_LIBRARY_PATH", "/path");?
>

That's why they call it "open source". ;)  Though, the CGI servlet
already supports doing this as initParams (which, in retrospect is what
you actually wanted to do ':-) ):

...
<Put name="ENV_LD_LIBRARY_PATH">[needed-lib-load-path]</Put>
...

The CGI servlet interprets anything beginning with 'ENV_' as an
environment variable setting.  This is passed to 'exec' stripped of the
leading 'ENV_'.  See the Jetty FAQ and apidoc for further details.

If this still fails then I suppose the tedious comparing between the
working system and the failing one to find what's missing (or just
amiss), is in order. :(

> Cheers,
> Håvarfd
>

Regards,

Anthony

vschade.vcf (226 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Setting an environment variable

Metal Fatigue
>>>>> "A" == Anthony Cook <[hidden email]> writes:

A> Odd.  Adding it to ld.so.conf should definitely have made it
A> [globally] available. :-/

You have to add it to /etc/ld.so.conf *and* run /sbin/ldconfig (which
updates the binary cache file, /etc/ld.so.cache, based on the
configuration in /etc/ld.so.conf).  Didja maybe forget that?

--
Seth Blumberg, a.k.a. Metal Fatigue, a.k.a. Nodens <[hidden email]> O-
-  --  ---  -----  --------  -------------  --------  -----  ---  --  -
"Faced with the prospect of rereading this book, I would rather have my
 brains ripped out with a plastic fork."           -- ZDnet book review


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Setting an environment variable

Anthony Cook
Metal Fatigue wrote:

>>>>>>"A" == Anthony Cook <[hidden email]> writes:
>
>
> A> Odd.  Adding it to ld.so.conf should definitely have made it
> A> [globally] available. :-/
>
> You have to add it to /etc/ld.so.conf *and* run /sbin/ldconfig (which
> updates the binary cache file, /etc/ld.so.cache, based on the
> configuration in /etc/ld.so.conf).  Didja maybe forget that?
>
Yep, forgot to inform that.  However, when he rebooted his 'server' --
which I took to mean the 'host system' -- the cache would have been
updated automatically during init. ;)


vschade.vcf (226 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Setting an environment variable

Metal Fatigue
>>>>> "A" == Anthony Cook <[hidden email]> writes:

A> However, when he rebooted his 'server' -- which I took to mean the
A> 'host system' -- the cache would have been updated automatically
A> during init. ;)

Good point.

--
Seth Blumberg, a.k.a. Metal Fatigue, a.k.a. Nodens <[hidden email]> O-
-  --  ---  -----  --------  -------------  --------  -----  ---  --  -
"Now, of course, this is so wrong as to be bordering on the criminally
 negligent (not for nothing is MS sometimes known in France as
 'Crimosoft')."                      -- Nick Brown <[hidden email]>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support