From 03deff9a1c8ee74d72d6fe428777e0e64c6c8784 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 13 Oct 2016 16:51:54 +0100 Subject: [PATCH] Handle relative pid folder correctly in the launch script Previously, a relative PID folder was not handled correctly when running stop, status, or force_reload. This meant that a service could be started when configured to use a relative pid file, but then could not be stopped. The PID folder should be treated as relative to the service's jar file. This commit updates stop, status, and force_reload to push the jar file's directory so that this is now the case for those three commands. Closes gh-7092 --- .../boot/launchscript/SysVinitLaunchScriptIT.java | 12 ++++++++++++ .../scripts/launch-with-multiple-java-opts.sh | 2 +- .../scripts/launch-with-multiple-run-args.sh | 2 +- .../scripts/launch-with-relative-pid-folder.sh | 10 ++++++++++ .../resources/scripts/launch-with-single-java-opt.sh | 2 +- .../resources/scripts/launch-with-single-run-arg.sh | 2 +- .../launch-with-use-of-start-stop-daemon-disabled.sh | 2 +- .../src/test/resources/scripts/test-functions.sh | 7 ++++--- .../springframework/boot/loader/tools/launch.script | 8 +++++++- 9 files changed, 38 insertions(+), 9 deletions(-) create mode 100755 spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-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 55220fb195..fe0094df11 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 @@ -198,6 +198,18 @@ public class SysVinitLaunchScriptIT { doLaunch("launch-with-use-of-start-stop-daemon-disabled.sh"); } + @Test + public void launchWithRelativePidFolder() throws Exception { + String output = doTest("launch-with-relative-pid-folder.sh"); + assertThat(output).has( + coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]")); + assertThat(output).has( + coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]")); + assertThat(output).has( + coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]")); + + } + private void doLaunch(String script) throws Exception { assertThat(doTest(script)).contains("Launched"); } diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-java-opts.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-java-opts.sh index 701ba50ee8..dc1ce03528 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-java-opts.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-java-opts.sh @@ -1,6 +1,6 @@ source ./test-functions.sh -echo 'JAVA_OPTS="-Dserver.port=8081 -Dserver.context-path=/test"' > /spring-boot-app.conf install_service +echo 'JAVA_OPTS="-Dserver.port=8081 -Dserver.context-path=/test"' > /test-service/spring-boot-app.conf start_service await_app http://127.0.0.1:8081/test/ curl -s http://127.0.0.1:8081/test/ diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-run-args.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-run-args.sh index 9ab7c4b869..675d65425a 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-run-args.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-multiple-run-args.sh @@ -1,6 +1,6 @@ source ./test-functions.sh -echo 'RUN_ARGS="--server.port=8081 --server.context-path=/test"' > /spring-boot-app.conf install_service +echo 'RUN_ARGS="--server.port=8081 --server.context-path=/test"' > /test-service/spring-boot-app.conf start_service await_app http://127.0.0.1:8081/test/ curl -s http://127.0.0.1:8081/test/ 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 new file mode 100755 index 0000000000..fcd457f8c8 --- /dev/null +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-relative-pid-folder.sh @@ -0,0 +1,10 @@ +source ./test-functions.sh +mkdir ./pid +install_service +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 +curl -s http://127.0.0.1:8080/ +status_service +stop_service diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-java-opt.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-java-opt.sh index f7052dc5ee..a0445b8224 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-java-opt.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-java-opt.sh @@ -1,6 +1,6 @@ source ./test-functions.sh -echo 'JAVA_OPTS=-Dserver.port=8081' > /spring-boot-app.conf install_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/ diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-run-arg.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-run-arg.sh index c79633e32d..0d61c5d154 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-run-arg.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-single-run-arg.sh @@ -1,6 +1,6 @@ source ./test-functions.sh -echo 'RUN_ARGS=--server.port=8081' > /spring-boot-app.conf install_service +echo 'RUN_ARGS=--server.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/ diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-use-of-start-stop-daemon-disabled.sh b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-use-of-start-stop-daemon-disabled.sh index 75b98f69e8..2f2bd3dfad 100755 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-use-of-start-stop-daemon-disabled.sh +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/launch-with-use-of-start-stop-daemon-disabled.sh @@ -1,7 +1,7 @@ source ./test-functions.sh chmod -x $(type -p start-stop-daemon) -echo 'USE_START_STOP_DAEMON=false' > /spring-boot-app.conf install_service +echo 'USE_START_STOP_DAEMON=false' > /test-service/spring-boot-app.conf start_service await_app curl -s http://127.0.0.1:8080/ 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 30f509db92..aab41ca0f3 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 @@ -1,7 +1,8 @@ install_service() { - mv /spring-boot-launch-script-tests-*.jar /spring-boot-app.jar - chmod +x /spring-boot-app.jar - ln -s /spring-boot-app.jar /etc/init.d/spring-boot-app + mkdir /test-service + mv /spring-boot-launch-script-tests-*.jar /test-service/spring-boot-app.jar + chmod +x /test-service/spring-boot-app.jar + ln -s /test-service/spring-boot-app.jar /etc/init.d/spring-boot-app } start_service() { 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 36e3c1641d..09ef435bc2 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 @@ -145,7 +145,7 @@ start() { do_start() { working_dir=$(dirname "$jarfile") pushd "$working_dir" > /dev/null - mkdir "$PID_FOLDER" &> /dev/null + mkdir -p "$PID_FOLDER" &> /dev/null if [[ -n "$run_user" ]]; then checkPermissions || return $? if [[ -z "$pid_subfolder" ]]; then @@ -180,6 +180,8 @@ do_start() { } stop() { + working_dir=$(dirname "$jarfile") + pushd "$working_dir" > /dev/null [[ -f $pid_file ]] || { echoYellow "Not running (pidfile not found)"; return 0; } pid=$(cat "$pid_file") isRunning "$pid" || { echoYellow "Not running (process ${pid}). Removing stale pid file."; rm -f "$pid_file"; return 0; } @@ -202,6 +204,8 @@ restart() { } force_reload() { + working_dir=$(dirname "$jarfile") + pushd "$working_dir" > /dev/null [[ -f $pid_file ]] || { echoRed "Not running (pidfile not found)"; return 7; } pid=$(cat "$pid_file") rm -f "$pid_file" @@ -211,6 +215,8 @@ force_reload() { } status() { + working_dir=$(dirname "$jarfile") + pushd "$working_dir" > /dev/null [[ -f "$pid_file" ]] || { echoRed "Not running"; return 3; } pid=$(cat "$pid_file") isRunning "$pid" || { echoRed "Not running (process ${pid} not found)"; return 1; }