Browse Source

Add `force-stop` support to launch script

Update the embedded launch script to support `force-stop`.

Closes gh-6223
pull/7796/head
Gaurav Rawat 10 years ago committed by Phillip Webb
parent
commit
509be7474d
  1. 8
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java
  2. 4
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/force-stop-when-stopped.sh
  3. 4
      spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh
  4. 20
      spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

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

@ -118,6 +118,14 @@ public class SysVinitLaunchScriptIT { @@ -118,6 +118,14 @@ public class SysVinitLaunchScriptIT {
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
}
@Test
public void forceStopWhenStopped() throws Exception {
String output = doTest("force-stop-when-stopped.sh");
assertThat(output).contains("Status: 0");
assertThat(output)
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
}
@Test
public void startWhenStarted() throws Exception {
String output = doTest("start-when-started.sh");

4
spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/force-stop-when-stopped.sh

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
source ./test-functions.sh
install_service
force_stop_service
echo "Status: $?"

4
spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/resources/scripts/test-functions.sh

@ -21,6 +21,10 @@ stop_service() { @@ -21,6 +21,10 @@ stop_service() {
service spring-boot-app stop
}
force_stop_service() {
service spring-boot-app force-stop
}
await_app() {
if [ -z $1 ]
then

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

@ -203,6 +203,24 @@ do_stop() { @@ -203,6 +203,24 @@ do_stop() {
return 1;
}
force_stop() {
[[ -f $pid_file ]] || { echoYellow "Not running (pidfile not found)"; return 0; }
pid=$(cat "$pid_file")
isRunning "$pid" || { echoYellow "Not running (process ${pid}). Removing stale pid file."; rm -f "$pid_file"; return 0; }
do_force_stop "$pid" "$pid_file"
}
do_force_stop() {
kill -9 "$1" &> /dev/null || { echoRed "Unable to kill process $1"; return 1; }
for i in $(seq 1 60); do
isRunning "$1" || { echoGreen "Stopped [$1]"; rm -f "$2"; return 0; }
[[ $i -eq 30 ]] && kill -9 "$1" &> /dev/null
sleep 1
done
echoRed "Unable to kill process $1";
return 1;
}
restart() {
stop && start
}
@ -242,6 +260,8 @@ start) @@ -242,6 +260,8 @@ start)
start "$@"; exit $?;;
stop)
stop "$@"; exit $?;;
force-stop)
force_stop "$@"; exit $?;;
restart)
restart "$@"; exit $?;;
force-reload)

Loading…
Cancel
Save