Skip to content

Commit 069e7f3

Browse files
committed
Merge pull request #14519 from Andreas Gebhardt
* gh-14519: Polish "Log a warning when using fallback for pid and log locations" Log a warning when using fallback for pid and log locations
2 parents 5d0e812 + 4a222cb commit 069e7f3

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,18 @@ configfile="$(basename "${jarfile%.*}.conf")"
5757
# shellcheck source=/dev/null
5858
[[ -r "${CONF_FOLDER}/${configfile}" ]] && source "${CONF_FOLDER}/${configfile}"
5959

60+
# ANSI Colors
61+
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
62+
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
63+
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
64+
6065
# Initialize PID/LOG locations if they weren't provided by the config file
6166
[[ -z "$PID_FOLDER" ]] && PID_FOLDER="{{pidFolder:/var/run}}"
6267
[[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="{{logFolder:/var/log}}"
6368
! [[ "$PID_FOLDER" == /* ]] && PID_FOLDER="$(dirname "$jarfile")"/"$PID_FOLDER"
6469
! [[ "$LOG_FOLDER" == /* ]] && LOG_FOLDER="$(dirname "$jarfile")"/"$LOG_FOLDER"
65-
! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp"
66-
! [[ -x "$LOG_FOLDER" ]] && LOG_FOLDER="/tmp"
70+
! [[ -x "$PID_FOLDER" ]] && echoYellow "PID_FOLDER $PID_FOLDER does not exist. Falling back to /tmp" && PID_FOLDER="/tmp"
71+
! [[ -x "$LOG_FOLDER" ]] && echoYellow "LOG_FOLDER $LOG_FOLDER does not exist. Falling back to /tmp" && LOG_FOLDER="/tmp"
6772

6873
# Set up defaults
6974
[[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run"
@@ -84,11 +89,6 @@ fi
8489
# Initialize stop wait time if not provided by the config file
8590
[[ -z "$STOP_WAIT_TIME" ]] && STOP_WAIT_TIME="{{stopWaitTime:60}}"
8691

87-
# ANSI Colors
88-
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
89-
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
90-
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
91-
9292
# Utility functions
9393
checkPermissions() {
9494
touch "$pid_file" &> /dev/null || { echoRed "Operation not permitted (cannot access pid file)"; return 4; }

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,22 @@ public void startWhenStopped() throws Exception {
171171

172172
@Test
173173
public void basicLaunch() throws Exception {
174-
doLaunch("basic-launch.sh");
174+
String output = doTest("basic-launch.sh");
175+
assertThat(output).doesNotContain("PID_FOLDER");
176+
}
177+
178+
@Test
179+
public void launchWithMissingLogFolderGeneratesAWarning() throws Exception {
180+
String output = doTest("launch-with-missing-log-folder.sh");
181+
assertThat(output).has(coloredString(AnsiColor.YELLOW,
182+
"LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
183+
}
184+
185+
@Test
186+
public void launchWithMissingPidFolderGeneratesAWarning() throws Exception {
187+
String output = doTest("launch-with-missing-pid-folder.sh");
188+
assertThat(output).has(coloredString(AnsiColor.YELLOW,
189+
"PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
175190
}
176191

177192
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source ./test-functions.sh
2+
install_service
3+
echo 'LOG_FOLDER=/does/not/exist' > /test-service/spring-boot-app.conf
4+
start_service
5+
await_app
6+
curl -s http://127.0.0.1:8080/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source ./test-functions.sh
2+
install_service
3+
echo 'PID_FOLDER=/does/not/exist' > /test-service/spring-boot-app.conf
4+
start_service
5+
await_app
6+
curl -s http://127.0.0.1:8080/

0 commit comments

Comments
 (0)