client.bat 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. @echo off
  2. @REM WebSphere Application Server liberty client launch script
  3. @REM
  4. @REM Copyright IBM Corp. 2015
  5. @REM The source code for this program is not published or other-
  6. @REM wise divested of its trade secrets, irrespective of what has
  7. @REM been deposited with the U.S. Copyright Office.
  8. @REM
  9. @REM ----------------------------------------------------------------------------
  10. @REM
  11. @REM To customize the use of this script (for example with /etc/init.d system
  12. @REM service managers), use the following environment variables:
  13. @REM
  14. @REM JAVA_HOME - The java executable is found in %JAVA_HOME%\bin
  15. @REM
  16. @REM JVM_ARGS - A list of JVM command line options,
  17. @REM e.g. system properties or -X parameters
  18. @REM The value will be expanded by cmd.exe (use quotes for spaces)
  19. @REM
  20. @REM LOG_DIR - The log file directory
  21. @REM The default value is %WLP_CLIENT_OUTPUT_DIR%\clientName\logs
  22. @REM
  23. @REM LOG_FILE - The log file name
  24. @REM This log file is only used if the client is run in the
  25. @REM background via the start action. This is not supported in client.
  26. @REM The default value is console.log
  27. @REM
  28. @REM WLP_USER_DIR - The user/custom configuration directory used to store
  29. @REM shared and client-specific configuration.
  30. @REM See README.TXT for details about shared resource locations.
  31. @REM A client's configuration is at %WLP_USER_DIR%\clients\clientName
  32. @REM The default value is the usr directory in the install directory.
  33. @REM
  34. @REM WLP_CLIENT_OUTPUT_DIR - The directory containing output files for defined clients.
  35. @REM This directory must have both read and write permissions for
  36. @REM the user or users that start clients.
  37. @REM By default, a client's output logs and workarea are stored
  38. @REM in the %WLP_USER_DIR%\clients\clientName directory
  39. @REM (alongside configuration and applications).
  40. @REM If this variable is set, the output logs and workarea
  41. @REM would be stored in %WLP_CLIENT_OUTPUT_DIR%\clientName.
  42. @REM
  43. @REM WLP_DEBUG_ADDRESS - The port to use when running the client in debug mode.
  44. @REM The default value is 7778.
  45. @REM
  46. @REM ----------------------------------------------------------------------------
  47. setlocal enabledelayedexpansion
  48. @REM We set enabledelayedexpansion to allow !VAR!. Quoting rules:
  49. @REM - Use "%VAR%" (for passing to commands) or !VAR! (for echo) to expand
  50. @REM variables containing unknown content. %VAR% is substituted before
  51. @REM parsing, which causes problems if the value contains () or &, and it
  52. @REM causes the wrong value to be used if the variable is set within "if".
  53. @REM - Use set VAR=!VAR2!, not set VAR="!VAR2!", and use "%VAR%" when testing
  54. @REM or passing the variable. %0 and environment variables must be dequoted
  55. @REM specially to avoid issues with quotes or &. There is no reliable way to
  56. @REM handle & within %*, so users should not call the script with ^&.
  57. @REM - Use !VAR! not "%VAR%" to write to the console. Otherwise, the quotes
  58. @REM will be output literally.
  59. @REM If the user has explicitly set %errorlevel% set in their environment, then
  60. @REM it will lose its special properties. Reset it.
  61. set errorlevel=
  62. set CURRENT_DIR="%~dp0"
  63. set CURRENT_DIR=!CURRENT_DIR:"=!
  64. set WLP_INSTALL_DIR=!CURRENT_DIR:~0,-5!
  65. set INVOKED="%~0"
  66. set INVOKED=!INVOKED:"=!
  67. set PARAMS_QUOTED=%*
  68. @REM De-quote input environment variables.
  69. if defined JRE_HOME set JRE_HOME=!JRE_HOME:"=!
  70. if defined JAVA_HOME set JAVA_HOME=!JAVA_HOME:"=!
  71. if defined LOG_DIR set LOG_DIR=!LOG_DIR:"=!
  72. if defined LOG_FILE set LOG_FILE=!LOG_FILE:"=!
  73. if defined WLP_USER_DIR set WLP_USER_DIR=!WLP_USER_DIR:"=!
  74. if defined WLP_CLIENT_OUTPUT_DIR set WLP_CLIENT_OUTPUT_DIR=!WLP_CLIENT_OUTPUT_DIR:"=!
  75. if defined WLP_DEBUG_ADDRESS set WLP_DEBUG_ADDRESS=!WLP_DEBUG_ADDRESS:"=!
  76. @REM Consume script parameters
  77. @REM Set the action - must be present
  78. set ACTION=%~1
  79. if "%ACTION%" == "" set ACTION=help:usage
  80. @REM Set the client name - optional
  81. set CLIENT_ARG=%2
  82. set CLIENT_NAME=%~2
  83. if not defined CLIENT_ARG (
  84. set CLIENT_NAME=defaultClient
  85. ) else if "%CLIENT_NAME%" == "" (
  86. set CLIENT_NAME=defaultClient
  87. ) else if "%CLIENT_NAME:~0,1%" == "-" (
  88. set CLIENT_NAME=defaultClient
  89. )
  90. @REM Set JAVA_PARAMS_QUOTED.
  91. set JAVA_AGENT_QUOTED="-javaagent:!WLP_INSTALL_DIR!\bin\tools\ws-javaagent.jar"
  92. if defined WLP_SKIP_BOOTSTRAP_AGENT set JAVA_AGENT_QUOTED=
  93. set JAVA_PARAMS_QUOTED=!JVM_ARGS! -jar "%WLP_INSTALL_DIR%\bin\tools\ws-client.jar"
  94. set RC=255
  95. @REM process the selected option...
  96. if "help" == "%ACTION%" (
  97. call:help
  98. ) else if "help:usage" == "%ACTION%" (
  99. call:usage
  100. ) else if "create" == "%ACTION%" (
  101. call:createClient
  102. ) else if "run" == "%ACTION%" (
  103. call:runClient
  104. ) else if "debug" == "%ACTION%" (
  105. if not defined WLP_DEBUG_ADDRESS set WLP_DEBUG_ADDRESS=7778
  106. set JAVA_PARAMS_QUOTED=-Dwas.debug.mode=true -Dcom.ibm.websphere.ras.inject.at.transform=true -Dsun.reflect.noInflation=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address="!WLP_DEBUG_ADDRESS!" !JAVA_PARAMS_QUOTED!
  107. call:runClient
  108. ) else if "package" == "%ACTION%" (
  109. call:package
  110. ) else (
  111. goto:actions
  112. )
  113. @REM
  114. @REM THE END.
  115. @REM -- we're really done now.
  116. @REM EXIT /B will return to where we before calling SETLOCAL.
  117. @REM EXIT will quit the CMD shell entirely.
  118. @REM EXIT_ALL is required on Windows XP because it loses the errorlevel when
  119. @REM using exit /b when this script is invoked from Java. %COMSPEC% /c exit
  120. @REM works but loses errorlevel when invoked from Cygwin.
  121. @REM
  122. if not defined EXIT_ALL set EXIT_ALL=0
  123. if %EXIT_ALL% == 1 (
  124. EXIT %RC%
  125. ) else (
  126. EXIT /B %RC%
  127. )
  128. ENDLOCAL
  129. :usage
  130. call:installEnv
  131. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --help:usage
  132. set RC=%errorlevel%
  133. call:javaCmdResult
  134. goto:eof
  135. :actions
  136. call:installEnv
  137. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --help:actions:%ACTION%
  138. set RC=%errorlevel%
  139. call:javaCmdResult
  140. goto:eof
  141. :help
  142. call:installEnv
  143. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --help !CLIENT_NAME!
  144. set RC=%errorlevel%
  145. call:javaCmdResult
  146. goto:eof
  147. :createClient
  148. call:installEnv
  149. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --batch-file=--create !PARAMS_QUOTED!
  150. set RC=%errorlevel%
  151. call:javaCmdResult
  152. goto:eof
  153. :runClient
  154. call:clientEnvAndJVMOptions
  155. if not %RC% == 0 goto:eof
  156. call:clientExists true
  157. if %RC% == 2 goto:eof
  158. call:clientWorkingDirectory
  159. !JAVA_CMD_QUOTED! !JAVA_AGENT_QUOTED! !JVM_OPTIONS! !JAVA_PARAMS_QUOTED! --batch-file !PARAMS_QUOTED!
  160. set RC=%errorlevel%
  161. call:javaCmdResult
  162. goto:eof
  163. :package
  164. call:clientEnv
  165. call:clientExists true
  166. if %RC% == 2 goto:eof
  167. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --batch-file=--package !PARAMS_QUOTED!
  168. set RC=%errorlevel%
  169. call:javaCmdResult
  170. goto:eof
  171. @REM
  172. @REM Utility functions
  173. @REM
  174. @REM
  175. @REM Set environment variables for a non-client or nonexistent client command.
  176. @REM
  177. :installEnv
  178. call:readClientEnv "%WLP_INSTALL_DIR%\etc\client.env"
  179. call:installEnvDefaults
  180. call:clientEnvDefaults
  181. goto:eof
  182. @REM
  183. @REM Set variable defaults for a non-client or nonexistent client command.
  184. @REM
  185. :installEnvDefaults
  186. call:readClientEnv "%WLP_INSTALL_DIR%\java\java.env"
  187. call:readClientEnv "%WLP_INSTALL_DIR%\etc\default.env"
  188. if not defined WLP_DEFAULT_USER_DIR set WLP_DEFAULT_USER_DIR=!WLP_INSTALL_DIR!\usr
  189. if not defined WLP_USER_DIR set WLP_USER_DIR=!WLP_DEFAULT_USER_DIR!
  190. if not defined WLP_DEFAULT_CLIENT_OUTPUT_DIR set WLP_DEFAULT_CLIENT_OUTPUT_DIR=!WLP_USER_DIR!\clients
  191. if not defined WLP_CLIENT_OUTPUT_DIR set WLP_CLIENT_OUTPUT_DIR=!WLP_DEFAULT_CLIENT_OUTPUT_DIR!
  192. set CLIENT_CONFIG_DIR=!WLP_USER_DIR!\clients\!CLIENT_NAME!
  193. goto:eof
  194. @REM
  195. @REM Set defaults for client variables.
  196. @REM
  197. :clientEnvDefaults
  198. set CLIENT_OUTPUT_DIR=!WLP_CLIENT_OUTPUT_DIR!\!CLIENT_NAME!
  199. if not defined LOG_DIR (
  200. set X_LOG_DIR=!CLIENT_OUTPUT_DIR!\logs
  201. ) else (
  202. set X_LOG_DIR=!LOG_DIR!
  203. )
  204. if not defined LOG_FILE (
  205. set X_LOG_FILE=console.log
  206. ) else (
  207. set X_LOG_FILE=!LOG_FILE!
  208. )
  209. @REM Unset these variables to prevent collisions with nested process invocations
  210. set LOG_DIR=
  211. set LOG_FILE=
  212. if NOT defined JAVA_HOME (
  213. if NOT defined JRE_HOME (
  214. if NOT defined WLP_DEFAULT_JAVA_HOME (
  215. @REM Use whatever java is on the path
  216. set JAVA_CMD_QUOTED="java"
  217. ) else (
  218. if "!WLP_DEFAULT_JAVA_HOME:~0,17!" == "@WLP_INSTALL_DIR@" (
  219. set WLP_DEFAULT_JAVA_HOME=!WLP_INSTALL_DIR!!WLP_DEFAULT_JAVA_HOME:~17!
  220. )
  221. set JAVA_CMD_QUOTED="!WLP_DEFAULT_JAVA_HOME!\bin\java"
  222. )
  223. ) else (
  224. set JAVA_CMD_QUOTED="%JRE_HOME%\bin\java"
  225. )
  226. ) else (
  227. if exist "%JAVA_HOME%\jre\bin\java.exe" set JAVA_HOME=!JAVA_HOME!\jre
  228. set JAVA_CMD_QUOTED="!JAVA_HOME!\bin\java"
  229. )
  230. goto:eof
  231. @REM
  232. @REM Set environment variables for an existing client.
  233. @REM
  234. :clientEnv
  235. call:readClientEnv "%WLP_INSTALL_DIR%\etc\client.env"
  236. call:installEnvDefaults
  237. call:readClientEnv "%CLIENT_CONFIG_DIR%\client.env"
  238. call:clientEnvDefaults
  239. goto:eof
  240. @REM
  241. @REM Set environment variables and JVM_OPTIONS for an existing client.
  242. @REM
  243. :clientEnvAndJVMOptions
  244. call:clientEnv
  245. set JVM_OPTIONS=
  246. @REM Avoid HeadlessException.
  247. set JVM_OPTIONS=-Djava.awt.headless=true !JVM_OPTIONS!
  248. set RC=0
  249. if exist "%CLIENT_CONFIG_DIR%\client.jvm.options" (
  250. call:mergeJVMOptions "%CLIENT_CONFIG_DIR%\client.jvm.options"
  251. )
  252. @REM If the client file is not found, check for options in the etc folder.
  253. if not defined USE_ETC_OPTIONS (
  254. set JVM_TEMP_OPTIONS=
  255. call:mergeJVMOptions "%WLP_INSTALL_DIR%\etc\client.jvm.options"
  256. )
  257. @REM If we are running on Java 9, apply Liberty's built-in java 9 options
  258. if exist "%JAVA_HOME%\lib\modules" (
  259. call:mergeJVMOptions "%WLP_INSTALL_DIR%\lib\platform\java\java9.options"
  260. )
  261. set JVM_OPTIONS=!JVM_OPTIONS!%JVM_TEMP_OPTIONS%
  262. goto:eof
  263. @REM
  264. @REM Read and set variables from the quoted file %1. Empty lines and lines
  265. @REM beginning with the hash character ('#') are ignored. All other lines must
  266. @REM be be of the form: VAR=VALUE
  267. @REM
  268. :readClientEnv
  269. if not exist %1 goto:eof
  270. for /f "usebackq eol=# delims== tokens=1,*" %%i in (%1) do set %%i=%%j
  271. goto:eof
  272. @REM
  273. @REM Merging one jvm option into the options string
  274. @REM
  275. :mergeJVMOptions
  276. set jvmoptionfile=%1
  277. if exist %jvmoptionfile% (
  278. set USE_ETC_OPTIONS=defined
  279. call:readJVMOptions %jvmoptionfile%
  280. )
  281. goto:eof
  282. @REM
  283. @REM Read the contents of the quoted file %1 and append the contents to
  284. @REM %JVM_OPTIONS%. Empty lines and lines beginning with the hash character
  285. @REM ('#') are ignored. All other lines are concatenated.
  286. @REM
  287. :readJVMOptions
  288. @REM delims= is not specified, so leading whitespace is not preserved. This
  289. @REM is contrary to the documentation, but we keep the current behavior for
  290. @REM backwards compatibility since it causes no other known issues.
  291. for /f "usebackq eol=# tokens=*" %%i in (%1) do (
  292. set JVM_OPTION="%%i"
  293. set JVM_OPTION=!JVM_OPTION:"=!
  294. set JVM_TEMP_OPTIONS=!JVM_TEMP_OPTIONS! "%%i"
  295. )
  296. goto:eof
  297. @REM
  298. @REM Set the current working directory for the existing client.
  299. @REM
  300. :clientWorkingDirectory
  301. if not exist "%CLIENT_OUTPUT_DIR%" mkdir "%CLIENT_OUTPUT_DIR%"
  302. cd /d "%CLIENT_OUTPUT_DIR%"
  303. goto:eof
  304. @REM
  305. @REM Check the result of a Java command.
  306. @REM
  307. :javaCmdResult
  308. if %RC% == 0 goto:eof
  309. if !JAVA_CMD_QUOTED! == "java" (
  310. @REM The command does not contain "\", so errorlevel 9009 will be reported
  311. @REM if the command does not exist.
  312. if %RC% neq 9009 goto:eof
  313. ) else (
  314. @REM The command contains "\", so errorlevel 3 will be reported. We can't
  315. @REM distinguish that from our own exit codes, so check for the existence
  316. @REM of java.exe.
  317. if exist !JAVA_CMD_QUOTED!.exe goto:eof
  318. )
  319. @REM Windows prints a generic "The system cannot find the path specified.",
  320. @REM so echo the java command.
  321. echo !JAVA_CMD_QUOTED!
  322. goto:eof
  323. @REM
  324. @REM clientExists: Return 0 if %CLIENT_CONFIG_DIR% exists, or is "defaultClient"
  325. @REM 2 if client does not exist
  326. @REM
  327. :clientExists
  328. if "%CLIENT_NAME%" == "defaultClient" (
  329. set RC=0
  330. ) else if NOT EXIST "%CLIENT_CONFIG_DIR%" (
  331. if "%1" == "true" (
  332. !JAVA_CMD_QUOTED! !JAVA_PARAMS_QUOTED! --message:info.clientNotExist "%CLIENT_NAME%"
  333. set RC=!errorlevel!
  334. if !RC! == 0 (
  335. set RC=2
  336. ) else (
  337. call:javaCmdResult
  338. )
  339. ) else (
  340. set RC=2
  341. )
  342. ) else (
  343. set RC=0
  344. )
  345. goto:eof