From ff681adc5b0c0a66de465c2477fc651fa5578774 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 26 Aug 2015 17:54:20 +0100 Subject: [PATCH] Fix launch.script to not exit prematurely Use "return" instead of "exit" where possible, especially in function definitions. Also fixed the exit codes to match the LSB spec for some specific conditions (fixes gh-3521). Fixes gh-3199, fixes gh-3535 --- .../src/main/asciidoc/deployment.adoc | 3 ++ .../spring-boot-sample-actuator/pom.xml | 3 ++ .../spring-boot-sample-devtools/pom.xml | 3 -- .../boot/loader/tools/launch.script | 42 ++++++++++--------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/deployment.adoc b/spring-boot-docs/src/main/asciidoc/deployment.adoc index aeffdc5e8e..736ad5fd97 100644 --- a/spring-boot-docs/src/main/asciidoc/deployment.adoc +++ b/spring-boot-docs/src/main/asciidoc/deployment.adoc @@ -432,6 +432,9 @@ the default behavior in a script or on the command line: but if it is not a symlink, or you want to explicitly set the app name this can be useful. +|`RUN_ARGS` +|The arguments to pass to the program (the Spring Boot app). + |`JAVA_HOME` |The location of the `java` executable is discovered by using the `PATH` by default, but you can set it explicitly if there is an executable file at `$JAVA_HOME/bin/java`. diff --git a/spring-boot-samples/spring-boot-sample-actuator/pom.xml b/spring-boot-samples/spring-boot-sample-actuator/pom.xml index 8bc49e99f8..9cf5b7473c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/pom.xml +++ b/spring-boot-samples/spring-boot-sample-actuator/pom.xml @@ -68,6 +68,9 @@ org.springframework.boot spring-boot-maven-plugin + + true + diff --git a/spring-boot-samples/spring-boot-sample-devtools/pom.xml b/spring-boot-samples/spring-boot-sample-devtools/pom.xml index 6416e47cb8..dfb514b593 100644 --- a/spring-boot-samples/spring-boot-sample-devtools/pom.xml +++ b/spring-boot-samples/spring-boot-sample-devtools/pom.xml @@ -43,9 +43,6 @@ org.springframework.boot spring-boot-maven-plugin - - false - diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index 3a0c4d2561..199f7735be 100755 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -71,8 +71,8 @@ echoYellow() { echo $'\e[0;33m'$1$'\e[0m'; } # Utility functions checkPermissions() { - touch "$pid_file" &> /dev/null || { echoRed "Operation not permitted (cannot access pid file)"; exit 1; } - touch "$log_file" &> /dev/null || { echoRed "Operation not permitted (cannot access log file)"; exit 1; } + touch "$pid_file" &> /dev/null || { echoRed "Operation not permitted (cannot access pid file)"; return 4; } + touch "$log_file" &> /dev/null || { echoRed "Operation not permitted (cannot access log file)"; return 4; } } isRunning() { @@ -115,40 +115,40 @@ command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPT start() { if [[ -f "$pid_file" ]]; then pid=$(cat "$pid_file") - isRunning $pid && { echoYellow "Already running [$pid]"; exit 0; } + isRunning $pid && { echoYellow "Already running [$pid]"; return 0; } fi pushd $(dirname "$jarfile") > /dev/null if [[ -n "$run_user" ]]; then mkdir "$PID_FOLDER" &> /dev/null - checkPermissions + checkPermissions || return $? chown "$run_user" "$PID_FOLDER" chown "$run_user" "$pid_file" chown "$run_user" "$log_file" su -c "$command &> \"$log_file\" & echo \$!" $run_user > "$pid_file" pid=$(cat "$pid_file") else - checkPermissions + checkPermissions || return $? $command &> "$log_file" & pid=$! disown $pid echo "$pid" > "$pid_file" fi - [[ -z $pid ]] && { echoRed "Failed to start"; exit 1; } + [[ -z $pid ]] && { echoRed "Failed to start"; return 1; } echoGreen "Started [$pid]" } stop() { - [[ -f $pid_file ]] || { echoRed "Not running (pidfile not found)"; exit 1; } + [[ -f $pid_file ]] || { echoRed "Not running (pidfile not found)"; return 1; } pid=$(cat "$pid_file") rm -f "$pid_file" - isRunning $pid || { echoRed "Not running (process ${pid} not found)"; exit 1; } - kill -HUP $pid &> /dev/null || { echoRed "Unable to kill process ${pid}"; exit 1; } - for i in $(seq 1 20); do - isRunning ${pid} || { echoGreen "Stopped [$pid]"; rm -f $pid_file; exit 0; } + isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 1; } + kill -HUP $pid &> /dev/null || { echoRed "Unable to kill process ${pid}"; return 3; } + for i in $(seq 1 60); do + isRunning ${pid} || { echoGreen "Stopped [$pid]"; rm -f $pid_file; return 0; } sleep 1 done echoRed "Unable to kill process ${pid}"; - exit 3; + return 3; } restart() { @@ -157,31 +157,33 @@ restart() { } status() { - [[ -f $pid_file ]] || { echoRed "Not running"; exit 1; } + [[ -f $pid_file ]] || { echoRed "Not running"; return 1; } pid=$(cat "$pid_file") - isRunning $pid || { echoRed "Not running (process ${pid} not found)"; exit 1; } + isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 3; } echoGreen "Running [$pid]" - exit 0 + return 0 } run() { pushd $(dirname "$jarfile") > /dev/null exec $command + result = $? popd + return $result } # Call the appropriate action function case "$action" in start) - start "$@";; + start "$@"; exit $?;; stop) - stop "$@";; + stop "$@"; exit $?;; restart) - restart "$@";; + restart "$@"; exit $?;; status) - status "$@";; + status "$@"; exit $?;; run) - run "$@";; + run "$@"; exit $?;; *) echo "Usage: $0 {start|stop|restart|status|run}"; exit 1; esac