From 56a58880088fa2fcbdc7d0c05e92f29050aeb8bb Mon Sep 17 00:00:00 2001 From: Ali Shahbour Date: Tue, 25 Apr 2017 10:51:31 +0300 Subject: [PATCH 1/2] Find .conf file next to symlink to jar that's using the launch script See gh-8988 --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 7 +++++++ .../scripts/launch-with-double-link-single-java-opt.sh | 6 ++++++ .../src/test/resources/scripts/test-functions.sh | 8 ++++++++ .../org/springframework/boot/loader/tools/launch.script | 9 +++++++-- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-double-link-single-java-opt.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 5f17163e679..10aea5d9f83 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 @@ -59,6 +59,7 @@ import static org.junit.Assume.assumeThat; * Integration tests for Spring Boot's launch script on OSs that use SysVinit. * * @author Andy Wilkinson + * @author Ali Shahbour */ @RunWith(Parameterized.class) public class SysVinitLaunchScriptIT { @@ -194,6 +195,12 @@ public class SysVinitLaunchScriptIT { doLaunch("launch-with-single-java-opt.sh"); } + @Test + public void launchWithDoubleLinkSingleJavaOpt() throws Exception { + doLaunch("launch-with-double-link-single-java-opt.sh"); + } + + @Test public void launchWithMultipleJavaOpts() throws Exception { doLaunch("launch-with-multiple-java-opts.sh"); diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-double-link-single-java-opt.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-double-link-single-java-opt.sh new file mode 100755 index 00000000000..9f1f5c404d0 --- /dev/null +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-double-link-single-java-opt.sh @@ -0,0 +1,6 @@ +source ./test-functions.sh +install_double_link_service +echo 'JAVA_OPTS=-Dserver.port=8081' > /test-service/spring-boot-app.conf +start_service +await_app http://127.0.0.1:8081/ +curl -s http://127.0.0.1:8081/ \ No newline at end of file diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh index c1734c757bb..549031b229c 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh @@ -5,6 +5,14 @@ install_service() { ln -s /test-service/spring-boot-app.jar /etc/init.d/spring-boot-app } +install_double_link_service() { + mkdir /test-service + mv /spring-boot-launch-script-tests-*.jar /test-service/ + chmod +x /test-service/spring-boot-launch-script-tests-*.jar + ln -s /test-service/spring-boot-launch-script-tests-*.jar /test-service/spring-boot-app.jar + ln -s /test-service/spring-boot-app.jar /etc/init.d/spring-boot-app +} + start_service() { service spring-boot-app start $@ } 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 25facc1ede1..5bc1ec1a1a8 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 @@ -32,7 +32,13 @@ WORKING_DIR="$(pwd)" cd "$(dirname "$0")" || exit 1 [[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0") while [[ -L "$jarfile" ]]; do - [[ "$jarfile" =~ init\.d ]] && init_script=$(basename "$jarfile") + if [[ "$jarfile" =~ init\.d ]]; then + init_script=$(basename "$jarfile") + else + # while looping check if their is any configuration file + configfile="${jarfile%.*}.conf" + [[ -r ${configfile} ]] && source "${configfile}" + fi jarfile=$(readlink "$jarfile") cd "$(dirname "$jarfile")" || exit 1 jarfile=$(pwd)/$(basename "$jarfile") @@ -45,7 +51,6 @@ configfile="$(basename "${jarfile%.*}.conf")" # Initialize CONF_FOLDER location defaulting to jarfolder [[ -z "$CONF_FOLDER" ]] && CONF_FOLDER="{{confFolder:${jarfolder}}}" - # shellcheck source=/dev/null [[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" From 3db5843c8b9e08562e4571a2e4ec6e547a4c62f2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 26 Sep 2017 14:42:18 +0100 Subject: [PATCH 2/2] Polish "Find .conf file next to symlink to jar that's using the launch script" Closes gh-8988 --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 1 - .../org/springframework/boot/loader/tools/launch.script | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 10aea5d9f83..65812fdf173 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 @@ -200,7 +200,6 @@ public class SysVinitLaunchScriptIT { doLaunch("launch-with-double-link-single-java-opt.sh"); } - @Test public void launchWithMultipleJavaOpts() throws Exception { doLaunch("launch-with-multiple-java-opts.sh"); 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 5bc1ec1a1a8..c4124cd2970 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 @@ -35,8 +35,8 @@ while [[ -L "$jarfile" ]]; do if [[ "$jarfile" =~ init\.d ]]; then init_script=$(basename "$jarfile") else - # while looping check if their is any configuration file configfile="${jarfile%.*}.conf" + # shellcheck source=/dev/null [[ -r ${configfile} ]] && source "${configfile}" fi jarfile=$(readlink "$jarfile")