Skip to content

Commit 30ea133

Browse files
committed
Merge pull request #7171 from lucassaldanha/gh-7121
* pr/7171: Make stop wait time in the launch script configurable
2 parents 2e6749e + 534a9db commit 30ea133

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

spring-boot-docs/src/main/asciidoc/deployment.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ for Gradle and to `${project.name}` for Maven.
634634
|`useStartStopDaemon`
635635
|If the `start-stop-daemon` command, when it's available, should be used to control the
636636
process. Defaults to `true`.
637+
638+
|`stopWaitTime`
639+
|The default value for `STOP_WAIT_TIME`. Only valid for an `init.d` service.
640+
Defaults to 60 seconds.
637641
|===
638642

639643

@@ -694,6 +698,10 @@ The following environment properties are supported with the default script:
694698
|`DEBUG`
695699
|if not empty will set the `-x` flag on the shell process, making it easy to see the logic
696700
in the script.
701+
702+
|`STOP_WAIT_TIME`
703+
|The time in seconds to wait when stopping the application before forcing a shutdown
704+
(`60` by default).
697705
|===
698706

699707
NOTE: The `PID_FOLDER`, `LOG_FOLDER` and `LOG_FILENAME` variables are only valid for an

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ fi
7373
# Initialize log file name if not provided by the config file
7474
[[ -z "$LOG_FILENAME" ]] && LOG_FILENAME="{{logFilename:${identity}.log}}"
7575

76+
# Initialize stop wait time if not provided by the config file
77+
[[ -z "$STOP_WAIT_TIME" ]] && STOP_WAIT_TIME={{stopWaitTime:60}}
78+
7679
# ANSI Colors
7780
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
7881
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
@@ -191,9 +194,9 @@ stop() {
191194

192195
do_stop() {
193196
kill "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; }
194-
for i in $(seq 1 60); do
197+
for i in $(seq 1 $STOP_WAIT_TIME); do
195198
isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; }
196-
[[ $i -eq 30 ]] && kill "$1" &> /dev/null
199+
[[ $i -eq STOP_WAIT_TIME/2 ]] && kill "$1" &> /dev/null
197200
sleep 1
198201
done
199202
echoRed "Unable to kill process $1";

spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/DefaultLaunchScriptTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public void confFolderCanBeReplaced() throws Exception {
111111
assertThatPlaceholderCanBeReplaced("confFolder");
112112
}
113113

114+
@Test
115+
public void stopWaitTimeCanBeReplaced() throws Exception {
116+
assertThatPlaceholderCanBeReplaced("stopWaitTime");
117+
}
118+
114119
@Test
115120
public void defaultForUseStartStopDaemonIsTrue() throws Exception {
116121
DefaultLaunchScript script = new DefaultLaunchScript(null, null);
@@ -125,6 +130,13 @@ public void defaultForModeIsAuto() throws Exception {
125130
assertThat(content).contains("MODE=\"auto\"");
126131
}
127132

133+
@Test
134+
public void defaultForStopWaitTimeIs60() throws Exception {
135+
DefaultLaunchScript script = new DefaultLaunchScript(null, null);
136+
String content = new String(script.toByteArray());
137+
assertThat(content).contains("STOP_WAIT_TIME=60");
138+
}
139+
128140
@Test
129141
public void loadFromFile() throws Exception {
130142
File file = this.temporaryFolder.newFile();

0 commit comments

Comments
 (0)