server 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. #!/bin/sh
  2. ###############################################################################
  3. # WebSphere Application Server liberty launch script
  4. #
  5. # Copyright IBM Corp. 2011, 2021
  6. # The source code for this program is not published or other-
  7. # wise divested of its trade secrets, irrespective of what has
  8. # been deposited with the U.S. Copyright Office.
  9. #
  10. # ----------------------------------------------------------------------------
  11. #
  12. # To customize the use of this script (for example with /etc/init.d system
  13. # service managers), use the following environment variables:
  14. #
  15. # JAVA_HOME - The java executable is found in ${JAVA_HOME}/bin
  16. #
  17. # JVM_ARGS - A list of JVM command line options,
  18. # e.g. system properties or -X parameters
  19. # The value will be expanded by the shell (use quotes for spaces)
  20. #
  21. # LOG_DIR - The log file directory
  22. # The default value is ${WLP_OUTPUT_DIR}/serverName/logs
  23. #
  24. # LOG_FILE - The log file name
  25. # This log file is only used if the server is run in the
  26. # background via the start action.
  27. # The default value is console.log
  28. #
  29. # PID_DIR - The directory that should be used for server pid file(s).
  30. # The default value is ${WLP_OUTPUT_DIR}/.pid
  31. #
  32. # PID_FILE - The file that should be used for the server pid file.
  33. # The default value is ${PID_DIR}/serverName.pid
  34. #
  35. # WLP_USER_DIR - The user/custom configuration directory used to store
  36. # shared and server-specific configuration.
  37. # See README.TXT for details about shared resource locations.
  38. # A server's configuration is at ${WLP_USER_DIR}/servers/serverName
  39. # The default value is the usr directory in the install directory.
  40. #
  41. # WLP_OUTPUT_DIR - The directory containing output files for defined servers.
  42. # This directory must have both read and write permissions for
  43. # the user or users that start servers.
  44. # By default, a server's output logs and workarea are stored
  45. # in the ${WLP_USER_DIR}/servers/serverName directory
  46. # (alongside configuration and applications).
  47. # If this variable is set, the output logs and workarea
  48. # would be stored in ${WLP_OUTPUT_DIR}/serverName.
  49. #
  50. # WLP_DEBUG_ADDRESS - The port to use when running the server in debug mode.
  51. # The default value is 7777.
  52. #
  53. # WLP_DEBUG_SUSPEND - Whether to suspend the jvm on startup or not. This can be
  54. # set to y to suspend the jvm on startup until a debugger attaches,
  55. # or set to n to startup without waiting for a debugger to attach.
  56. # The default value is y.
  57. #
  58. # WLP_DEBUG_REMOTE - Whether to allow remote debugging or not. This can be set
  59. # to y to allow remote debugging. By default, this value is not
  60. # defined, which does not allow remote debugging on newer JDK/JREs.
  61. #
  62. # WLP_SKIP_UMASK - Skip setting the umask value to allow the default value
  63. # to be used.
  64. #
  65. # WLP_ZOS_PROCEDURE - The name of the STC procedure to be used to start the
  66. # server in a z/OS environment.
  67. #
  68. # WLP_ZOS_JOBNAME - The job name to use when starting the server in
  69. # a z/OS environment.
  70. #
  71. ###############################################################################
  72. SERVER_UNKNOWN_STATUS=5
  73. ##
  74. ## Determine the platform and absolute path of the installation directory.
  75. ##
  76. case $OSTYPE in
  77. cygwin)
  78. uname=CYGWIN_NT
  79. # Determine the installation directory without forking if possible. Use
  80. # eval to hide ${var//find/replace}, ${var%suffix}, and ${var:first:length}
  81. # syntaxes from shells that can't parse them.
  82. eval '
  83. # cd to the install directory.
  84. savePWD=$PWD
  85. script=${0//\\/\/}
  86. unset CDPATH; cd "${script%/*}"/..
  87. # Convert the install (current working) directory to a Windows path.
  88. case $PWD in
  89. /cygdrive/?/*)
  90. # Use ${var:first:length} to avoid forking for cygpath.
  91. WLP_INSTALL_DIR=${PWD:10:1}:${PWD:11}
  92. ;;
  93. *)
  94. WLP_INSTALL_DIR=`cygpath -ma .`
  95. esac
  96. cd "$savePWD"
  97. '
  98. ;;
  99. *)
  100. uname=`uname`
  101. case $uname in
  102. CYGWIN_*)
  103. WLP_INSTALL_DIR=`cygpath -ma "${0}"/../..`
  104. ;;
  105. *)
  106. dirname=`dirname "$0"`
  107. WLP_INSTALL_DIR=`unset CDPATH; cd "$dirname/.." && pwd`
  108. esac
  109. esac
  110. ##
  111. ## Platform specific setup
  112. ##
  113. PS_P='ps -p'
  114. UMASK_O='umask o='
  115. tryShellExtensions=true
  116. os400lib=false
  117. shareclassesCacheDirPerm=true
  118. defaultFileEncoding=
  119. newline='
  120. '
  121. nativeEBCDIC=false
  122. case ${uname} in
  123. CYGWIN_*)
  124. # java.exe is a non-Cygwin process, so we need to pass -W.
  125. PS_P='ps -W -p'
  126. shareclassesCacheDirPerm=false
  127. ;;
  128. OS/390)
  129. defaultFileEncoding=iso8859-1
  130. nativeEBCDIC=true # Auto-convert server.env/jvm.options from ASCII-to-EBCDIC, if necessary.
  131. _BPXK_WLM_PROPAGATE=NO # Prevent WLM enclave propagation to spawned processes
  132. _EDC_PTHREAD_YIELD=-2 # Disable sleeps inside of pthread_yield
  133. JAVA_PROPAGATE=NO # Prevent WLM enclave propagation to new threads
  134. export _BPXK_WLM_PROPAGATE _EDC_PTHREAD_YIELD JAVA_PROPAGATE
  135. WLP_NLS_PATH="${WLP_INSTALL_DIR}/lib/native/zos/s390x/nls/%N.cat"
  136. if [ ${NLSPATH} ]
  137. then
  138. NLSPATH="${WLP_NLS_PATH}:${NLSPATH}"
  139. else
  140. NLSPATH="${WLP_NLS_PATH}"
  141. fi
  142. ;;
  143. OS400)
  144. # Avoid issues with qsh.
  145. tryShellExtensions=false
  146. # os400lib gets unset later if we cannot find WAS_PRODUCT_LIB and WAS_SHARED_LIB
  147. os400lib=true
  148. # on os400 use 'umask -S o=', not 'umask o='
  149. UMASK_O='umask -S o='
  150. ;;
  151. esac
  152. ##
  153. ## safeEcho: Portable echo that can handle backslashes and leading dashes.
  154. safeEcho()
  155. {
  156. cat <<EOF
  157. $*
  158. EOF
  159. return $?
  160. }
  161. # Starting the server with a full tmp directory may prevent the server from
  162. # reading server.env during startup.
  163. safeEcho "" || exit $?
  164. # Define escapeForEval functions using ${var//find/replace} and ${var#suffix}
  165. # if possible since those constructs are significantly faster than safeEcho+sed
  166. # since they avoid forks. Use eval (to hide the syntax from shells that don't
  167. # support them) in a subshell (to avoid exiting the shell process on error) to
  168. # test if the shell has support.
  169. if ${tryShellExtensions} && (eval 'true ${1//b/c} ${1#*=}') 2> /dev/null; then
  170. # The shell has support. Define the functions using eval, again to hide the
  171. # syntax from shells that don't support it.
  172. eval "
  173. escapeForEval()
  174. {
  175. escapeForEvalResult=\\'\${1//\\'/\\'\\\"\\'\\\"\\'}\\'
  176. }
  177. extractValueAndEscapeForEval()
  178. {
  179. escapeForEval \"\${1#*=}\"
  180. }
  181. substitutePrefixVar()
  182. {
  183. case \$1 in
  184. @\$2@*) substitutePrefixVarResult=\$3\${1#@\$2@};;
  185. *) substitutePrefixVarResult=\$1
  186. esac
  187. }
  188. "
  189. else
  190. ##
  191. ## escapeForEval: Escape the first parameter to be safe for use in eval,
  192. ## and set escapeForEvalResult with the result.
  193. ##
  194. escapeForEval()
  195. {
  196. escapeForEvalResult=\'`safeEcho "$1" | sed s/\'/\'\"\'\"\'/g`\'
  197. }
  198. ##
  199. ## extractValueAndEscapeForEval: Extract the value of a var=value string,
  200. ## and set escapeForEvalResult with the result.
  201. ##
  202. extractValueAndEscapeForEval()
  203. {
  204. escapeForEvalResult=\'`safeEcho "$1" | sed -e 's/[^=]*=//' -e s/\'/\'\"\'\"\'/g`\'
  205. }
  206. ##
  207. ## substitutePrefixVar: If $1 has a prefix @$2@, set substitutePrefixVarResult
  208. ## to $1 with the prefix replaced by $3. Otherwise, set
  209. ## to $1.
  210. substitutePrefixVar()
  211. {
  212. case $1 in
  213. @$2@*) substitutePrefixVarResult=$3`safeEcho "$1" | sed -e "s/^@$2@//"`;;
  214. *) substitutePrefixVarResult=$1
  215. esac
  216. }
  217. fi
  218. ##
  219. ## Quote ${WLP_INSTALL_DIR} for eval.
  220. ##
  221. escapeForEval "${WLP_INSTALL_DIR}"
  222. WLP_INSTALL_DIR_QUOTED=${escapeForEvalResult}
  223. READ_ETC=1
  224. ##
  225. ## Consume script parameters:
  226. ## action is required/positional,
  227. ## serverName is optional, --options following
  228. ##
  229. if [ $# -lt 1 ]
  230. then
  231. ACTION=help:usage
  232. else
  233. ACTION=$1
  234. shift #consume
  235. if [ $# -ge 1 ]
  236. then
  237. # Only use if it isn't something that looks like an option
  238. case $1 in
  239. --*);;
  240. *)
  241. SERVER_NAME=$1
  242. shift #consume
  243. esac
  244. fi
  245. fi
  246. ##
  247. ## Set server name and directory
  248. ##
  249. if [ -z "$SERVER_NAME" ]
  250. then
  251. SERVER_NAME=defaultServer
  252. fi
  253. ##
  254. ## Set JAVA_AGENT_QUOTED if WLP_SKIP_BOOTSTRAP_AGENT is unset.
  255. ##
  256. JAVA_AGENT_QUOTED=-javaagent:${WLP_INSTALL_DIR_QUOTED}/bin/tools/ws-javaagent.jar
  257. if [ -n "${WLP_SKIP_BOOTSTRAP_AGENT}" ]; then
  258. JAVA_AGENT_QUOTED=
  259. fi
  260. ##
  261. ## createServer: Function to launch server create
  262. ##
  263. createServer()
  264. {
  265. javaCmd '' "${SERVER_NAME}" --create "$@"
  266. rc=$?
  267. if [ $rc = 0 ]; then
  268. rmIfExist "${X_PID_FILE}"
  269. if $os400lib; then
  270. # If production on IBM i, authorize QEJBSVR to the server folder
  271. chgautOS400 "${WLP_USER_DIR}/servers/${SERVER_NAME}" "*RX"
  272. chgautOS400 "${WLP_OUTPUT_DIR}" "*RWX"
  273. if [ -d "${WLP_USER_DIR}/servers/${SERVER_NAME}/apps" ]; then
  274. chgautOS400 "${WLP_USER_DIR}/servers/${SERVER_NAME}/apps" "*RWX"
  275. fi
  276. fi
  277. fi
  278. return $rc
  279. }
  280. ##
  281. ## chgautOS400: Change authorization of directory or file $1 to $2 for QEJBSVR.
  282. ## This should only be called if $os400lib is true
  283. ##
  284. chgautOS400()
  285. {
  286. system "CHGAUT OBJ('$1') USER(QEJBSVR) DTAAUT($2) OBJAUT(*ALL) SUBTREE(*ALL)"
  287. }
  288. ##
  289. ## mkdirs: Create a directory and all parent directories, if necessary.
  290. ##
  291. mkdirs()
  292. {
  293. if [ ! -d "$1" ]; then
  294. mkdir -p "$1"
  295. if $os400lib; then
  296. chgautOS400 "$1" "*RWX"
  297. fi
  298. fi
  299. }
  300. ##
  301. ## rmIfExist: Remove files if they exist.
  302. ##
  303. rmIfExist()
  304. {
  305. for file
  306. do
  307. # [ is a builtin command for most shells, so a fork is not required.
  308. if [ -f "${file}" ]; then
  309. # If any file exists, pass all files so we only fork once.
  310. rm -f "$@"
  311. return
  312. fi
  313. done
  314. }
  315. ##
  316. ## touchIfNotExist: Create an empty file.
  317. ##
  318. touchIfNotExist()
  319. {
  320. if [ ! -f "$1" ]; then
  321. # true is a builtin command for most shells, so a fork is not required.
  322. true > "$1"
  323. if $os400lib; then
  324. chgautOS400 "$1" "*RWX"
  325. fi
  326. fi
  327. }
  328. ##
  329. ## serverStatus: Check for a running server process. If the first argument is
  330. ## true, avoid using the launcher to verify the status if possible,
  331. ## and don't output messages even if the launcher is used.
  332. ## The second argument is the --status variant.
  333. ## If success is returned, then ${PID} will be set if available.
  334. serverStatus()
  335. {
  336. if [ -f "${SERVER_OUTPUT_DIR}/workarea/.sLock" ]; then
  337. if [ ! -f "${SERVER_OUTPUT_DIR}/workarea/.sCommand" ]; then
  338. # Workarea exists, .sCommand doesn't. Server is not running.
  339. rmIfExist "${X_PID_FILE}"
  340. return 1
  341. fi
  342. # Read the PID file to set ${PID} if possible. Remove it if stale.
  343. # Otherwise, assume the server is started if we're avoiding the launcher.
  344. if serverPIDStatus && $1; then
  345. return 0
  346. fi
  347. # The workarea suggests a started server. Either the script started a
  348. # server process that ended before removing .sCommand, or the server was
  349. # started without using the script (so the PID file was never created).
  350. # In either case, verify the status using the launcher.
  351. if $1; then
  352. javaCmd '' "${SERVER_NAME}" $2 > /dev/null
  353. else
  354. javaCmd '' "${SERVER_NAME}" --pid="${PID}" $2
  355. fi
  356. rc=$?
  357. if [ $rc = 1 ]; then
  358. # The launcher verified the server is not running. Remove the indicator
  359. # files to avoid checking again on subsequent script invocations.
  360. rm -f "${SERVER_OUTPUT_DIR}/workarea/.sCommand"
  361. fi
  362. return $rc
  363. fi
  364. if serverPIDStatus; then
  365. if $1; then
  366. return 0
  367. fi
  368. # PID file suggests a started server with a removed workspace. Verify
  369. # using the launcher.
  370. javaCmd '' "${SERVER_NAME}" --pid-file="${X_PID_FILE}" --pid="${PID}" $2
  371. return $?
  372. fi
  373. # Neither workarea nor PID file suggest a started server.
  374. return 1
  375. }
  376. ##
  377. ## serverPIDStatus: Check the PID file for a running server process. ${PID}
  378. ## will be set to the PID if running or to empty if not.
  379. serverPIDStatus()
  380. {
  381. if [ -f "${X_PID_FILE}" ]; then
  382. PID=`cat "${X_PID_FILE}"`
  383. if $PS_P "$PID" > /dev/null 2>&1; then
  384. return 0
  385. fi
  386. rm "${X_PID_FILE}"
  387. fi
  388. PID=
  389. return 1
  390. }
  391. ##
  392. ## checkServer: Check for created/existing server. If it does not, issue an
  393. ## error message if the first argument is true, and then exit the
  394. ## script regardless.
  395. checkServer()
  396. {
  397. if [ -d "${SERVER_CONFIG_DIR}" ] || [ "defaultServer" = "${SERVER_NAME}" ]
  398. then
  399. return 0
  400. fi
  401. if $1
  402. then
  403. javaCmd '' --message:info.serverNotExist "${SERVER_NAME}"
  404. rc=$?
  405. if [ $rc = 0 ]
  406. then
  407. rc=1
  408. fi
  409. else
  410. rc=1
  411. fi
  412. return $rc
  413. }
  414. ##
  415. ## installEnv: Set variables for a non-server or nonexistent server command.
  416. installEnv()
  417. {
  418. readServerEnv "${WLP_INSTALL_DIR}/etc/server.env"
  419. installEnvDefaults
  420. serverEnvDefaults
  421. }
  422. ##
  423. ## installEnvDefaults: Set variable defaults for a non-server or nonexistent
  424. ## server command.
  425. installEnvDefaults()
  426. {
  427. readServerEnv "${WLP_INSTALL_DIR}/java/java.env"
  428. readServerEnv "${WLP_INSTALL_DIR}/etc/default.env"
  429. if [ -z "${WLP_USER_DIR}" ]
  430. then
  431. if [ -z "${WLP_DEFAULT_USER_DIR}" ]
  432. then
  433. WLP_DEFAULT_USER_DIR=${WLP_INSTALL_DIR}/usr
  434. fi
  435. WLP_USER_DIR=${WLP_DEFAULT_USER_DIR}
  436. fi
  437. if [ -z "${WLP_OUTPUT_DIR}" ]
  438. then
  439. if [ -z "${WLP_DEFAULT_OUTPUT_DIR}" ]
  440. then
  441. WLP_DEFAULT_OUTPUT_DIR=${WLP_USER_DIR}/servers
  442. fi
  443. WLP_OUTPUT_DIR=${WLP_DEFAULT_OUTPUT_DIR}
  444. fi
  445. SERVER_CONFIG_DIR=${WLP_USER_DIR}/servers/${SERVER_NAME}
  446. if $os400lib
  447. then
  448. if [ -z "${WAS_PRODUCT_LIB}" ] || [ -z "${WAS_SHARED_LIB}" ]
  449. then
  450. os400lib=false
  451. fi
  452. fi
  453. export WLP_USER_DIR
  454. export WLP_OUTPUT_DIR
  455. }
  456. ##
  457. ## serverEnvDefaults: Set defaults for server variables.
  458. serverEnvDefaults()
  459. {
  460. SERVER_OUTPUT_DIR=${WLP_OUTPUT_DIR}/${SERVER_NAME}
  461. # Unset set/tested variables to prevent collisions with nested process invocations
  462. if [ -z "$LOG_DIR" ]
  463. then
  464. X_LOG_DIR=${SERVER_OUTPUT_DIR}/logs
  465. else
  466. X_LOG_DIR=${LOG_DIR}
  467. unset LOG_DIR
  468. fi
  469. export X_LOG_DIR
  470. if [ -z "$LOG_FILE" ]
  471. then
  472. X_LOG_FILE=console.log
  473. else
  474. X_LOG_FILE=${LOG_FILE}
  475. unset LOG_FILE
  476. fi
  477. export X_LOG_FILE
  478. if [ -z "$PID_DIR" ]; then
  479. X_PID_DIR=${WLP_OUTPUT_DIR}/.pid
  480. else
  481. X_PID_DIR=${PID_DIR}
  482. unset PID_DIR
  483. fi
  484. if [ -z "$PID_FILE" ]; then
  485. X_PID_FILE=${X_PID_DIR}/${SERVER_NAME}.pid
  486. else
  487. X_PID_FILE=${PID_FILE}
  488. X_PID_DIR=`dirname "${X_PID_FILE}"`
  489. unset PID_FILE
  490. fi
  491. if [ -z "${JAVA_HOME}" ]
  492. then
  493. if [ -z "${JRE_HOME}" ]
  494. then
  495. if [ -z "${WLP_DEFAULT_JAVA_HOME}" ]
  496. then
  497. # Use whatever java is on the path
  498. JAVA_CMD=java
  499. else
  500. substitutePrefixVar "${WLP_DEFAULT_JAVA_HOME}" WLP_INSTALL_DIR "${WLP_INSTALL_DIR}"
  501. JAVA_HOME=${substitutePrefixVarResult}
  502. JAVA_CMD=${JAVA_HOME}/bin/java
  503. fi
  504. else
  505. JAVA_HOME=${JRE_HOME}
  506. JAVA_CMD=${JRE_HOME}/bin/java
  507. fi
  508. else
  509. if [ -f "${JAVA_HOME}/jre/bin/java" ]
  510. then
  511. JAVA_CMD=${JAVA_HOME}/jre/bin/java
  512. else
  513. JAVA_CMD=${JAVA_HOME}/bin/java
  514. fi
  515. fi
  516. # Prefer OPENJ9_JAVA_OPTIONS to deprecated IBM_JAVA_OPTIONS
  517. if [ -z "${OPENJ9_JAVA_OPTIONS}" ]
  518. then
  519. SPECIFIED_JAVA_OPTIONS=${IBM_JAVA_OPTIONS}
  520. else
  521. SPECIFIED_JAVA_OPTIONS=${OPENJ9_JAVA_OPTIONS}
  522. fi
  523. # Command-line parsing of -Xshareclasses does not allow "," in cacheDir.
  524. case ${WLP_OUTPUT_DIR} in
  525. *,*)
  526. SERVER_IBM_JAVA_OPTIONS=${SPECIFIED_JAVA_OPTIONS}
  527. ;;
  528. *)
  529. if ( echo "${SPECIFIED_JAVA_OPTIONS}" | grep -q "Xshareclasses"); then
  530. SERVER_IBM_JAVA_OPTIONS=${SPECIFIED_JAVA_OPTIONS}
  531. else
  532. # Set -Xscmx
  533. if [ "${ACTION}" = "debug" ]
  534. then
  535. XSCMX_VAL="130m"
  536. else
  537. XSCMX_VAL="80m"
  538. fi
  539. if $shareclassesCacheDirPerm
  540. then
  541. SERVER_IBM_JAVA_OPTIONS="-Xshareclasses:name=liberty-%u,nonfatal,cacheDir=\"${WLP_OUTPUT_DIR}/.classCache\",cacheDirPerm=1000 -XX:ShareClassesEnableBCI -Xscmx${XSCMX_VAL} ${SPECIFIED_JAVA_OPTIONS}"
  542. else
  543. SERVER_IBM_JAVA_OPTIONS="-Xshareclasses:name=liberty-%u,nonfatal,cacheDir=\"${WLP_OUTPUT_DIR}/.classCache\" -XX:ShareClassesEnableBCI -Xscmx${XSCMX_VAL} ${SPECIFIED_JAVA_OPTIONS}"
  544. fi
  545. fi
  546. esac
  547. # Add -Xquickstart -Xshareclasses:none for client JVMs only. We don't want
  548. # shared classes cache created for client operations.
  549. # Add -Dcom.ibm.tools.attach.enable=yes to allow self-attach on z/OS
  550. IBM_JAVA_OPTIONS="-Xquickstart -Dcom.ibm.tools.attach.enable=yes ${SPECIFIED_JAVA_OPTIONS} -Xshareclasses:none"
  551. export IBM_JAVA_OPTIONS
  552. OPENJ9_JAVA_OPTIONS="-Xquickstart -Dcom.ibm.tools.attach.enable=yes ${SPECIFIED_JAVA_OPTIONS} -Xshareclasses:none"
  553. export OPENJ9_JAVA_OPTIONS
  554. # Set a default file encoding if needed
  555. if [ -n "$defaultFileEncoding" ]; then
  556. if ! expr "${JVM_OPTIONS_QUOTED} ${JVM_ARGS} ${SPECIFIED_JAVA_OPTIONS}" : '.*\(-Dfile\.encoding\=[^[:space:]]\)' > /dev/null; then
  557. JVM_ARGS="${JVM_ARGS} -Dfile.encoding=$defaultFileEncoding"
  558. fi
  559. fi
  560. serverUmask
  561. }
  562. ##
  563. ## serverEnv: Set variables for an existing server.
  564. serverEnv()
  565. {
  566. readServerEnv "${WLP_INSTALL_DIR}/etc/server.env"
  567. installEnvDefaults
  568. readServerEnv "${WLP_USER_DIR}/shared/server.env"
  569. readServerEnv "${SERVER_CONFIG_DIR}/server.env"
  570. serverEnvDefaults
  571. }
  572. ##
  573. ## serverEnvAndJVMOptions: Read server.env files and set environment variables.
  574. ## Read jvm.options file into ${JVM_OPTIONS_QUOTED}
  575. serverEnvAndJVMOptions()
  576. {
  577. serverEnv
  578. # Avoids HeadlessException on all platforms and Liberty JVMs appearing as applications and stealing focus on Mac.
  579. # Declare allowAttachSelf=true so that the VM will permit a late self attach if localConnector-1.0 is enabled
  580. JVM_OPTIONS_QUOTED="-Djava.awt.headless=true -Djdk.attach.allowAttachSelf=true"
  581. SERVER_JVM_OPTIONS_QUOTED=${JVM_OPTIONS_QUOTED}
  582. rc=0
  583. # The order of merging the jvm.option files sets the precedence.
  584. # Once a given jvm option is set, it will be overridden if a duplicate
  585. # is seen later. They will both be written in to the options parameter
  586. # but the last one written will take precedence. If none are read
  587. # the script will try to read the jvm.options in etc
  588. TEMP_SAVED_OPTIONS=$SERVER_JVM_OPTIONS_QUOTED
  589. mergeJVMOptions "${WLP_USER_DIR}/shared/jvm.options"
  590. if [ $rc -ne 0 ]; then
  591. return $rc
  592. fi
  593. # This location is intentionally not documented but removing might break existing installations
  594. mergeJVMOptions "${WLP_INSTALL_DIR}/usr/shared/jvm.options"
  595. if [ $rc -ne 0 ]; then
  596. return $rc
  597. fi
  598. mergeJVMOptions "${SERVER_CONFIG_DIR}/configDropins/defaults/jvm.options"
  599. if [ $rc -ne 0 ]; then
  600. return $rc
  601. fi
  602. mergeJVMOptions "${SERVER_CONFIG_DIR}/jvm.options"
  603. if [ $rc -ne 0 ]; then
  604. return $rc
  605. fi
  606. mergeJVMOptions "${SERVER_CONFIG_DIR}/configDropins/overrides/jvm.options"
  607. if [ $rc -ne 0 ]; then
  608. return $rc
  609. fi
  610. # If none of the four files above are seen we will check for an options
  611. # file in the etc folder.
  612. if [ $READ_ETC -eq 1 ]; then
  613. SERVER_JVM_OPTIONS_QUOTED=$TEMP_SAVED_OPTIONS
  614. mergeJVMOptions "${WLP_INSTALL_DIR}/etc/jvm.options"
  615. fi
  616. JPMS_MODULE_FILE_LOCATION="${JAVA_HOME}/lib/modules"
  617. if [ -z "${JAVA_HOME}" ]; then
  618. JPMS_MODULE_FILE_LOCATION=$(dirname $(dirname $(which java)))/lib/modules
  619. fi
  620. # If we are running on Java 9, apply Liberty's built-in java 9 options
  621. if [ -f "${JPMS_MODULE_FILE_LOCATION}" ]; then
  622. mergeJVMOptions "${WLP_INSTALL_DIR}/lib/platform/java/java9.options"
  623. fi
  624. return $rc
  625. }
  626. mergeJVMOptions()
  627. {
  628. jvmOptions=$1
  629. if [ -f "$jvmOptions" ]; then
  630. READ_ETC=0
  631. saveIFS=$IFS
  632. IFS=$newline
  633. for option in `readNativeFile "$jvmOptions" '[#-]' | tr -d '\r'`; do
  634. if [ -n "$option" ]; then
  635. case $option in
  636. \#*);;
  637. *)
  638. escapeForEval "${option}"
  639. SERVER_JVM_OPTIONS_QUOTED="${SERVER_JVM_OPTIONS_QUOTED} '${option}'"
  640. ;;
  641. esac
  642. fi
  643. done
  644. IFS=$saveIFS
  645. fi
  646. }
  647. ##
  648. ## readServerEnv: Read server.env file and export environment variables.
  649. readServerEnv()
  650. {
  651. if [ -f "$1" ]; then
  652. saveIFS=$IFS
  653. IFS=$newline
  654. for line in `readNativeFile "$1" '[#_A-Za-z=]' | tr -d '\r'`; do
  655. case $line in
  656. \#*);;
  657. *=*)
  658. # Only accept alphanumeric variable names to avoid eval complexities.
  659. if var=`safeEcho "$line" | sed -e 's/^\([a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/'`; then
  660. case $var in
  661. *=*)
  662. SERVER_ENV_SETUP_FAILURE="${var} ${SERVER_ENV_SETUP_FAILURE}" ;;
  663. *)
  664. extractValueAndEscapeForEval "${line}"
  665. eval "${var}=${escapeForEvalResult}; export ${var}" ;;
  666. esac
  667. fi
  668. esac
  669. done
  670. IFS=$saveIFS
  671. fi
  672. }
  673. ##
  674. ## Detects the code page of the file and converts to EBCDIC,
  675. ## if necessary, before cat'ing.
  676. ##
  677. ## Only applicable if running in a native EBCDIC environment (z/OS).
  678. ##
  679. ## $1 the file name
  680. ## $2 pattern denoting the expected first char of file
  681. readNativeFile() {
  682. if ${nativeEBCDIC}; then
  683. # ASCII 'm' overlaps with EBCDIC '_', so strip it out before detecting the codepage.
  684. # Note: cat used here to handle ASCII-tagged files.
  685. filecontents=`cat "$1" | iconv -f ISO8859-1 -t IBM-1047 | tr -d 'm\r\n'`
  686. case $filecontents in
  687. $2*) iconv -f ISO8859-1 -t IBM-1047 "$1" ;; # ASCII file.
  688. *) cat "$1" # EBCDIC file or ASCII-tagged file.
  689. esac
  690. else
  691. cat "$1"
  692. fi
  693. }
  694. ##
  695. ## serverWorkingDirectory: Change the working directory to ${SERVER_OUTPUT_DIR}
  696. serverWorkingDirectory()
  697. {
  698. # Change the working directory to ${SERVER_OUTPUT_DIR}.
  699. mkdirs "${SERVER_OUTPUT_DIR}"
  700. cd "${SERVER_OUTPUT_DIR}"
  701. }
  702. ## set the umask value to remove all permissions for the Other category
  703. ## but leave existing values for User and Group unaltered
  704. ##
  705. ## If the WLP_SKIP_UMASK variable is set then do not set umask
  706. serverUmask()
  707. {
  708. if [ -z "${WLP_SKIP_UMASK}" ]; then
  709. $UMASK_O
  710. fi
  711. }
  712. ##
  713. ## javaCmd: Execute a java-based command. Arguments are:
  714. ##
  715. ## backgroundLogFile
  716. ## Non-empty path for output log if the process should be created in the
  717. ## background; empty otherwise. Directory must exist.
  718. ##
  719. ## "$@"
  720. ## All remaining arguments to be passed to the command
  721. ##
  722. ## The following variables must be set:
  723. ## ${JAVA_CMD} - the java command
  724. ## ${JAVA_DEBUG} - JVM options to enable debug, or empty
  725. ## ${JAVA_AGENT_QUOTED} - The -javaagent argument quoted for eval
  726. ## ${JVM_OPTIONS_QUOTED} - jvm.options quoted for eval
  727. ## ${WLP_INSTALL_DIR_QUOTED} - ${WLP_INSTALL_DIR} quoted for eval
  728. javaCmd()
  729. {
  730. JAVA_CMD_LOG=$1
  731. shift
  732. # Filter all of the -D and -X arguments off of the argument line and add them to $JVM_OPTIONS_QUOTED
  733. REMAINING_ARGS=""
  734. for option in "$@"; do
  735. if [ -n "${option}" ]; then
  736. if [ -z "${option##-D*}" ] || [ -z "${option##-X*}" ]; then
  737. JVM_OPTIONS_QUOTED="$JVM_OPTIONS_QUOTED '$option'"
  738. elif [ -z "$REMAINING_ARGS" ] ; then
  739. REMAINING_ARGS="$option"
  740. else
  741. REMAINING_ARGS="$REMAINING_ARGS $option"
  742. fi
  743. else
  744. REMAINING_ARGS="$REMAINING_ARGS $option"
  745. fi
  746. done
  747. # Set all the parameters for the java command. We use eval so that each line
  748. # in jvm.options is treated as a distinct argument.
  749. eval "set -- ${JAVA_AGENT_QUOTED} ${JVM_OPTIONS_QUOTED} ${JAVA_DEBUG} ${JVM_ARGS} -jar ${WLP_INSTALL_DIR_QUOTED}/bin/tools/ws-server.jar ""$REMAINING_ARGS"
  750. ARGS="$@"
  751. # Do not add extra logic after the commands without preserving $?
  752. if [ -n "${JAVA_CMD_LOG}" ]; then
  753. rmIfExist "${JAVA_CMD_LOG}"
  754. "${JAVA_CMD}" "$@" >> "${JAVA_CMD_LOG}" 2>&1 &
  755. elif [ $ACTION = "run" ] || [ $ACTION = "debug" ] ; then
  756. exec "${JAVA_CMD}" "$@"
  757. else
  758. "${JAVA_CMD}" "$@"
  759. fi
  760. }
  761. ##
  762. ## Issue a translated warning message. The java command will use the same options as javaCmd,
  763. ## but will ignore debug settings and will not exit after running the command when 'run'
  764. ## or 'debug' is used
  765. ##
  766. ## "$@"
  767. ## All arguments passed to the java command
  768. ##
  769. issueMessage()
  770. {
  771. # Set all the parameters for the java command. We use eval so that each line
  772. # in jvm.options is treated as a distinct argument.
  773. eval "set -- ${JAVA_AGENT_QUOTED} ${JVM_OPTIONS_QUOTED} ${JVM_ARGS} -jar ${WLP_INSTALL_DIR_QUOTED}/bin/tools/ws-server.jar "'"$@"'
  774. ARGS="$@"
  775. "${JAVA_CMD}" "$@"
  776. }
  777. ##
  778. ## serverCmdOS400: Launch a server process using the OS400 native launcher.
  779. ##
  780. ## backgroundLogFile
  781. ## Non-empty path for output log if the process should be created in the
  782. ## background; empty otherwise. Directory must exist.
  783. ##
  784. ## "$@"
  785. ## All remaining arguments to be passed to the command
  786. ##
  787. ## The following variables must be set:
  788. ## ${JAVA_CMD} - the java command
  789. ## ${JAVA_DEBUG} - JVM options to enable debug, or empty
  790. ## ${JAVA_AGENT_QUOTED} - The -javaagent argument quoted for eval
  791. ## ${JVM_OPTIONS_QUOTED} - jvm.options quoted for eval
  792. ## ${WLP_INSTALL_DIR_QUOTED} - ${WLP_INSTALL_DIR} quoted for eval
  793. serverCmdOS400()
  794. {
  795. SERVER_CMD_OS400_BACKGROUND_LOG=$1
  796. shift
  797. eval "set -- -jvmargs ${JAVA_AGENT_QUOTED} ${JVM_OPTIONS_QUOTED} ${JAVA_DEBUG} ${JVM_ARGS} -jar ${WLP_INSTALL_DIR_QUOTED}/bin/tools/ws-server.jar "'"$@"'
  798. export JAVA_HOME
  799. if [ -n "${SERVER_CMD_OS400_BACKGROUND_LOG}" ]
  800. then
  801. "/QSYS.LIB/${WAS_PRODUCT_LIB}.LIB/QWLPSTRSVR.PGM" \
  802. -pgm "${WAS_PRODUCT_LIB}/QWLPSTRSVR" \
  803. -server "${SERVER_NAME}" \
  804. -sharedlib "${WAS_SHARED_LIB}" \
  805. -pidfile "${X_PID_FILE}" \
  806. -background \
  807. -logdir "${X_LOG_DIR}" \
  808. -serveroutputdir "${SERVER_OUTPUT_DIR}" \
  809. -serverlog "${SERVER_CMD_OS400_BACKGROUND_LOG}" \
  810. "$@"
  811. else
  812. "/QSYS.LIB/${WAS_PRODUCT_LIB}.LIB/QWLPSTRSVR.PGM" \
  813. -logdir "${X_LOG_DIR}" \
  814. -serveroutputdir "${SERVER_OUTPUT_DIR}" \
  815. "$@"
  816. fi
  817. }
  818. ##
  819. ## serverCmd: Launch a server process.
  820. ##
  821. ## backgroundLogFile
  822. ## Non-empty path for output log if the process should be created in the
  823. ## background; empty otherwise. Directory must exist.
  824. ##
  825. ## PID will be set if the process is launched in the background and the return
  826. ## code is 0.
  827. ##
  828. serverCmd()
  829. {
  830. ## If one or more variables in server.env contains non-alphanumeric characters
  831. ## SERVER_ENV_SETUP_FAILURE will contain the invalid entries. We have to
  832. ## temporarily set ACTION to 'start' so that the process will not exit after
  833. ## the error message when ACTION is 'run' or 'debug'
  834. if [ -n "${SERVER_ENV_SETUP_FAILURE}" ];
  835. then
  836. for i in ${SERVER_ENV_SETUP_FAILURE}; do
  837. issueMessage --message:warning.variable.invalid "$i"
  838. done
  839. fi
  840. SERVER_CMD_BACKGROUND_LOG=$1
  841. shift
  842. ## On OS400, we need to create the defaultServer first from this script
  843. ## to get all the permissions correct. If we allow the server start
  844. ## to inline the server create from the java process, we won't get
  845. ## the correct permissions
  846. if $os400lib && [ ! -d "${SERVER_CONFIG_DIR}" ] && [ "defaultServer" = "${SERVER_NAME}" ]
  847. then
  848. # Create the server or exit the script
  849. createServer || exit $?
  850. fi
  851. SAVE_JVM_OPTIONS_QUOTED=${JVM_OPTIONS_QUOTED}
  852. JVM_OPTIONS_QUOTED=${SERVER_JVM_OPTIONS_QUOTED}
  853. SAVE_IBM_JAVA_OPTIONS=${IBM_JAVA_OPTIONS}
  854. IBM_JAVA_OPTIONS=${SERVER_IBM_JAVA_OPTIONS}
  855. SAVE_OPENJ9_JAVA_OPTIONS=${OPENJ9_JAVA_OPTIONS}
  856. OPENJ9_JAVA_OPTIONS=${SERVER_IBM_JAVA_OPTIONS}
  857. if $os400lib; then
  858. serverCmdOS400 "${SERVER_CMD_BACKGROUND_LOG}" "${SERVER_NAME}" "$@"
  859. rc=$?
  860. JVM_OPTIONS_QUOTED=${SAVE_JVM_OPTIONS_QUOTED}
  861. IBM_JAVA_OPTIONS=${SAVE_IBM_JAVA_OPTIONS}
  862. OPENJ9_JAVA_OPTIONS=${SAVE_OPENJ9_JAVA_OPTIONS}
  863. if [ -n "${SERVER_CMD_BACKGROUND_LOG}" ]; then
  864. PID=`cat "${X_PID_FILE}"`
  865. # Verify/wait for the process to start
  866. javaCmd '' "${SERVER_NAME}" --pid="${PID}" --status:start "$@"
  867. rc=$?
  868. fi
  869. elif [ "${uname}" = OS/390 ] && [ -n "${WLP_ZOS_PROCEDURE}" ] && [ -e "${WLP_INSTALL_DIR}/lib/native/zos/s390x/bbgzcsl" ]; then
  870. # Start the STC procedure
  871. if [ -n "${WLP_ZOS_JOBNAME}" ]; then
  872. "${WLP_INSTALL_DIR}/lib/native/zos/s390x/bbgzcsl" "${WLP_ZOS_PROCEDURE}" "${SERVER_NAME}" "${X_PID_FILE}" "${WLP_ZOS_JOBNAME}" "$@"
  873. else
  874. "${WLP_INSTALL_DIR}/lib/native/zos/s390x/bbgzcsl" "${WLP_ZOS_PROCEDURE}" "${SERVER_NAME}" "${X_PID_FILE}" "$@"
  875. fi
  876. rc=$?
  877. JVM_OPTIONS_QUOTED=${SAVE_JVM_OPTIONS_QUOTED}
  878. IBM_JAVA_OPTIONS=${SAVE_IBM_JAVA_OPTIONS}
  879. OPENJ9_JAVA_OPTIONS=${SAVE_OPENJ9_JAVA_OPTIONS}
  880. if [ $rc = 0 ]; then
  881. # Verify/wait for the process to start
  882. PID=`cat "${X_PID_FILE}"`
  883. javaCmd '' "${SERVER_NAME}" --pid="${PID}" --status:start "$@"
  884. rc=$?
  885. elif [ $rc = 20 ]; then
  886. # PID file not created
  887. javaCmd '' --message:error.zosProcStart.create.pidfile "${SERVER_NAME}" "${WLP_ZOS_PROCEDURE}"
  888. rc=$?
  889. if [ $rc = 0 ]; then
  890. rc=22
  891. fi
  892. elif [ $rc = 21 ]; then
  893. # Command has exceeded the max allowable length for MGCRE
  894. javaCmd '' --message:error.zosProcStart.start.length "${WLP_ZOS_PROCEDURE}"
  895. rc=$?
  896. if [ $rc = 0 ]; then
  897. rc=22
  898. fi
  899. elif [ $rc = 22 ]; then
  900. # The specified z/OS procedure name is invalid
  901. javaCmd '' --message:error.zosProcStart.procedure.invalid "${WLP_ZOS_PROCEDURE}"
  902. rc=$?
  903. if [ $rc = 0 ]; then
  904. rc=22
  905. fi
  906. elif [ $rc = 23 ]; then
  907. # The specified z/OS jobname is invalid
  908. javaCmd '' --message:error.zosProcStart.jobname.invalid "${WLP_ZOS_PROCEDURE}" "${WLP_ZOS_JOBNAME}"
  909. rc=$?
  910. if [ $rc = 0 ]; then
  911. rc=22
  912. fi
  913. else
  914. # Problem issuing MGCRE
  915. javaCmd '' --message:error.zosProcStart.mvs.start "${WLP_ZOS_PROCEDURE}" "$rc"
  916. rc=$?
  917. if [ $rc = 0 ]; then
  918. rc=22
  919. fi
  920. fi
  921. else
  922. X_CMD="${JAVA_CMD} ${ARGS}"
  923. export X_CMD
  924. javaCmd "${SERVER_CMD_BACKGROUND_LOG}" "${SERVER_NAME}" "$@"
  925. rc=$?
  926. PID=$!
  927. JVM_OPTIONS_QUOTED=${SAVE_JVM_OPTIONS_QUOTED}
  928. IBM_JAVA_OPTIONS=${SAVE_IBM_JAVA_OPTIONS}
  929. OPENJ9_JAVA_OPTIONS=${SAVE_OPENJ9_JAVA_OPTIONS}
  930. if [ -n "${SERVER_CMD_BACKGROUND_LOG}" ]; then
  931. # Verify/wait for the process to start
  932. javaCmd '' "${SERVER_NAME}" --pid="${PID}" --status:start "$@"
  933. rc=$?
  934. # write the pid file if return is OK or UNKNOWN
  935. if [ $rc = 0 -o $rc = $SERVER_UNKNOWN_STATUS ]; then
  936. safeEcho "${PID}" > "${X_PID_FILE}"
  937. fi
  938. fi
  939. fi
  940. return $rc
  941. }
  942. JAVA_DEBUG=
  943. JVM_OPTIONS_QUOTED=
  944. INVOKED="$0"
  945. export INVOKED
  946. case "$ACTION" in
  947. # Start the server in the foreground
  948. run | debug)
  949. if serverEnvAndJVMOptions
  950. then
  951. :
  952. else
  953. exit $?
  954. fi
  955. if checkServer true
  956. then
  957. if [ "${ACTION}" = "debug" ]
  958. then
  959. if [ -z "${WLP_DEBUG_ADDRESS}" ]
  960. then
  961. WLP_DEBUG_ADDRESS=7777
  962. fi
  963. if [ -z "${WLP_DEBUG_SUSPEND}" ]
  964. then
  965. WLP_DEBUG_SUSPEND=y
  966. fi
  967. if [ "${WLP_DEBUG_REMOTE}" = "y" ]
  968. then
  969. WLP_DEBUG_REMOTE_HOST="0.0.0.0:"
  970. else
  971. WLP_DEBUG_REMOTE_HOST=""
  972. fi
  973. JAVA_DEBUG="-Dwas.debug.mode=true -Dsun.reflect.noInflation=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=${WLP_DEBUG_SUSPEND},address=${WLP_DEBUG_REMOTE_HOST}${WLP_DEBUG_ADDRESS}"
  974. fi
  975. serverWorkingDirectory
  976. # WLP_JAR_CYGWIN is used only in support of java -jar startup of a Liberty server.
  977. # When WLP_JAR_CYGWIN=true (or synonym) is specied, the PID of the launching
  978. # process (i.e. parent of server process) is determined and stored in the PID file
  979. # for use by the java -jar shutdown hook to ensure termination of the launching
  980. # process. This is necessary because the launching process does not terminate on
  981. # its own under cygwin and if left behind holds file locks that prevent cleanup
  982. # of the java -jar extraction directory.
  983. if [ "$WLP_JAR_CYGWIN" = "true" -o "$WLP_JAR_CYGWIN" = "1" -o "$WLP_JAR_CYGWIN" = "TRUE" -o "$WLP_JAR_CYGWIN" = "True" ]
  984. then
  985. serverCmd '' "$@" &
  986. PID=$!
  987. mkdirs "${X_PID_DIR}"
  988. # find parent PID and store it
  989. SPID=`ps -ef | while read l; do grep $PID | awk -v PID=$PID '{ if ( $3 == PID ) print $2 }'; done`
  990. safeEcho "${SPID}" > "${X_PID_FILE}"
  991. wait "${PID}" # wait because this
  992. rc=$?
  993. else
  994. serverCmd '' "$@"
  995. rc=$?
  996. fi
  997. exit $rc
  998. else
  999. exit 2
  1000. fi
  1001. ;;
  1002. # Start the server in the background
  1003. start)
  1004. if serverEnvAndJVMOptions
  1005. then
  1006. :
  1007. else
  1008. exit $?
  1009. fi
  1010. if checkServer true
  1011. then
  1012. # We can't start the server in the background if it is already running.
  1013. serverStatus false --status:starting
  1014. rc=$?
  1015. case $rc in
  1016. "0" )
  1017. rc=1
  1018. ;;
  1019. "1" )
  1020. serverWorkingDirectory
  1021. mkdirs "${X_LOG_DIR}"
  1022. if [ -f "${X_LOG_DIR}/${X_LOG_FILE}" ] && [ ! -w "${X_LOG_DIR}/${X_LOG_FILE}" ]
  1023. then
  1024. javaCmd '' --message:error.fileNotFound "${X_LOG_DIR}/${X_LOG_FILE}"
  1025. rc=$?
  1026. if [ $rc = 0 ]; then
  1027. rc=22
  1028. fi
  1029. exit $rc
  1030. fi
  1031. mkdirs "${X_PID_DIR}"
  1032. rmIfExist "${X_PID_FILE}"
  1033. mkdirs "${SERVER_OUTPUT_DIR}/workarea"
  1034. touchIfNotExist "${SERVER_OUTPUT_DIR}/workarea/.sLock"
  1035. rmIfExist "${SERVER_OUTPUT_DIR}/workarea/.sCommand"
  1036. # Start the target server with the provided arguments
  1037. serverCmd "${X_LOG_DIR}/${X_LOG_FILE}" "$@"
  1038. rc=$?
  1039. if [ $rc = 1 ]; then
  1040. # The launcher failed (due to bad JVM arguments, for example).
  1041. # Translate to a better error code.
  1042. rc=22
  1043. fi
  1044. ;;
  1045. esac
  1046. exit $rc
  1047. else
  1048. exit 2
  1049. fi
  1050. ;;
  1051. create)
  1052. installEnv
  1053. createServer "$@"
  1054. exit $rc
  1055. ;;
  1056. # Stop the server.
  1057. stop)
  1058. serverEnv
  1059. if checkServer true
  1060. then
  1061. PID=
  1062. if [ -f "${X_PID_FILE}" ]; then
  1063. PID=`cat "${X_PID_FILE}"`
  1064. fi
  1065. javaCmd '' "${SERVER_NAME}" --pid="${PID}" --stop "$@"
  1066. rc=$?
  1067. case "$rc" in
  1068. "0" )
  1069. rm -f "${X_PID_FILE}"
  1070. ;;
  1071. "1" )
  1072. rmIfExist "${X_PID_FILE}" "${SERVER_OUTPUT_DIR}/workarea/.sCommand"
  1073. ;;
  1074. esac
  1075. exit $rc
  1076. else
  1077. exit 2
  1078. fi
  1079. ;;
  1080. # Check if server is running
  1081. status)
  1082. serverEnv
  1083. if checkServer true
  1084. then
  1085. serverPIDStatus
  1086. mkdirs "${X_LOG_DIR}"
  1087. javaCmd '' "${SERVER_NAME}" --pid="${PID}" --status
  1088. rc=$?
  1089. if [ $rc = 1 ]; then
  1090. rmIfExist "${X_PID_FILE}" "${SERVER_OUTPUT_DIR}/workarea/.sCommand"
  1091. fi
  1092. exit $rc
  1093. else
  1094. exit 2
  1095. fi
  1096. ;;
  1097. status:fast)
  1098. serverEnv
  1099. if checkServer false
  1100. then
  1101. serverStatus true --status
  1102. exit $?
  1103. else
  1104. exit 2
  1105. fi
  1106. ;;
  1107. # Package up the runtime and target server configuration
  1108. package)
  1109. if serverEnvAndJVMOptions
  1110. then
  1111. :
  1112. else
  1113. exit $?
  1114. fi
  1115. # Check to see if the server exists
  1116. if checkServer true
  1117. then
  1118. serverPIDStatus
  1119. JVM_OPTIONS_QUOTED=${SERVER_JVM_OPTIONS_QUOTED}
  1120. javaCmd '' "${JVM_OPTIONS_QUOTED}" "${SERVER_NAME}" --pid="${PID}" --package "$@"
  1121. exit $?
  1122. else
  1123. exit 2
  1124. fi
  1125. ;;
  1126. # dump the server's configs/logs/status to a zip file
  1127. dump)
  1128. serverEnv
  1129. # Check to see if the server exists
  1130. if checkServer true
  1131. then
  1132. javaCmd '' "${SERVER_NAME}" --dump "$@"
  1133. exit $?
  1134. else
  1135. exit 2
  1136. fi
  1137. ;;
  1138. # dump JVM status
  1139. javadump)
  1140. serverEnv
  1141. if checkServer true
  1142. then
  1143. javaCmd '' "${SERVER_NAME}" --javadump "$@"
  1144. exit $?
  1145. else
  1146. exit 2
  1147. fi
  1148. ;;
  1149. # pause the server
  1150. pause)
  1151. serverEnv
  1152. # Check to see if the server exists
  1153. if checkServer true
  1154. then
  1155. javaCmd '' "${SERVER_NAME}" --pause "$@"
  1156. exit $?
  1157. else
  1158. exit 2
  1159. fi
  1160. ;;
  1161. # resume the server
  1162. resume)
  1163. serverEnv
  1164. # Check to see if the server exists
  1165. if checkServer true
  1166. then
  1167. javaCmd '' "${SERVER_NAME}" --resume "$@"
  1168. exit $?
  1169. else
  1170. exit 2
  1171. fi
  1172. ;;
  1173. version)
  1174. installEnv
  1175. javaCmd '' --version
  1176. ;;
  1177. list)
  1178. installEnv
  1179. javaCmd '' --list
  1180. ;;
  1181. help)
  1182. installEnv
  1183. javaCmd '' --help ${SERVER_NAME}
  1184. ;;
  1185. help:usage)
  1186. installEnv
  1187. javaCmd '' --help:usage
  1188. ;;
  1189. *)
  1190. installEnv
  1191. javaCmd '' --help:actions:${ACTION}
  1192. ;;
  1193. esac
  1194. exit 0