From 24f8c737fb4f543e70741f42916128274c3f5021 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 14 Oct 2016 09:19:11 +0100 Subject: [PATCH] Make relative PID_FOLDER and LOG_FOLDER absolute using jar's directory Closes gh-7092 Closes gh-7093 --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 5 +++++ .../resources/scripts/launch-with-relative-log-folder.sh | 8 ++++++++ .../resources/scripts/launch-with-relative-pid-folder.sh | 4 ++-- .../org/springframework/boot/loader/tools/launch.script | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-log-folder.sh diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index fe0094df11f..2ad08cac5bd 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -207,7 +207,12 @@ public class SysVinitLaunchScriptIT { coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]")); assertThat(output).has( coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]")); + } + @Test + public void launchWithRelativeLogFolder() throws Exception { + String output = doTest("launch-with-relative-log-folder.sh"); + assertThat(output).contains("Log written"); } private void doLaunch(String script) throws Exception { diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-log-folder.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-log-folder.sh new file mode 100755 index 00000000000..4f44ee3d2c0 --- /dev/null +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-log-folder.sh @@ -0,0 +1,8 @@ +source ./test-functions.sh +mkdir ./pid +install_service +echo 'LOG_FOLDER=log' > /test-service/spring-boot-app.conf +mkdir -p /test-service/log +start_service +await_app +[[ -s /test-service/log/spring-boot-app.log ]] && echo "Log written" \ No newline at end of file diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-folder.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-folder.sh index fcd457f8c8d..a46d67b8a2a 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-folder.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-folder.sh @@ -1,7 +1,7 @@ source ./test-functions.sh -mkdir ./pid install_service -echo 'PID_FOLDER=./pid' > /test-service/spring-boot-app.conf +mkdir /test-service/pid +echo 'PID_FOLDER=pid' > /test-service/spring-boot-app.conf start_service echo "PID: $(cat /test-service/pid/spring-boot-app/spring-boot-app.pid)" await_app 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 09ef435bc23..f2fca2c793d 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 @@ -52,6 +52,8 @@ configfile="$(basename "${jarfile%.*}.conf")" # 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"