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

windows elasticsearch.bat file has problems with certains paths #30606

Closed
Dobatymo opened this issue May 15, 2018 · 13 comments · Fixed by #39712
Closed

windows elasticsearch.bat file has problems with certains paths #30606

Dobatymo opened this issue May 15, 2018 · 13 comments · Fixed by #39712
Labels
>bug :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts Team:Delivery Meta label for Delivery team

Comments

@Dobatymo
Copy link

Dobatymo commented May 15, 2018

Bug report:

Elasticsearch version: 6.2.4
Plugins installed: None
JVM version: 1.8.0_171
OS version: Windows 10 (1511)

Description of the problem including expected versus actual behavior:

I cannot start elastic search using elasticsearch.bat.
The error message is: \Common was unexpected at this time.

Fix

%JAVA% is assigned C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe in elasticsearch-env.bat.
This breaks the last for loop in elasticsearch.bat. This can be fixed be changing it to

for /F "usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" ^|^| echo jvm_options_parser_failed`) do set JVM_OPTIONS=%%a

See also https://stackoverflow.com/a/30139757/

@Dobatymo Dobatymo changed the title windows file has problems with certains paths windows elasticsearch.bat file has problems with certains paths May 15, 2018
@cbuescher cbuescher added >bug :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts labels May 15, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@cbuescher
Copy link
Member

I found #28753 which might be related but that should have been fixed in 6.2.3. Not sure if this is a different issue.

@sathiql
Copy link

sathiql commented Jun 1, 2018

I had the same issue in windows
Added JAVA_HOME in Environmetn Variable --> System Variables section.
It worked

@Dobatymo
Copy link
Author

Dobatymo commented Jun 2, 2018

@sathiql JAVA_HOME is assigned, the problem is with the parentheses in the path. Does your path contain parentheses?

@Henr1k80
Copy link

Henr1k80 commented Jun 6, 2018

My Windows 10 with java SE x64 version 1.8.0_171-b11 running Elasticsearch 6.2.4 also had this problem
I added the fix to the bat file and it worked.
In my Path variable there is this path:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
which I guess is some kind of symbolic link folder to my current x64 java (special icon, only java, javaw and javaws exe). I think it is the culprit.
I have no JAVA_HOME and adding one did not help.

@lashchev
Copy link

lashchev commented Jun 11, 2018

Thanks, @Dobatymo for the fix! It works in general, but the result will be that only first option from jvm.options file will be picked up. Here is the updated version (with added delims= option) that picks all JVM options:

for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" ^|^| echo jvm_options_parser_failed`) do set JVM_OPTIONS=%%a

@lashchev
Copy link

Still the same issue in v6.3.0

Another issue that is in the elasticsearch.bat is just 2 lines above "for /F". It starts with set "ES_JVM_OPTIONS=
It has double quotes between "set" and variable name. These quotes are not really needed because in the command below that variable is enclosed in the quotes anyway.
So, the full working snippet that works for me looks like the following

set ES_JVM_OPTIONS=%ES_PATH_CONF%\jvm.options
@setlocal
for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_JVM_OPTIONS!" ^|^| echo jvm_options_parser_failed`) do set JVM_OPTIONS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%JVM_OPTIONS%" & set ES_JAVA_OPTS=%JVM_OPTIONS:${ES_TMPDIR}=!ES_TMPDIR!% %ES_JAVA_OPTS%

@PhaedrusTheGreek
Copy link
Contributor

PhaedrusTheGreek commented Aug 14, 2018

This is reproducible in Windows Server 2016 when JAVA_HOME has parenthesis, like in Program Files (x86).

LeeDr pushed a commit to LeeDr/elasticsearch that referenced this issue Sep 5, 2018
@SreekanthPuj
Copy link

SreekanthPuj commented Oct 9, 2018

I've resolved this with the below two steps on Windows 10 - 64 bit machine using Command Line Installer for ElasticSearch 6.4.2

  1. Added an environment variable JAVA_HOME to the System Environment varaibles.

  2. In the ElasticSearch.bat
    replace

