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
This commit is contained in:
parent
2e6749e916
commit
534a9db6fd
|
|
@ -634,6 +634,10 @@ for Gradle and to `${project.name}` for Maven.
|
|||
|`useStartStopDaemon`
|
||||
|If the `start-stop-daemon` command, when it's available, should be used to control the
|
||||
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:
|
|||
|`DEBUG`
|
||||
|if not empty will set the `-x` flag on the shell process, making it easy to see the logic
|
||||
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
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@ fi
|
|||
# Initialize log file name if not provided by the config file
|
||||
[[ -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
|
||||
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
|
||||
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
|
||||
|
|
@ -191,9 +194,9 @@ stop() {
|
|||
|
||||
do_stop() {
|
||||
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; }
|
||||
[[ $i -eq 30 ]] && kill "$1" &> /dev/null
|
||||
[[ $i -eq STOP_WAIT_TIME/2 ]] && kill "$1" &> /dev/null
|
||||
sleep 1
|
||||
done
|
||||
echoRed "Unable to kill process $1";
|
||||
|
|
|
|||
|
|
@ -111,6 +111,11 @@ public class DefaultLaunchScriptTests {
|
|||
assertThatPlaceholderCanBeReplaced("confFolder");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stopWaitTimeCanBeReplaced() throws Exception {
|
||||
assertThatPlaceholderCanBeReplaced("stopWaitTime");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultForUseStartStopDaemonIsTrue() throws Exception {
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(null, null);
|
||||
|
|
@ -125,6 +130,13 @@ public class DefaultLaunchScriptTests {
|
|||
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
|
||||
public void loadFromFile() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
|
|
|
|||
Loading…
Reference in New Issue