Change ownership when log file is created by launch script

Closes gh-11951
This commit is contained in:
Andy Wilkinson
2018-02-13 14:18:03 +00:00
parent 2f6d05dc51
commit d59000ceb1
4 changed files with 41 additions and 2 deletions

View File

@@ -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 {
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");

View File

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

View File

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

View File

@@ -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 $?