|
1 | 1 | #!/bin/bash |
2 | | - |
3 | | -# Copyright (c) 2017, 2022, Oracle and/or its affiliates. |
| 2 | +# Copyright (c) 2017, 2024, Oracle and/or its affiliates. |
4 | 3 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
5 | 4 |
|
6 | 5 | # |
@@ -46,17 +45,32 @@ export SHUTDOWN_TIMEOUT_ARG=${SHUTDOWN_TIMEOUT:-30} |
46 | 45 | # Calculate the wait timeout to issue "kill -9" before the pod is destroyed. |
47 | 46 | # Allow 3 seconds for the NFS v3 manager to detect the process destruction and release file locks. |
48 | 47 | export SIGKILL_WAIT_TIMEOUT=$(expr $SHUTDOWN_TIMEOUT_ARG - 3) |
49 | | -wait_and_kill_after_timeout(){ |
| 48 | + |
| 49 | +# Block until the given file appears or the given timeout is reached. |
| 50 | +wait_file() { |
| 51 | + local file="$1"; shift |
| 52 | + local wait_seconds="${1:-10}"; shift |
| 53 | + test $wait_seconds -lt 1 && echo 'At least 1 second is required' && return 1 |
| 54 | + |
| 55 | + until test $((wait_seconds--)) -eq 0 -o -e "$file" ; do sleep 1; done |
| 56 | + |
| 57 | + test $wait_seconds -ge 0 |
| 58 | +} |
| 59 | + |
| 60 | +wait_and_kill_after_timeout() { |
50 | 61 | trace "Wait for ${SIGKILL_WAIT_TIMEOUT} seconds for ${SERVER_NAME} to shut down." >> ${STOP_OUT_FILE} |
51 | 62 | sleep ${SIGKILL_WAIT_TIMEOUT} |
52 | | - trace "The server ${SERVER_NAME} didn't shut down in ${SIGKILL_WAIT_TIMEOUT} seconds, " \ |
53 | | - "killing the server processes." >> ${STOP_OUT_FILE} |
54 | | - # Adjust PATH if necessary before calling jps |
55 | | - adjustPath |
56 | | - |
57 | | - #Specifically killing the NM first as it can auto-restart a killed WL server. |
58 | | - kill -9 `jps -v | grep " NodeManager " | awk '{ print $1 }'` |
59 | | - kill -9 `jps -v | grep -v Jps | awk '{ print $1 }'` |
| 63 | + wait_file "${SHUTDOWN_MARKER_FILE}" ${SIGKILL_WAIT_TIMEOUT} || { |
| 64 | + trace "The server ${SERVER_NAME} didn't shut down in ${SIGKILL_WAIT_TIMEOUT} seconds, " \ |
| 65 | + "killing the server processes." >> ${STOP_OUT_FILE} |
| 66 | + # Adjust PATH if necessary before calling jps |
| 67 | + adjustPath |
| 68 | + |
| 69 | + #Specifically killing the NM first as it can auto-restart a killed WL server. |
| 70 | + kill -9 `jps -v | grep " NodeManager " | awk '{ print $1 }'` |
| 71 | + kill -9 `jps -v | grep -v Jps | awk '{ print $1 }'` |
| 72 | + } |
| 73 | + |
60 | 74 | touch ${SHUTDOWN_MARKER_FILE} |
61 | 75 | } |
62 | 76 |
|
@@ -106,8 +120,11 @@ check_for_shutdown() { |
106 | 120 |
|
107 | 121 |
|
108 | 122 | # Check if the server is already shutdown |
109 | | -check_for_shutdown |
110 | | -[ $? -eq 0 ] && trace "Server is already shutting down, is shutdown or failed" &>> ${STOP_OUT_FILE} && exit 0 |
| 123 | +if check_for_shutdown ; then |
| 124 | + trace "Server is already shutting down, is shutdown or failed" &>> ${STOP_OUT_FILE} |
| 125 | + touch ${SHUTDOWN_MARKER_FILE} |
| 126 | + exit 0 |
| 127 | +fi |
111 | 128 |
|
112 | 129 | # Otherwise, connect to the node manager and stop the server instance |
113 | 130 | [ ! -f "${SCRIPTPATH}/wlst.sh" ] && trace SEVERE "Missing file '${SCRIPTPATH}/wlst.sh'." && exit 1 |
|
0 commit comments