Commit 509be747 authored by Gaurav Rawat's avatar Gaurav Rawat Committed by Phillip Webb

Add `force-stop` support to launch script

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

Closes gh-6223
parent 3c930347
...@@ -118,6 +118,14 @@ public class SysVinitLaunchScriptIT { ...@@ -118,6 +118,14 @@ public class SysVinitLaunchScriptIT {
.has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)")); .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 @Test
public void startWhenStarted() throws Exception { public void startWhenStarted() throws Exception {
String output = doTest("start-when-started.sh"); String output = doTest("start-when-started.sh");
......
source ./test-functions.sh
install_service
force_stop_service
echo "Status: $?"
...@@ -21,6 +21,10 @@ stop_service() { ...@@ -21,6 +21,10 @@ stop_service() {
service spring-boot-app stop service spring-boot-app stop
} }
force_stop_service() {
service spring-boot-app force-stop
}
await_app() { await_app() {
if [ -z $1 ] if [ -z $1 ]
then then
......
...@@ -203,6 +203,24 @@ do_stop() { ...@@ -203,6 +203,24 @@ do_stop() {
return 1; 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() { restart() {
stop && start stop && start
} }
...@@ -242,6 +260,8 @@ start) ...@@ -242,6 +260,8 @@ start)
start "$@"; exit $?;; start "$@"; exit $?;;
stop) stop)
stop "$@"; exit $?;; stop "$@"; exit $?;;
force-stop)
force_stop "$@"; exit $?;;
restart) restart)
restart "$@"; exit $?;; restart "$@"; exit $?;;
force-reload) force-reload)
......
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