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 c3ceaf6fb7..30e6ca41c7 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 @@ -156,7 +156,15 @@ do_start() { pushd "$working_dir" > /dev/null if [[ ! -e "$PID_FOLDER" ]]; then mkdir -p "$PID_FOLDER" &> /dev/null - chown "$run_user" "$PID_FOLDER" + if [[ -n "$run_user" ]]; then + chown "$run_user" "$PID_FOLDER" + fi + fi + if [[ ! -e "$log_file" ]]; then + touch "$log_file" &> /dev/null + if [[ -n "$run_user" ]]; then + chown "$run_user" "$log_file" + fi fi if [[ -n "$run_user" ]]; then checkPermissions || return $? 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 3a0f92ebd4..346cb54ea2 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 @@ -229,7 +229,6 @@ public class SysVinitLaunchScriptIT { @Test public void pidFolderOwnership() throws Exception { String output = doTest("pid-folder-ownership.sh"); - System.err.println(output); assertThat(output).contains("phil root"); } @@ -245,6 +244,18 @@ public class SysVinitLaunchScriptIT { assertThat(output).contains("phil root"); } + @Test + public void logFileOwnershipIsChangedWhenCreated() throws Exception { + String output = doTest("log-file-ownership-is-changed-when-created.sh"); + assertThat(output).contains("andy root"); + } + + @Test + public void logFileOwnershipIsUnchangedWhenExists() throws Exception { + String output = doTest("log-file-ownership-is-unchanged-when-exists.sh"); + assertThat(output).contains("root root"); + } + @Test public void launchWithRelativeLogFolder() throws Exception { String output = doTest("launch-with-relative-log-folder.sh"); diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-changed-when-created.sh b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-changed-when-created.sh new file mode 100755 index 0000000000..c007f35cad --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-changed-when-created.sh @@ -0,0 +1,9 @@ +source ./test-functions.sh +install_service +echo 'LOG_FOLDER=log' > /test-service/spring-boot-app.conf +mkdir -p /test-service/log +useradd andy +chown andy /test-service/spring-boot-app.jar +start_service +await_app +ls -al /test-service/log/spring-boot-app.log \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-unchanged-when-exists.sh b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-unchanged-when-exists.sh new file mode 100755 index 0000000000..ec28e35ac2 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-unchanged-when-exists.sh @@ -0,0 +1,11 @@ +source ./test-functions.sh +install_service +echo 'LOG_FOLDER=log' > /test-service/spring-boot-app.conf +mkdir -p /test-service/log +touch /test-service/log/spring-boot-app.log +chmod a+w /test-service/log/spring-boot-app.log +useradd andy +chown andy /test-service/spring-boot-app.jar +start_service +await_app +ls -al /test-service/log/spring-boot-app.log \ No newline at end of file