forked from JATOS/JATOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.bat
More file actions
228 lines (186 loc) · 6.12 KB
/
loader.bat
File metadata and controls
228 lines (186 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
@REM JATOS loader for Windows
@setlocal enabledelayedexpansion
@echo off
rem IP address and port (DEPRECATED - use 'conf/jatos.conf' instead)
set address=127.0.0.1
set port=9000
rem Don't change after here unless you know what you're doing
rem ###################################
if "%JATOS_HOME%"=="" (
set "APP_HOME=%~dp0"
rem Also set the old env name for backwards compatibility
set "JATOS_HOME=%~dp0"
) else (
set "APP_HOME=%JATOS_HOME%"
)
set "APP_LIB_DIR=%APP_HOME%\lib\"
set LOCAL_JRE=jre\win64_jre
rem Detect if we were double clicked, although theoretically A user could
rem manually run cmd /c
for %%x in (!cmdcmdline!) do if %%~x==/c set DOUBLECLICKED=1
if _%DOUBLECLICKED%_==_1_ (
call :start
exit
)
rem # If we were started from CMD, evaluate start parameter
if "%1"=="start" (
call :start %*
exit /B 0
) else if "%1"=="stop" (
call :stop
exit /B 0
) else (
@echo "Usage: loader.bat start|stop"
exit /B 0
)
exit /B 0
rem ### Functions ###
:start
rem # Check if JATOS is already running
wmic process where "name like '%%java%%'" get commandline | findstr /i /c:"jatos" > NUL && (
echo JATOS already running
if _%DOUBLECLICKED%_==_1_ pause
goto:eof
)
rem # If there is an old RUNNING_PID file of an earlier JATOS run that wasn't orderly closed delete it
IF EXIST "%JATOS_HOME%\RUNNING_PID" (
del "%JATOS_HOME%\RUNNING_PID"
)
echo Starting JATOS ... please wait
rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config.
set _JAVA_OPTS=%JAVA_OPTS%
if "!_JAVA_OPTS!"=="" set _JAVA_OPTS=!CFG_OPTS!
rem We keep in _JAVA_PARAMS all -J-prefixed and -D-prefixed arguments
rem "-J" is stripped, "-D" is left as is, and everything is appended to JAVA_OPTS
set _JAVA_PARAMS=
set _APP_ARGS=
rem # Generate application secret for the Play framework
rem # If it's the first start, create a new secret, otherwise load it from the file.
IF NOT EXIST "%JATOS_HOME%\play.http.secret.key" (
set rand=%RANDOM%%RANDOM%%RANDOM%%RANDOM%%RANDOM%%RANDOM%%RANDOM%%RANDOM%%RANDOM%
echo !rand!>"%JATOS_HOME%\play.http.secret.key"
)
set /p SECRET=<"%JATOS_HOME%\play.http.secret.key"
call :checkjava
if errorlevel 1 (
exit /B 1
)
if not exist "%JATOS_HOME%\logs" mkdir "%JATOS_HOME%\logs"
rem # Start JATOS with configuration file and application secret
set JATOS_OPTS=-Dconfig.file="conf/jatos.conf" -Djatos.secret=!SECRET! -Djatos.http.port=%port% -Djatos.http.address=%address% -Dfile.encoding="UTF-8"
if _%DOUBLECLICKED%_==_1_ (
set JATOS_OPTS=-Dpidfile.path="NUL" %JATOS_OPTS%
) else (
set JATOS_OPTS=-Dpidfile.path="%JATOS_HOME%\RUNNING_PID" %JATOS_OPTS%
)
set "APP_CLASSPATH=%JATOS_HOME%\lib\*"
call :process_args %SCRIPT_CONF_ARGS% %%*
set _JAVA_OPTS=--illegal-access=permit --add-opens java.base/java.lang=ALL-UNNAMED !_JAVA_OPTS! !_JAVA_PARAMS!
set "APP_MAIN_CLASS=play.core.server.ProdServerStart"
set CMD="%_JAVACMD%" !_JAVA_OPTS! !JATOS_OPTS! -cp "%APP_CLASSPATH%" %APP_MAIN_CLASS% !_APP_ARGS!
cd %JATOS_HOME%
%CMD% 2>&1
goto:eof
:stop
if not exist "%JATOS_HOME%\RUNNING_PID" (
echo This JATOS was not running
goto:eof
)
echo Stopping JATOS
set /p PID=<"%JATOS_HOME%\RUNNING_PID"
taskkill /pid %PID% /f
if errorlevel 1 (
del "%JATOS_HOME%\RUNNING_PID"
echo ...failed
) else (
del "%JATOS_HOME%\RUNNING_PID"
echo ...stopped
)
goto:eof
:checkjava
rem We use the value of the JAVACMD environment variable if defined
set _JAVACMD=%JAVACMD%
rem # Java's path can be defined in PATH or JAVA_HOME
rem # Don't confuse JAVA_HOME with JATOS_HOME
if exist "%JATOS_HOME%\%LOCAL_JRE%" (
set "JAVA_HOME=%JATOS_HOME%\%LOCAL_JRE%"
echo JATOS uses local JRE
)
if "%_JAVACMD%"=="" (
if not "%JAVA_HOME%"=="" (
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
)
)
if "%_JAVACMD%"=="" set _JAVACMD=java
rem Detect if this java is ok to use.
for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do (
if %%~j==java set JAVAINSTALLED=1
if %%~j==openjdk set JAVAINSTALLED=1
)
rem BAT has no logical or, so we do it OLD SCHOOL! Oppan Redmond Style
set JAVAOK=true
if not defined JAVAINSTALLED set JAVAOK=false
if "%JAVAOK%"=="false" (
echo.
echo A Java JDK or JRE is not installed or cannot be found.
echo.
echo Please go to
echo http://www.oracle.com/technetwork/java/javase/downloads/index.html
echo and download a valid Java JRE and install before running JATOS.
echo.
echo If you think this message is in error, please check
echo your environment variables to see if "java.exe" is
echo available via JAVA_HOME or PATH.
echo.
if defined DOUBLECLICKED pause
exit /B 1
)
exit /b 0
rem Processes incoming arguments and places them in appropriate global variables
:process_args
:param_loop
call set _PARAM1=%%1
set "_TEST_PARAM=%~1"
if ["!_PARAM1!"]==[""] goto param_afterloop
rem ignore arguments that do not start with '-'
if "%_TEST_PARAM:~0,1%"=="-" goto param_java_check
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
shift
goto param_loop
:param_java_check
if "!_TEST_PARAM:~0,2!"=="-J" (
rem strip -J prefix
set _JAVA_PARAMS=!_JAVA_PARAMS! !_TEST_PARAM:~2!
shift
goto param_loop
)
if "!_TEST_PARAM:~0,2!"=="-D" (
rem test if this was double-quoted property "-Dprop=42"
for /F "delims== tokens=1,*" %%G in ("!_TEST_PARAM!") DO (
if not ["%%H"] == [""] (
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
) else if [%2] neq [] (
rem it was a normal property: -Dprop=42 or -Drop="42"
call set _PARAM1=%%1=%%2
set _JAVA_PARAMS=!_JAVA_PARAMS! !_PARAM1!
rem # Overwrite global variables address and port if we have them
if "%1%" == "-Djatos.http.port" (
set port=%2%
) else if "%1%" == "-Djatos.http.address" (
set address=%2%
)
shift
)
)
) else (
if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%2
shift
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
)
)
shift
goto param_loop
:param_afterloop
exit /B 0