Add `force-stop` support to launch script

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

Closes gh-6223
pull/7796/head
Gaurav Rawat 9 years ago committed by Phillip Webb
parent 3c930347c5
commit 509be7474d

@ -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");

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

@ -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() {
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)
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)

Loading…
Cancel
Save