agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
Subject: [Pljava-dev] Setting environment for postmaster in init scripts
Date: Fri, 10 Jun 2005 12:35:53 -0400
Message-ID: <42A9C169.8040608@bonbon.net> (raw)

Hi all,
    I've been wanting to write up a few points I discovered in the 
process of trying to install PL/Java into postgres 7.4.

First, the easiest way to set LD_LIBRARY_PATH is by adding the paths to 
/etc/ld.so.conf, then running ldconfig.  More on why below.

I use Suse 9.x, which, like RedHat and others, uses  system of init 
scripts (Sys V style, I believe) to start services automatically on load. 

When you install Suse binaries (rpm's) for Postgres, an script is 
installed into /etc/init.d/postgresql to control startup.  The script 
(under Suse) sources the file /etc/sysconfig/postgresql, which you can 
use to set the CLASSPATH variable.

Within /etc/init.d/postgresql, a function called pg_ctl is defined, 
containing the variable CMD.  CMD is later executed inside an su 
command, which retains all environment variables EXCEPT those beginning 
with LD_ .  This is a security measure, to avoid pointing to non-system 
libraries in su commands.

Therefore a postmaster process started by this script will only 
recognize LD_LIBRARY path set either via ld.so.conf, or by changing the 
function pg_ctl to include an export statement before the command text:

pg_ctl () {
        CMD="/usr/bin/pg_ctl $@ --lsb"
        su - postgres -c " export LD_{add variables here} {and here};$CMD"
}

In my case, I ended up putting put all relevant variables inside this 
command:

pg_ctl () {
        CMD="/usr/bin/pg_ctl $@ --lsb"
        su - postgres -c " export 
LD_PRELOAD=/usr/lib/jvm/java/jre/lib/i386/libz
ip.so 
LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/i386:$JAVA_HOME/jre/lib/i386/client 
CLASSPATH=/usr/lib/postgresql/pljava/pljava.jar;$CMD"
}

This makes the postmaster aware of all variables describe in the PL/JAVA 
1.1 setup document.

I hope this is helpful.

Cheers,

Eric






Message-ID: <42A9C169.8040608@bonbon.net>
Permalink:  ../42A9C169.8040608@bonbon.net/
Also on:    postgresql.org/message-id/42A9C169.8040608@bonbon.net

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pljava-dev@postgresql.org
  Subject: Re: [Pljava-dev] Setting environment for postmaster in init scripts
  In-Reply-To: <42A9C169.8040608@bonbon.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox