Merge pull request #6223 from gauravbrills/patch-1
* pr/6223: Add `force-stop` support to launch script
This commit is contained in:
commit
75186d42da
|
|
@ -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…
Reference in New Issue