Skip to content

Commit

Permalink
Merge pull request #24639 from OndroMih/ondromih-startserv-on-mac
Browse files Browse the repository at this point in the history
Fix the startserv script for Mac OS
  • Loading branch information
arjantijms authored Oct 20, 2023
2 parents ef006f7 + 3a9042d commit ee7cfe5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,32 @@ start_as_main_process () {
exec java -jar "$ASADMIN_JAR" start-domain --help
fi

# Execute start-domain --dry-run and store the output line by line into an array.
# If it fails, the last item in the array will be FAILED
readarray -t COMMAND < <(java -jar "$ASADMIN_JAR" start-domain --dry-run "$@" 2> /dev/null || echo -e 'FAILED' )
# Execute start-domain --dry-run and store the output line by line into an array,
# except the first and last line, which aren't part of the command to execute.
# If it fails, the first item in the array will be FAILED
COMMAND=()
local FIRST=y
local SECOND=y
local PREV_COM
while read COM; do
if [[ "$FIRST" == y ]]; then
FIRST=n
elif [[ "$SECOND" == y ]]; then
SECOND=n
PREV_COM="$COM"
else
COMMAND+=("$PREV_COM");
PREV_COM="$COM"
fi
done < <(java -jar "$ASADMIN_JAR" start-domain --dry-run "$@" 2> /dev/null || echo -e "FAILED\n" )

# If asadmin command failed (last item is FAILED), we execute it again to show
# If asadmin command failed (first item is 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 ]
if [[ "${COMMAND[@]:0:1}" == FAILED ]]
then

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

exec "$JAVA" -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" start-domain --dry-run "$@"
else
# Filter the command
# - remove 1st line (Dump of JVM Invocation line...)
# - remove line with "-read-stdin" and the following line with "true"
# to prevent waiting for master password in stdin
# - remove last line (Command executed successfully)

COMMAND=("${COMMAND[@]:1}")
unset 'COMMAND[-1]'

# Execute the command to start GlassFish
# If all OK, execute the command to start GlassFish
exec "${COMMAND[@]}"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
#

AS_INSTALL=`dirname "$0"`/..
AS_INSTALL=`dirname "$0"`/../glassfish
case "`uname`" in
CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL`
esac
Expand All @@ -35,29 +35,32 @@ start_as_main_process () {
exec java -jar "$ASADMIN_JAR" start-domain --help
fi

# 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 "$ASADMIN_JAR" start-domain --dry-run "$@" 2> /dev/null || echo -e 'FAILED' )
# Execute start-domain --dry-run and store the output line by line into an array,
# except the first and last line, which aren't part of the command to execute.
# If it fails, the first item in the array will be FAILED
COMMAND=()
local FIRST=y
local SECOND=y
local PREV_COM
while read COM; do
if [[ "$FIRST" == y ]]; then
FIRST=n
elif [[ "$SECOND" == y ]]; then
SECOND=n
PREV_COM="$COM"
else
COMMAND+=("$PREV_COM");
PREV_COM="$COM"
fi
done < <(java -jar "$ASADMIN_JAR" start-domain --dry-run "$@" 2> /dev/null || echo -e "FAILED\n" )

# If asadmin command failed (last item is FAILED), we execute it again to show
# If asadmin command failed (first item is 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 ]
if [[ "${COMMAND[@]:0:1}" == FAILED ]]
then

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

exec "$JAVA" -jar "$AS_INSTALL_LIB/client/appserver-cli.jar" start-domain --dry-run "$@"
else
# Filter the command
# - remove 1st line (Dump of JVM Invocation line...)
# - remove line with "-read-stdin" and the following line with "true"
# to prevent waiting for master password in stdin
# - remove last line (Command executed successfully)

COMMAND=("${COMMAND[@]:1}")
unset 'COMMAND[-1]'

# Execute the command to start GlassFish
# If all OK, execute the command to start GlassFish
exec "${COMMAND[@]}"
fi

Expand Down

0 comments on commit ee7cfe5

Please sign in to comment.