Skip to content

Commit d59000c

Browse files
committed
Change ownership when log file is created by launch script
Closes gh-11951
1 parent 2f6d05d commit d59000c

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public void launchWithRelativePidFolder() throws Exception {
223223
@Test
224224
public void pidFolderOwnership() throws Exception {
225225
String output = doTest("pid-folder-ownership.sh");
226-
System.err.println(output);
227226
assertThat(output).contains("phil root");
228227
}
229228

@@ -239,6 +238,18 @@ public void logFileOwnership() throws Exception {
239238
assertThat(output).contains("phil root");
240239
}
241240

241+
@Test
242+
public void logFileOwnershipIsChangedWhenCreated() throws Exception {
243+
String output = doTest("log-file-ownership-is-changed-when-created.sh");
244+
assertThat(output).contains("andy root");
245+
}
246+
247+
@Test
248+
public void logFileOwnershipIsUnchangedWhenExists() throws Exception {
249+
String output = doTest("log-file-ownership-is-unchanged-when-exists.sh");
250+
assertThat(output).contains("root root");
251+
}
252+
242253
@Test
243254
public void launchWithRelativeLogFolder() throws Exception {
244255
String output = doTest("launch-with-relative-log-folder.sh");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source ./test-functions.sh
2+
install_service
3+
echo 'LOG_FOLDER=log' > /test-service/spring-boot-app.conf
4+
mkdir -p /test-service/log
5+
useradd andy
6+
chown andy /test-service/spring-boot-app.jar
7+
start_service
8+
await_app
9+
ls -al /test-service/log/spring-boot-app.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
source ./test-functions.sh
2+
install_service
3+
echo 'LOG_FOLDER=log' > /test-service/spring-boot-app.conf
4+
mkdir -p /test-service/log
5+
touch /test-service/log/spring-boot-app.log
6+
chmod a+w /test-service/log/spring-boot-app.log
7+
useradd andy
8+
chown andy /test-service/spring-boot-app.jar
9+
start_service
10+
await_app
11+
ls -al /test-service/log/spring-boot-app.log

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ do_start() {
148148
pushd "$working_dir" > /dev/null
149149
if [[ ! -e "$PID_FOLDER" ]]; then
150150
mkdir -p "$PID_FOLDER" &> /dev/null
151-
chown "$run_user" "$PID_FOLDER"
151+
if [[ -n "$run_user" ]]; then
152+
chown "$run_user" "$PID_FOLDER"
153+
fi
154+
fi
155+
if [[ ! -e "$log_file" ]]; then
156+
touch "$log_file" &> /dev/null
157+
if [[ -n "$run_user" ]]; then
158+
chown "$run_user" "$log_file"
159+
fi
152160
fi
153161
if [[ -n "$run_user" ]]; then
154162
checkPermissions || return $?

0 commit comments

Comments
 (0)