Merge pull request #7171 from lucassaldanha/gh-7121
* pr/7171: Make stop wait time in the launch script configurable
This commit is contained in:
		
						commit
						30ea1338de
					
				| 
						 | 
					@ -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:
 | 
				
			||||||
|`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
 | 
				
			||||||
# 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() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 {
 | 
				
			||||||
		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 {
 | 
				
			||||||
		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();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue