diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index c79e808933b..d732403ea65 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -57,13 +57,18 @@ configfile="$(basename "${jarfile%.*}.conf")" # shellcheck source=/dev/null [[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" +# ANSI Colors +echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; } +echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; } +echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; } + # Initialize PID/LOG locations if they weren't provided by the config file [[ -z "$PID_FOLDER" ]] && PID_FOLDER="{{pidFolder:/var/run}}" [[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="{{logFolder:/var/log}}" ! [[ "$PID_FOLDER" == /* ]] && PID_FOLDER="$(dirname "$jarfile")"/"$PID_FOLDER" ! [[ "$LOG_FOLDER" == /* ]] && LOG_FOLDER="$(dirname "$jarfile")"/"$LOG_FOLDER" -! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp" -! [[ -x "$LOG_FOLDER" ]] && LOG_FOLDER="/tmp" +! [[ -x "$PID_FOLDER" ]] && echoYellow "PID_FOLDER $PID_FOLDER does not exist. Falling back to /tmp" && PID_FOLDER="/tmp" +! [[ -x "$LOG_FOLDER" ]] && echoYellow "LOG_FOLDER $LOG_FOLDER does not exist. Falling back to /tmp" && LOG_FOLDER="/tmp" # Set up defaults [[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run" @@ -84,11 +89,6 @@ fi # Initialize stop wait time if not provided by the config file [[ -z "$STOP_WAIT_TIME" ]] && STOP_WAIT_TIME="{{stopWaitTime:60}}" -# ANSI Colors -echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; } -echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; } -echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; } - # Utility functions checkPermissions() { touch "$pid_file" &> /dev/null || { echoRed "Operation not permitted (cannot access pid file)"; return 4; } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index 9c0508e67f5..c7602ac2415 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -171,7 +171,22 @@ public class SysVinitLaunchScriptIT { @Test public void basicLaunch() throws Exception { - doLaunch("basic-launch.sh"); + String output = doTest("basic-launch.sh"); + assertThat(output).doesNotContain("PID_FOLDER"); + } + + @Test + public void launchWithMissingLogFolderGeneratesAWarning() throws Exception { + String output = doTest("launch-with-missing-log-folder.sh"); + assertThat(output).has(coloredString(AnsiColor.YELLOW, + "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp")); + } + + @Test + public void launchWithMissingPidFolderGeneratesAWarning() throws Exception { + String output = doTest("launch-with-missing-pid-folder.sh"); + assertThat(output).has(coloredString(AnsiColor.YELLOW, + "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp")); } @Test diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-log-folder.sh b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-log-folder.sh new file mode 100755 index 00000000000..1f3aed38443 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-log-folder.sh @@ -0,0 +1,6 @@ +source ./test-functions.sh +install_service +echo 'LOG_FOLDER=/does/not/exist' > /test-service/spring-boot-app.conf +start_service +await_app +curl -s http://127.0.0.1:8080/ diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-pid-folder.sh b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-pid-folder.sh new file mode 100755 index 00000000000..83430bea62f --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-missing-pid-folder.sh @@ -0,0 +1,6 @@ +source ./test-functions.sh +install_service +echo 'PID_FOLDER=/does/not/exist' > /test-service/spring-boot-app.conf +start_service +await_app +curl -s http://127.0.0.1:8080/