Skip to content

Commit

Permalink
Fix the startserv script for Mac OS
Browse files Browse the repository at this point in the history
Works even with zsh
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Oct 18, 2023
1 parent ab6951f commit 3a9042d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
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
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 3a9042d

Please sign in to comment.