Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rApache not reading ldpaths #47

Open
jeroen opened this issue Jun 10, 2017 · 11 comments
Open

rApache not reading ldpaths #47

jeroen opened this issue Jun 10, 2017 · 11 comments

Comments

@jeroen
Copy link
Collaborator

jeroen commented Jun 10, 2017

Running Ubuntu 16.04 with r-cran-java. Loading rJavain the console works fine, but when loading it inside rApache on the same machine gives:

 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory

I think /usr/bin/R sources /usr/lib/R/etc/ldpaths which sets LD_LIBRARY_PATH to the path where libjvm.so lives (i.e. ${JAVA_HOME}/jre/lib/amd64/server) before starting the repl.

What would be the most natural way to do this accomplish the same thing in rapache? The problem is that ldpaths is a shell script which sets an environment variable, so calling this via system() does not work because that sets the LD_LIBRARY_PATH only in the system() subprocess.

@s-u
Copy link

s-u commented Jun 22, 2017

Ideally, you should use R CMD to setup the environment, so if let's say if you are running

sh startme.sh

then for Java to work you'd run

R CMD sh startme.sh

instead. Alternatively, whatever you're starting can use R CMD sh -c set to get all the necessary R environment variables.

@jeroen
Copy link
Collaborator Author

jeroen commented Jun 22, 2017

We should probably do this before our call to Rf_initEmbeddedR at https://github.com/jeffreyhorner/rapache/blob/master/mod_R.c#L973-L1010

@jeffreyhorner
Copy link
Owner

jeffreyhorner commented Jun 22, 2017

What's happening is that the linux service script(unity, init, system, etc.) ought to be amended to update the LD_LIBRARY_PATH (And other side effects of R CMD sh) prior to starting the server. Typically, the service script runs in a minimal environment.

I've known about this issue for a long time, but I'm not sure the best way to fix it.

@jeffreyhorner
Copy link
Owner

Here's a version of the init script that ultimately get's placed into /etc/init.d/apache2 on ubuntu:

http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/vivid/apache2/vivid/view/head:/debian/apache2.2-common.apache2.init

It references a file that's typically located at /etc/apache2/envvars

Maybe we need an additional config tool that outputs the side effects of R CMD sh and update that!

@jeroen
Copy link
Collaborator Author

jeroen commented Jun 22, 2017

Modifying global apache configs is difficult to setup and sound dangerous, especially if people are running other (non-R) websites on the same apache box.

Can we just output the variables we need to a file and run base::readRenviron() to source them? Or is there more to it than setting environment variables?

@jeroen jeroen closed this as completed Jun 22, 2017
@jeroen jeroen reopened this Jun 22, 2017
@jeffreyhorner
Copy link
Owner

You'll see in the /etc/init.d/apache2 script that the environment has to be set up at the invocation of apachectl. The facility for setting up that enviroment seems to be defined by the content of /etc/apache2/envvars, which would affect all the sites including non-R sites.

@jeffreyhorner
Copy link
Owner

jeffreyhorner commented Jun 22, 2017

Something like this would populate the R environment to /etc/apache2/envvars:

#!/bin/bash
# save this to /tmp/exportenv.sh
for i in `env`; do
   echo export $i
done

Then run

/usr/bin/env -i R CMD sh /tmp/exportenv.sh >> /etc/apache2/envvars

But this doesn't solve it completely as there are some env vars that contain spaces like:

LN_S=ln -s

So that shows up as two lines in the /etc/apache2/envvars like this:

export LN_S=ln
export -s

And then there are other strange env vars like:

export _=/usr/bin/env

@jeroen
Copy link
Collaborator Author

jeroen commented Jun 22, 2017

I really don't like hardcoding that stuff in /etc/apache2/envvars. It becomes a mess when you upgrade R and then need to re-do this stuff. I guess I need to hack a runtime solution.

@jeroen
Copy link
Collaborator Author

jeroen commented Jun 22, 2017

What I don't understand is what R CMD sh does beyond the things in /usr/lib/R/etc/ldpaths ?

@alexvpickering
Copy link

Just confirming that I was able to solve the same issue by adding export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/amd64/server (directory with libjvm.so - can differ) to /etc/apache2/envvars.

Another issue arose however from the same rJava-dependent function call (mailR::send.mail) which works fine as user www-data from the terminal. No response is received and the apache2 logs show:

[Sat Jan 20 08:03:11.177569 2018] [:error] [pid 3967:tid 140146487838464] [client 192.168.1.67:41784] rApache Notice! *** stack smashing detected ***: /usr/sbin/apache2 terminated [Sat Jan 20 08:03:11.932544 2018] [core:notice] [pid 24498:tid 140146758621056] AH00051: child pid 3967 exit signal Aborted (6), possible coredump in /etc/apache2

@jeroen
Copy link
Collaborator Author

jeroen commented Jan 25, 2018

@alexvpickering I have never seen this stack smashing detected error. If you can reproduce it you can open a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants