From 615d3c21474e9f1135293c702a6844cb79414348 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Fri, 14 Dec 2018 11:50:12 +0100 Subject: [PATCH] PRISM startup scripts: use exec call to start Java by default Previously, we have called java as a child process of the startup script. This is a bit problematic, as killing the startup script (in a non-interactive setting, e.g., by running via a script that enforces a time limit or killing it via a process manager) does not necessarily kill the Java child process. This can leave potentially long-running Java processes consuming resources floating around. We avoid this by using 'exec java ...' to invoke Java, which replaces the shell process with the Java process for PRISM, keeping the process ID. As a fallback, if it turns out there a unforseen problems with the new exec-based approach, one can set the environment variable PRISM_NO_EXEC to 'yes' to obtain the old behaviour, i.e., export PRISM_NO_EXEC=yes bin/prism ... --- prism/src/bin/prism.cygwin | 15 +++++++++++++-- prism/src/bin/prism.darwin32 | 14 ++++++++++++-- prism/src/bin/prism.darwin64 | 14 ++++++++++++-- prism/src/bin/prism.linux | 14 ++++++++++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/prism/src/bin/prism.cygwin b/prism/src/bin/prism.cygwin index 3b63f732..03494f5c 100644 --- a/prism/src/bin/prism.cygwin +++ b/prism/src/bin/prism.cygwin @@ -107,5 +107,16 @@ if [ "$PRISM_DEBUG" != "" ]; then PRISM_JAVA="$PRISM_DEBUG" fi -# Run PRISM through Java -"$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH_WIN" -classpath "$PRISM_CLASSPATH_WIN" $PRISM_MAINCLASS "$@" +# +# If environment variable PRISM_NO_EXEC is set to 'yes', use old method of starting Java. +# The default method is to use an exec call. +# +if [ "$PRISM_NO_EXEC" = "yes" ]; then + # Run PRISM through Java as a child process (exit code of script is exit code of the java call) + # Note: Killing this startup script will not necessarily kill the Java process + "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH_WIN" -classpath "$PRISM_CLASSPATH_WIN" $PRISM_MAINCLASS "$@" +else + # (Default) Run PRISM through Java via an exec call (the shell process is replaced by the Java process) + exec "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH_WIN" -classpath "$PRISM_CLASSPATH_WIN" $PRISM_MAINCLASS "$@" +fi + diff --git a/prism/src/bin/prism.darwin32 b/prism/src/bin/prism.darwin32 index a8f2b830..edca3a53 100755 --- a/prism/src/bin/prism.darwin32 +++ b/prism/src/bin/prism.darwin32 @@ -112,6 +112,16 @@ if [ "$PRISM_DEBUG" != "" ]; then PRISM_JAVA="$PRISM_DEBUG" fi -# Run PRISM through Java (exit code of script is exit code of the java call) -"$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +# +# If environment variable PRISM_NO_EXEC is set to 'yes', use old method of starting Java. +# The default method is to use an exec call. +# +if [ "$PRISM_NO_EXEC" = "yes" ]; then + # Run PRISM through Java as a child process (exit code of script is exit code of the java call) + # Note: Killing this startup script will not necessarily kill the Java process + "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +else + # (Default) Run PRISM through Java via an exec call (the shell process is replaced by the Java process) + exec "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +fi diff --git a/prism/src/bin/prism.darwin64 b/prism/src/bin/prism.darwin64 index a8f2b830..edca3a53 100755 --- a/prism/src/bin/prism.darwin64 +++ b/prism/src/bin/prism.darwin64 @@ -112,6 +112,16 @@ if [ "$PRISM_DEBUG" != "" ]; then PRISM_JAVA="$PRISM_DEBUG" fi -# Run PRISM through Java (exit code of script is exit code of the java call) -"$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +# +# If environment variable PRISM_NO_EXEC is set to 'yes', use old method of starting Java. +# The default method is to use an exec call. +# +if [ "$PRISM_NO_EXEC" = "yes" ]; then + # Run PRISM through Java as a child process (exit code of script is exit code of the java call) + # Note: Killing this startup script will not necessarily kill the Java process + "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +else + # (Default) Run PRISM through Java via an exec call (the shell process is replaced by the Java process) + exec "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE "$PRISM_ICON" "$PRISM_DOCK_NAME" -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +fi diff --git a/prism/src/bin/prism.linux b/prism/src/bin/prism.linux index dc7a7a33..54d591a4 100755 --- a/prism/src/bin/prism.linux +++ b/prism/src/bin/prism.linux @@ -103,6 +103,16 @@ if [ "$PRISM_DEBUG" != "" ]; then PRISM_JAVA="$PRISM_DEBUG" fi -# Run PRISM through Java (exit code of script is exit code of the java call) -"$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +# +# If environment variable PRISM_NO_EXEC is set to 'yes', use old method of starting Java. +# The default method is to use an exec call. +# +if [ "$PRISM_NO_EXEC" = "yes" ]; then + # Run PRISM through Java as a child process (exit code of script is exit code of the java call) + # Note: Killing this startup script will not necessarily kill the Java process + "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +else + # (Default) Run PRISM through Java via an exec call (the shell process is replaced by the Java process) + exec "$PRISM_JAVA" $PRISM_JAVA_ARG1 $PRISM_JAVA_ARG2 $PRISM_JAVA_DEBUG $PRISM_JAVAMAXMEM $PRISM_JAVASTACKSIZE -Djava.awt.headless=$PRISM_HEADLESS -Djava.library.path="$JAVA_LIBRARY_PATH" -classpath "$PRISM_CLASSPATH" $PRISM_MAINCLASS "$@" +fi