for /F "usebackq delims=" %%a in (`"%JAVA% -cp "!ES_CLASSPATH!" blah blah

with

for /F "usebackq delims=" %%a in (`"!JAVA! -cp "!ES_CLASSPATH!" blah blah

it worked like a charm for me...

PS:
The startup then hit an issue:
[2018-10-09T18:20:49,158][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [Sree_Cluster1_node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: ElasticsearchException[X-Pack is not supported and Machine Learning is not available for [windows-x86]; you can use the other X-Pack features (unsupported) by setting xpack.ml.enabled: false in elasticsearch.yml]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]

This one got resolved by adding xpack.ml.enabled: false to the elasticsearch.yml

@SreekanthPuj SreekanthPuj mentioned this issue Oct 9, 2018
SreekanthPuj added a commit to SreekanthPuj/elasticsearch that referenced this issue Oct 9, 2018
pgomulka added a commit that referenced this issue Apr 2, 2019
the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes #38578
closes #38624
closes #33405
closes #30606
pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Apr 3, 2019
…39712)

the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes elastic#38578
closes elastic#38624
closes elastic#33405
closes elastic#30606
pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Apr 4, 2019
the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes elastic#38578
closes elastic#38624
closes elastic#33405
closes elastic#30606
pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Apr 4, 2019
the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes elastic#38578
closes elastic#38624
closes elastic#33405
closes elastic#30606
pgomulka added a commit that referenced this issue Apr 5, 2019
…40768)

the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes #38578
closes #38624
closes #33405
closes #30606
backports:
* Bat scripts to work with JAVA_HOME with parentheses(#39712)
* Link to SYSTEM_JAVA_HOME on windows (#40806)
@jaiswarvipin
Copy link

Hi All,
if your java is installed under C:\Program Files (x86) then set the JAVA_HOME like will below

set JAVA_HOME=C:\Progra~2\Java\jre1.8.0_131

if your java is installed under C:\Program Files then set the JAVA_HOME like will below
set JAVA_HOME=C:\Progra~1\Java\jre1.8.0_131

After that try to start the elastic search, it should start then.

Thanks & Regards
Jaiswar Vipin Kumar R

gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this issue May 27, 2019
the elasticsearch.bat and elasticsearch-env.bat won't work if JAVA
contains parentheses. This seems to be the limitation of FOR /F IN
(command) DO syntax.
The JAVA variable present in a command contains a path to a binary to
start elasticsearch (with spaces & parens). We can workaround the
problem of spaces and parentheses in this path by referring this
variable with a CALL command.
Note that executing binaries with CALL is an undocumented behaviour (but works)
closes elastic#38578
closes elastic#38624
closes elastic#33405
closes elastic#30606
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
@hap2y1122
Copy link

I had the same issue in windows
Added JAVA_HOME in Environmetn Variable --> System Variables section.
It worked

I did the same but it won't work

@hap2y1122
Copy link

after hours my conclusion of those whose elasticsearch.bat file not opening

  • First go to edit environment variables
  • Go to system variables section
  • Add a new path or edit the old java home path to >> JAVA_HOME or ES_JAVA_HOME : the current java path till jdk-{version}
  • Add it
  • Then go to path and double click
  • Edit the path till bin this time

Do these you elasticsearch.bat file not opening will be solved.

@vancleimatheus
Copy link

vancleimatheus commented Sep 8, 2021

Very late to the party but I would add some more comments for someone that might be here in the future:

  • in addition to checking JAVA_HOME environment variable, be sure it points to a valid location, even though java is working on my machine I'm not sure why JAVA_HOME was set to an older version
  • be sure JAVA_HOME doesn't include \bin, the script will include the \bin
  • I believe the changes made by @pgomulka are not included on packages for older versions, it would be nice if it was possible to include these changes.
  • Either way, I edited elasticsearch.bat to include @pgomulka changes and it worked fine

just my 2cents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts Team:Delivery Meta label for Delivery team
Projects
None yet