Skip to content

Commit

Permalink
Startserv script for Linux (Bash) starts GF in foreground with a sing…
Browse files Browse the repository at this point in the history
…le JVM process

Instead of starting a launcher, which starts GF and then waits for it to finish 
(2 JVM processes running), runs GF in dry-run mode and then executes GF in foreground directly, 
using the command line retrieved from dry-run mode.

To do later: Modify GF to output only the command line so that it's not needed to filter it.
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Jun 16, 2023
1 parent c004690 commit dae9ddf
Showing 1 changed file with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
#
Expand All @@ -16,6 +16,43 @@
#

AS_INSTALL=`dirname "$0"`/..
AS_INSTALL_LIB="$AS_INSTALL/modules"
AS_INSTALL_LIB="$AS_INSTALL/lib"

exec java -jar "$AS_INSTALL_LIB/admin-cli.jar" start-domain --verbose "$@"
start_as_main_process () {
local COMMAND

# Execute start-domain --dry-run and store the output line by line into an array.
# If it fails, the array will contain a single element FAILED
readarray -t COMMAND < <(java -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" start-domain --dry-run "$@" 2> /dev/null || echo -e 'FAILED' )

# If asadmin command failed, we execute it again to show the output to the user and exit
# If all OK, we filter and execute the command
if [ "${COMMAND[1]}" = FAILED ]
then

java -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" start-domain --dry-run "$@"

else
# Filter the command
# - remove 1st line,
# - remove line with -read-stdin to prevent waiting for master password in stdin
# - remove last line

COMMAND=("${COMMAND[@]:1}")
unset 'COMMAND[-1]'
for i in "${!COMMAND[@]}"; do
if [[ ${COMMAND[i]} = "-read-stdin" ]]; then
unset 'COMMAND[i]'
fi
done

# Execute the command to start GlassFish
exec "${COMMAND[@]}"
fi

}

start_as_main_process "$@"

# Alternatively, run the following:
# exec java -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" start-domain --verbose "$@"

0 comments on commit dae9ddf

Please sign in to comment.