Bug 227354 - textproc/elasticsearch6 fails to start because java PATH from env is not passed to it
Summary: textproc/elasticsearch6 fails to start because java PATH from env is not pass...
Status: Closed Not A Bug
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Felder
URL: https://forums.freebsd.org/threads/te...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-04-07 21:07 UTC by Jamie Baxter
Modified: 2019-10-18 13:10 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (feld)


Attachments
Diff file for additions to elasticsearch.in to set & export JAVA_HOME (625 bytes, patch)
2018-04-07 21:07 UTC, Jamie Baxter
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jamie Baxter 2018-04-07 21:07:53 UTC
Created attachment 192319 [details]
Diff file for additions to elasticsearch.in to set & export JAVA_HOME

When elasticsearch6 is started from the rc.subr system on a default installation, it fails to initialize because the path for java (JAVA_HOME=/usr/local/openjdk8) is not passed to it (adding the path to /etc/profile does not work as rc does not import from profile).

JAVA_HOME can be added through an additional (but possibly less recognized) rcvar  ${portname}_env="JAVA_HOME=/usr/local/openjdk8", but even fresh installations would necessitate this call (there does not appear to be any documentation to suggest this fix).

It might be instead better to declare JAVA_HOME in the rc script similar to sysutils/logstash6 (which also depends on java/openjdk8 in a similar manner), where an rcvar declares a default JAVA_HOME & exports the value.

See attached diff for files/elasticsearch6.in as an example.
Comment 1 Mark Felder freebsd_committer freebsd_triage 2018-04-08 14:06:32 UTC
I can't reproduce this issue. On a clean FreeBSD 11.1-RELEASE install: 

pkg install elasticsearch6

edit elasticsearch.yml to your needs

sysrc elasticsearch_enable=YES

service elasticsearch start



This works for me on at least a dozen servers. I have no JAVA_HOME issues.
Comment 2 Jamie Baxter 2018-04-08 14:30:52 UTC
I get inconsistent results, apparently?

I have two boxes with 11.1-RELEASE-p6 (self-compiled GENERIC) that both reproduce this issue.
I also have a pair of Vultr instances with 11.1-RELEASE-p6 (both the same modified kernels) where one reproduces and the other behaves as you describe in comment #1.

I will try to dig further to find the difference.
Comment 3 Jamie Baxter 2018-04-08 21:53:32 UTC
So the one machine that properly starts elasticsearch is being provided a different $PATH variable than the non-starters.

All the failing instances have an env PATH=/sbin:/bin:/usr/sbin:/usr/bin:
The one working instance shows an env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin://bin

Having /usr/local/bin in PATH is sufficient because java/javavmwrapper provides the symbolic links in there to call java.
From my understanding, only /usr/sbin/service is declaring the environment for the rc.d scripts, and only provides /sbin:/bin:/usr/sbin:/usr/bin (this is the same on all four of my BSD machines):

# tail -n 11 /usr/sbin/service | head -n 6
for dir in /etc/rc.d $local_startup; do
	if [ -x "$dir/$script" ]; then
		[ -n "$VERBOSE" ] && echo "$script is located in $dir"
		exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $*
	fi
done

Is there another configuration file somewhere that can declare environment variables that are get incorporated here? I know /etc/profile is not invoked at all here, and I'm not sure where else to look just yet.
Comment 4 Jamie Baxter 2018-04-09 02:23:54 UTC
Found the (likely) responsible culprit: the one system that elasticsearch starts properly on without hacking still has csh as the root shell. All three other machines have had their root shells changed to bash.

Changing the root shell to either sh or bash breaks the script starting (they don't forward /usr/local/bin nor /usr/local/sbin into /usr/local/lib/elasticsearch/bin/elasticsearch), but csh and tcsh both work fine (they both pass /usr/local/bin & /usr/local/sbin just fine).
Comment 5 Jamie Baxter 2018-04-09 15:57:38 UTC
Full steps to reproduce on a fresh installation (both /bin/sh and /usr/local/bin/bash can elicit this in step 2):

# pkg install textproc/elasticsearch6
# chsh -s /bin/sh
# service elasticsearch onestart
Starting elasticsearch.
could not find java; set JAVA_HOME or ensure java is in PATH
/usr/local/etc/rc.d/elasticsearch: WARNING: failed to start elasticsearch
Comment 6 Mark Felder freebsd_committer freebsd_triage 2018-08-07 17:22:00 UTC
We concluded that this is expected behavior because the root shell was changed away from csh.
Comment 7 TAO ZHOU 2019-03-06 05:11:31 UTC
I had exactly the same problem.
Even though I am using bash on all machines, some work, other don't.
Fixed by adding
```
elasticsearch_env="JAVA_HOME=/usr/local/openjdk8"
```
to rc.conf
Comment 8 Pokemon 2019-04-06 07:31:56 UTC
MARKED AS SPAM
Comment 9 mzs_47 2019-10-18 13:10:46 UTC
(In reply to Jamie Baxter from comment #4)

Imo, this is not the case, I did not change the default shell of root(sh) and I observed the same issue.

I changed to csh( for command completion) and faced the same issue.

I had to used the tip in comment #7 as a workaround.

This is a bug for sure.