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.
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.
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.
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.
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).
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
We concluded that this is expected behavior because the root shell was changed away from csh.
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
MARKED AS SPAM
(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.