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