From 86a7d93848c63cb377ea81e0a7736edab2724049 Mon Sep 17 00:00:00 2001 From: Ali Shahbour Date: Tue, 25 Apr 2017 10:51:31 +0300 Subject: [PATCH 1/4] #Support original file name even if it is a symbolic link [http://stackoverflow.com/questions/43584510/conf-file-for-spring-boot-application](config file) this is needed if your systemd or init.d is pointing to a symbolic link file instead of the original fat jar --- .../org/springframework/boot/loader/tools/launch.script | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 25facc1ede11..fd9acd4616eb 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 @@ -31,6 +31,7 @@ WORKING_DIR="$(pwd)" # Follow symlinks to find the real jar and detect init.d script cd "$(dirname "$0")" || exit 1 [[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0") +originalconfigfile="$(basename "${jarfile%.*}.conf")" while [[ -L "$jarfile" ]]; do [[ "$jarfile" =~ init\.d ]] && init_script=$(basename "$jarfile") jarfile=$(readlink "$jarfile") @@ -47,7 +48,8 @@ configfile="$(basename "${jarfile%.*}.conf")" [[ -z "$CONF_FOLDER" ]] && CONF_FOLDER="{{confFolder:${jarfolder}}}" # shellcheck source=/dev/null -[[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" +[[ -r "${CONF_FOLDER}/${originalconfigfile}" ]] && source "${CONF_FOLDER}/${originalconfigfile}" +[[ ! -r "${CONF_FOLDER}/${originalconfigfile}" ]] && [[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" # Initialize PID/LOG locations if they weren't provided by the config file [[ -z "$PID_FOLDER" ]] && PID_FOLDER="{{pidFolder:/var/run}}" From 67092a895ccbce9bc9db46462f33057e8fa7452b Mon Sep 17 00:00:00 2001 From: Ali Shahbour Date: Fri, 2 Jun 2017 00:16:45 +0300 Subject: [PATCH 2/4] Change launch.script to support checking configuration file on every symbolic link except if it contain init.d Add test to check the configuration file when having double link --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 8 +++++++- .../launch-with-double-link-single-java-opt.sh | 6 ++++++ .../src/test/resources/scripts/test-functions.sh | 8 ++++++++ .../springframework/boot/loader/tools/launch.script | 13 ++++++++----- 4 files changed, 29 insertions(+), 6 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 0a18899e0106..d2bf649aab96 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 @@ -194,7 +194,13 @@ public void launchWithSingleJavaOpt() throws Exception { doLaunch("launch-with-single-java-opt.sh"); } - @Test + @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 000000000000..9f1f5c404d06 --- /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 c1734c757bb3..549031b229c5 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 fd9acd4616eb..5bc1ec1a1a88 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 @@ -31,9 +31,14 @@ WORKING_DIR="$(pwd)" # Follow symlinks to find the real jar and detect init.d script cd "$(dirname "$0")" || exit 1 [[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0") -originalconfigfile="$(basename "${jarfile%.*}.conf")" 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") @@ -46,10 +51,8 @@ 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}/${originalconfigfile}" ]] && source "${CONF_FOLDER}/${originalconfigfile}" -[[ ! -r "${CONF_FOLDER}/${originalconfigfile}" ]] && [[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" +[[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}" # Initialize PID/LOG locations if they weren't provided by the config file [[ -z "$PID_FOLDER" ]] && PID_FOLDER="{{pidFolder:/var/run}}" From 306082aa5d793e1ed1b0f61df7a597eea79878a1 Mon Sep 17 00:00:00 2001 From: Ali Shahbour Date: Fri, 2 Jun 2017 00:29:27 +0300 Subject: [PATCH 3/4] fix checkstyle-validation --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 d2bf649aab96..6dae336b576e 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 @@ -194,13 +194,13 @@ public void launchWithSingleJavaOpt() throws Exception { 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 launchWithDoubleLinkSingleJavaOpt() throws Exception { + doLaunch("launch-with-double-link-single-java-opt.sh"); + } - @Test + @Test public void launchWithMultipleJavaOpts() throws Exception { doLaunch("launch-with-multiple-java-opts.sh"); } From 813dbe66c57a74a8d7b389b498b06ddc9ec94d43 Mon Sep 17 00:00:00 2001 From: Ali Shahbour Date: Mon, 5 Jun 2017 12:50:03 +0300 Subject: [PATCH 4/4] add @author tag --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 1 + 1 file changed, 1 insertion(+) 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 6dae336b576e..ee2593aa7fc6 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 @@ * 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 {