[SRU] R_HOME environmental variable not set

Bug #130059 reported by Lance Rushing
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
plr (Debian)
Fix Released
Unknown
plr (Ubuntu)
Fix Released
Undecided
Martin Pitt
Dapper
Fix Released
Undecided
Unassigned
Edgy
Fix Released
Undecided
Unassigned
Feisty
Fix Released
Medium
Unassigned

Bug Description

When installing postgresql-8.1-plr on fiesty (other releases/plr versions??) the R_HOME environmental variable is not set in /etc/postgresql/version/cluster/environment.

Usually setting R_HOME is not a big deal, as one can put it in /etc/profile, or ~postgres/.bashrc, etc.

But the init.d scripts are using pg_ctlcluster when starting postgres. And, after many hours of searching, I found that pg_ctlcluster clears the environment variables.

From a change log I found:
"""
 * Support auxiliary environment variables for postmaster:
     - pg_createcluster: Create /etc/postgresql/version/cluster/environment
       file (empty, just a comment).
    ...
     - pg_ctlcluster: Clear environment and only set variables mentioned in
       environment file and LANG/LC_ALL.
"""

=======================

Step to reproduce:
1) Make sure postgres is started
 $ /etc/init.d/postgresql-8.1 start

2) create a test database
 $ sudo -u postgres createdb plr_test

3) setup R functions
 $ sudo -u postgres psql plr_test < /usr/share/postgresql/8.1/plr.sql

4) create a user function that calls R
 $ sudo -u postgres psql plr_test
 plr_test=# CREATE OR REPLACE FUNCTION test() RETURNS text AS 'return ()' LANGUAGE 'plr' IMMUTABLE STRICT;
 CREATE FUNCTION

5) call the function
 plr_test=# select test();
 ERROR: environment variable R_HOME not defined
 HINT: R_HOME must be defined in the environment of the user that starts the postmaster process.

=======================

To fix: Add a "R_HOME = '/usr/lib/R' " to /etc/postgresql/version/cluster/environmen

Example Fix for version 8.1:
 $ sudo -s
 # echo -e "\nR_HOME = '/usr/lib/R'" >> /etc/postgresql/8.1/main/environment
 # exit

To Test:
 $ sudo /etc/init.d/postgresql-8.1 restart
 $ sudo -u postgres psql plr_test
 plr_test=# select test();
  test
 ------

 (1 row)

Revision history for this message
Luca Falavigna (dktrkranz) wrote : Re: R_HOME environmental variable not set

Confirmed in Gutsy, Feisty, Edgy, and Dapper.

Dapper version requires additional love:
root@gandalf:/# sudo -u postgres psql plr_test < /usr/share/postgresql/8.1/plr.sql
SET
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: function plr_call_handler() does not exist
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: relation "plr_environ_type" already exists
ERROR: could not load library "/usr/lib/postgresql/8.1/lib/plr.so": libR.so: cannot open shared object file: No such file or directory
ERROR: function plr_environ() does not exist
ERROR: relation "r_typename" already exists
ERROR: language "plr" does not exist
ERROR: language "plr" does not exist
We need to use fix from http://bugs.debian.org/360796.

Changed in plr:
status: New → Confirmed
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Attached debdiff for Gutsy should fix this.

NOTE: you will have to install plr build-dependencies to regenerate source package.

Revision history for this message
Barry deFreese (bddebian) wrote :

This looks clean enough but you might want to ping Martin Pitt (pitti) since he appears to be the maintainer. Thanks for the patch!

Revision history for this message
Daniel Holbach (dholbach) wrote :

Martin: can you check this one out?

Changed in plr:
assignee: nobody → pitti
Revision history for this message
Martin Pitt (pitti) wrote :

This is not quite sufficient, I'm afraid. You cannot assume that there is only one 8.2 cluster, and that it is called 'main'. That is the default after a clean installation, but people are free to create arbitrarily many clusters.

So you should iterate over "pg_lsclusters -h" to find out valid cluster versions and names, and do the R_HOME thing for all of them.

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Thanks for your feedback, Martin.
I attach a new debdiff which should cover your suggestion.

Revision history for this message
Martin Pitt (pitti) wrote :

Luca,

thanks, this already looks better. Still some issues:

 * The postinst loop does not check whether R_HOME is already set. So every installation or upgrade of plr would add another R_HOME to the file, and this would even override an admin's setting which points to somewhere else.

 * The postrm loop will fail and bail out if the environment file does not exist (which is legitimate).

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Again, thanks for the feedback and sorry for bothering you more than necessary :)

Revision history for this message
Martin Pitt (pitti) wrote :

