Browse Source

Change ownership when log file is created by launch script

Closes gh-11951
pull/12071/head
Andy Wilkinson 8 years ago
parent
commit
d59000ceb1
  1. 13
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java
  2. 9
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-changed-when-created.sh
  3. 11
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/log-file-ownership-is-unchanged-when-exists.sh
  4. 10
      spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

13
spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java

@ -223,7 +223,6 @@ public class SysVinitLaunchScriptIT { @@ -223,7 +223,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");
}
@ -239,6 +238,18 @@ public class SysVinitLaunchScriptIT { @@ -239,6 +238,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");

9
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 @@ @@ -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

11
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 @@ @@ -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

10
spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

@ -148,7 +148,15 @@ do_start() { @@ -148,7 +148,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 $?

Loading…
Cancel
Save