Commit 534a9db6 authored by Lucas Saldanha's avatar Lucas Saldanha Committed by Phillip Webb

Make stop wait time in the launch script configurable

Create a parameter `STOP_WAIT_TIME` for the startup script
that configures the time in seconds to wait for a normal
shutdown. Because of #4941 we also send a shutdown half
way the countdown.

Fixes gh-7121
parent 2e6749e9
...@@ -634,6 +634,10 @@ for Gradle and to `${project.name}` for Maven. ...@@ -634,6 +634,10 @@ for Gradle and to `${project.name}` for Maven.
|`useStartStopDaemon` |`useStartStopDaemon`
|If the `start-stop-daemon` command, when it's available, should be used to control the |If the `start-stop-daemon` command, when it's available, should be used to control the
process. Defaults to `true`. process. Defaults to `true`.
|`stopWaitTime`
|The default value for `STOP_WAIT_TIME`. Only valid for an `init.d` service.
Defaults to 60 seconds.
|=== |===
...@@ -694,6 +698,10 @@ The following environment properties are supported with the default script: ...@@ -694,6 +698,10 @@ The following environment properties are supported with the default script:
|`DEBUG` |`DEBUG`
|if not empty will set the `-x` flag on the shell process, making it easy to see the logic |if not empty will set the `-x` flag on the shell process, making it easy to see the logic
in the script. in the script.
|`STOP_WAIT_TIME`
|The time in seconds to wait when stopping the application before forcing a shutdown
(`60` by default).
|=== |===
NOTE: The `PID_FOLDER`, `LOG_FOLDER` and `LOG_FILENAME` variables are only valid for an NOTE: The `PID_FOLDER`, `LOG_FOLDER` and `LOG_FILENAME` variables are only valid for an
......
...@@ -73,6 +73,9 @@ fi ...@@ -73,6 +73,9 @@ fi
# Initialize log file name if not provided by the config file # Initialize log file name if not provided by the config file
[[ -z "$LOG_FILENAME" ]] && LOG_FILENAME="{{logFilename:${identity}.log}}" [[ -z "$LOG_FILENAME" ]] && LOG_FILENAME="{{logFilename:${identity}.log}}"
# Initialize stop wait time if not provided by the config file
[[ -z "$STOP_WAIT_TIME" ]] && STOP_WAIT_TIME={{stopWaitTime:60}}
# ANSI Colors # ANSI Colors
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; } echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; } echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
...@@ -191,9 +194,9 @@ stop() { ...@@ -191,9 +194,9 @@ stop() {
do_stop() { do_stop() {
kill "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; } kill "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; }
for i in $(seq 1 60); do for i in $(seq 1 $STOP_WAIT_TIME); do
isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; } isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; }
[[ $i -eq 30 ]] && kill "$1" &> /dev/null [[ $i -eq STOP_WAIT_TIME/2 ]] && kill "$1" &> /dev/null
sleep 1 sleep 1
done done
echoRed "Unable to kill process $1"; echoRed "Unable to kill process $1";
......
...@@ -111,6 +111,11 @@ public class DefaultLaunchScriptTests { ...@@ -111,6 +111,11 @@ public class DefaultLaunchScriptTests {
assertThatPlaceholderCanBeReplaced("confFolder"); assertThatPlaceholderCanBeReplaced("confFolder");
} }
@Test
public void stopWaitTimeCanBeReplaced() throws Exception {
assertThatPlaceholderCanBeReplaced("stopWaitTime");
}
@Test @Test
public void defaultForUseStartStopDaemonIsTrue() throws Exception { public void defaultForUseStartStopDaemonIsTrue() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null); DefaultLaunchScript script = new DefaultLaunchScript(null, null);
...@@ -125,6 +130,13 @@ public class DefaultLaunchScriptTests { ...@@ -125,6 +130,13 @@ public class DefaultLaunchScriptTests {
assertThat(content).contains("MODE=\"auto\""); assertThat(content).contains("MODE=\"auto\"");
} }
@Test
public void defaultForStopWaitTimeIs60() throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null, null);
String content = new String(script.toByteArray());
assertThat(content).contains("STOP_WAIT_TIME=60");
}
@Test @Test
public void loadFromFile() throws Exception { public void loadFromFile() throws Exception {
File file = this.temporaryFolder.newFile(); File file = this.temporaryFolder.newFile();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment