Bug 1465812

Summary: [GSS](6.4.z) standalone.bat restart EAP unexpectedly
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Hiroki Daicho <hdaicho>
Component: Scripts and CommandsAssignee: Radovan STANCEL <rstancel>
Status: CLOSED EOL QA Contact: Pavel Slavicek <pslavice>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.3CC: fnasser, pgier, pkremens, rstancel
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-19 12:47:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hiroki Daicho 2017-06-28 09:28:12 UTC
Description of problem:

By the following code in standalone.bat, domain.bat, EAP restarts unexpectedly when the ERRORLEVEL set more than 10.
> if ERRORLEVEL 10 goto RESTART

For example, when Shutting down Windows while EAP is running, exit code is set as 143 and EAP is restarted.
Originally, EAP expect 10 for restarting.
The value is defined as the following constant.
org.jboss.as.process.ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT

Version-Release number of selected component (if applicable):
6.x, 7.x

How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Hiroki Daicho 2017-06-29 08:23:08 UTC
After the java process shutting down, exit code is put into ERRORLEVEL.
According to the following code, if the ERRORLEVEL is set more than 10, 
the "IF statement" will be true.

If EAP is runnning on Windows shutting down, the java process is finished with return code 143.

- standalone.bat

:RESTART
if x%XLOGGC% == x (
  "%JAVA%" %JAVA_OPTS% ^
   "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^
   "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
      -jar "%JBOSS_HOME%\jboss-modules.jar" ^
      %MODULE_OPTS% ^
      -mp "%JBOSS_MODULEPATH%" ^
      -jaxpmodule "javax.xml.jaxp-provider" ^
       org.jboss.as.standalone ^
      "-Djboss.home.dir=%JBOSS_HOME%" ^
       %SERVER_OPTS%
) else (
  "%JAVA%" -Xloggc:%XLOGGC% %JAVA_OPTS% ^
   "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\server.log" ^
   "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
      -jar "%JBOSS_HOME%\jboss-modules.jar" ^
      %MODULE_OPTS% ^
      -mp "%JBOSS_MODULEPATH%" ^
      -jaxpmodule "javax.xml.jaxp-provider" ^
       org.jboss.as.standalone ^
      "-Djboss.home.dir=%JBOSS_HOME%" ^
       %SERVER_OPTS%
)

if ERRORLEVEL 10 goto RESTART

Comment 2 Hiroki Daicho 2017-06-30 01:35:18 UTC
According to following example, "IF statement" of windows batch doesn't mean "EQUAL" validation.
It runs as "ERRORLEVEL >= 0".

- example_if_statement.bat
@echo off
# failed to call wrong api. ERRORLEVEL will be set to 1.
call :aa
echo %ERRORLEVEL% 
if ERRORLEVEL 0 echo TRUE

- result
> 1
> TRUE

Comment 3 Hiroki Daicho 2017-06-30 06:47:53 UTC
- Reported case
 - When the OS shutting down during EAP is still running. (exit code 143)
 - Shutting down with Ctrl+C and answering No for question of "Terminate batch job <Y/N>?". (exit code 130)

- Workaround
change the IF statament in standalone.bat/domain.bat as follows.

if %ERRORLEVEL%==10 goto RESTART
or
if %ERRORLEVEL% EQU 10 goto RESTART