OK, seems I still managed to overlook some things, and there are some new issues:

 * The grep and thus the postinst will fail if 'environment' does not exist.
 * stylistic: IMHO this would be easier to read: if ! grep -q "^R_HOME" /etc/postgresql/$cluster/environment
 * The postrm should do cleanup only on "purge", not on the other actions; in particular, doing it on "upgrade" is actively wrong.

Please see http://www.debian.org/doc/debian-policy/ch-maintainerscripts.html for details.

Thanks for bearing with me!

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

New debdiff should fix some issues. I've also added another switch which creates environment file if not present.

Sorry for the delay and thanks for your patience.

Revision history for this message
Martin Pitt (pitti) wrote :

Luca,

that patch looks good now, thank you!

Dirk just made a good point in the corresponding Debian bug. It is probably much easier to hardcode that value as a fallback in the plr source itself than to muck around with the environment file.

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

It could be a better solution, lesser code required and no risks to have problems in postgresql.
I will try to find a solution this way in the next days. Thank you for pointing this out.

Changed in plr:
status: Unknown → New
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Attached debdiff implements the above solution.

Revision history for this message
Martin Pitt (pitti) wrote :

Luca, that looks good. I just fixed the indentation and used simple-patchsys.mk (I like cdbs better than dpatch). I uploaded a new Debian revision with that fix and synced it to Gutsy.

Thank you!

Revision history for this message
Martin Pitt (pitti) wrote :

plr (1:8.2.0.1-2) unstable; urgency=low

  * Move packaging to cdbs.
  * Add debian/patches/R_HOME_default.patch: Fall back to /usr/lib/R if R_HOME
    is not defined. This is pretty much a constant in Debian and Ubuntu, and
    doing it with an implicit default is much more elegant than hacking in
    configuration files. Thanks to Luca Falavigna for this patch!
    Closes: #439270 and LP: #130059

 -- Martin Pitt <email address hidden> Fri, 24 Aug 2007 17:42:15 +0200

Changed in plr:
status: Confirmed → Fix Released
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Thanks Martin!
What about SRUs? Do you think it's worth to manage them?

Revision history for this message
Martin Pitt (pitti) wrote :

Luca,

yes I think this would make a fine SRU. I guess the patch will more or less apply to previous versions, too, but there are some different build systems, etc. For SRUs, please do not introduce dpatch, just apply it inline. Please attach debdiffs for dapper and feisty, I will review them and sponsor if necessary. (NB that I'm on honeymoon for the next 14 days, though, so please poke cjwatson for approval and #ubuntu-motu for sponsoring).

Thanks a lot!

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

I fear I can't just apply this fix inline because source files are into a tarball and they are uncompressed at build time.
I'm not aware of a solution without using a patch system, even a homemade one.

Revision history for this message
Martin Pitt (pitti) wrote :

Ah, I see. You need to apply the patch in debian/rules then, no problem.

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Debdiff for feisty-proposed.

Changed in plr:
status: New → Confirmed
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Debdiff for edgy-proposed.

Changed in plr:
status: New → Confirmed
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Debdiff for dapper-proposed.

Changed in plr:
status: New → Confirmed
Changed in plr:
status: New → Fix Released
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks. Feisty looks good. For Dapper and Edgy, please revert the Maintainer: change (that hasn't been tested with dapper/edgy package tools).

For Dapper: Please give a rationale and a bug number for the rpath addition in the changelog.

Changed in plr:
importance: Undecided → Medium
status: Confirmed → In Progress
Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Debdiff for edgy-proposed after Maintainer change removal.

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Debdiff for dapper-proposed after Maintainer change removal and changelog integration.

For my reference: while preparing SRU proposals, is XSBC-Original-Maintainer required for Feisty and newer only?

Revision history for this message
Martin Pitt (pitti) wrote :

debdiffs look good now, thank you! Please upload.

> while preparing SRU proposals, is XSBC-Original-Maintainer required for Feisty and newer only?

Right.

Revision history for this message
Martin Pitt (pitti) wrote :

I sponsored the uploads and accepted them to {dapper,edgy,feisty}-proposed. Please go ahead with QA testing.

Changed in plr:
status: In Progress → Fix Committed
status: Confirmed → Fix Committed
status: Confirmed → Fix Committed
Revision history for this message
doogers (weliback) wrote :

"Fix tested succesfully on Dapper, Edgy and Feisty

Revision history for this message
Remo Quintino (remoquintino) wrote :

Works for me too on dapper, edgy and feisty. Bye

Revision history for this message
Luca Falavigna (dktrkranz) wrote :

Seven days testing period elapsed and two persons confirmed the fix is good on each version.
Tagging with verification-motu-done as per https://wiki.ubuntu.com/MOTU/SRU.

Revision history for this message
Martin Pitt (pitti) wrote :

Copied to {dapper,edgy,feisty}-updates.

Changed in plr:
status: Fix Committed → Fix Released
status: Fix Committed → Fix Released
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.