Skip to content

Commit 138d5d7

Browse files
committed
Update scripts so that container exits promptly after server shuts down
1 parent 7e7715a commit 138d5d7

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

operator/src/main/resources/scripts/startServer.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trace "Starting WebLogic Server '${SERVER_NAME}'."
2525
function exitOrLoop {
2626
if [ -f /weblogic-operator/debug/livenessProbeSuccessOverride ]
2727
then
28-
while true ; do sleep 60 ; done
28+
waitForShutdownMarker
2929
else
3030
exit 1
3131
fi
@@ -100,23 +100,21 @@ function waitUntilShutdown() {
100100
#
101101
if [ "${SERVER_OUT_IN_POD_LOG}" == 'true' ] ; then
102102
trace "Showing the server out file from ${SERVER_OUT_FILE}"
103-
tail -F -n +0 ${SERVER_OUT_FILE} || exitOrLoop
104-
else
105-
trace "Wait indefinitely so that the Kubernetes pod does not exit and try to restart"
106-
while true; do sleep 60; done
103+
${SCRIPTPATH}/tailLog.sh ${SERVER_OUT_FILE} &
107104
fi
105+
waitForShutdownMarker
108106
}
109107

110-
function mockWaitUntilShutdown() {
108+
function waitForShutdownMarker() {
111109
#
112110
# Wait forever. Kubernetes will monitor this pod via liveness and readyness probes.
113111
#
114112
trace "Wait indefinitely so that the Kubernetes pod does not exit and try to restart"
115113
while true; do
116-
if [ -e /u01/doShutdown ] ; then
114+
if [ -e /weblogic-operator/doShutdown ] ; then
117115
exit 0
118116
fi
119-
sleep 5
117+
sleep 3
120118
done
121119
}
122120

@@ -219,7 +217,7 @@ copySitCfg /weblogic-operator/introspector ${DOMAIN_HOME}/optconfig/diagnostics
219217

220218
if [ "${MOCK_WLS}" == 'true' ]; then
221219
mockWLS
222-
mockWaitUntilShutdown
220+
waitForShutdownMarker
223221
else
224222
startWLS
225223
waitUntilShutdown

operator/src/main/resources/scripts/stopServer.sh

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
1313
source ${SCRIPTPATH}/traceUtils.sh
1414
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/traceUtils.sh" && exit 1
1515

16-
trace "Stop server ${SERVER_NAME}" &>> /u01/oracle/stopserver.out
16+
trace "Stop server ${SERVER_NAME}" &>> /weblogic-operator/stopserver.out
1717

1818
checkEnv SERVER_NAME || exit 1
1919

2020
if [ "${MOCK_WLS}" == 'true' ]; then
21-
touch /u01/doShutdown
21+
touch /weblogic-operator/doShutdown
2222
exit 0
2323
fi
2424

@@ -28,27 +28,27 @@ function check_for_shutdown() {
2828
state=`${SCRIPTPATH}/readState.sh`
2929
exit_status=$?
3030
if [ $exit_status -ne 0 ]; then
31-
trace "Node manager not running or server instance not found; assuming shutdown" &>> /u01/oracle/stopserver.out
31+
trace "Node manager not running or server instance not found; assuming shutdown" &>> /weblogic-operator/stopserver.out
3232
return 0
3333
fi
3434

3535
if [ "$state" = "SHUTDOWN" ]; then
36-
trace "Server is shutdown" &>> /u01/oracle/stopserver.out
36+
trace "Server is shutdown" &>> /weblogic-operator/stopserver.out
3737
return 0
3838
fi
3939

4040
if [[ "$state" =~ ^FAILED ]]; then
41-
trace "Server in failed state" &>> /u01/oracle/stopserver.out
41+
trace "Server in failed state" &>> /weblogic-operator/stopserver.out
4242
return 0
4343
fi
4444

45-
trace "Server is currently in state $state" &>> /u01/oracle/stopserver.out
45+
trace "Server is currently in state $state" &>> /weblogic-operator/stopserver.out
4646
return 1
4747
}
4848

4949
# Check if the server is already shutdown
5050
check_for_shutdown
51-
[ $? -eq 0 ] && trace "Server already shutdown or failed" &>> /u01/oracle/stopserver.out && exit 0
51+
[ $? -eq 0 ] && trace "Server already shutdown or failed" &>> /weblogic-operator/stopserver.out && exit 0
5252

5353
# Otherwise, connect to the node manager and stop the server instance
5454
[ ! -f "${SCRIPTPATH}/wlst.sh" ] && trace "Error: missing file '${SCRIPTPATH}/wlst.sh'." && exit 1
@@ -60,28 +60,23 @@ export SHUTDOWN_TIMEOUT_ARG=${SHUTDOWN_TIMEOUT:-30}
6060
export SHUTDOWN_IGNORE_SESSIONS_ARG=${SHUTDOWN_IGNORE_SESSIONS:-false}
6161
export SHUTDOWN_TYPE_ARG=${SHUTDOWN_TYPE:-Graceful}
6262

63-
trace "Before stop-server.py [${SERVER_NAME}] ${SCRIPTDIR}" &>> /u01/oracle/stopserver.out
64-
${SCRIPTPATH}/wlst.sh /weblogic-operator/scripts/stop-server.py &>> /u01/oracle/stopserver.out
65-
trace "After stop-server.py" &>> /u01/oracle/stopserver.out
63+
trace "Before stop-server.py [${SERVER_NAME}] ${SCRIPTDIR}" &>> /weblogic-operator/stopserver.out
64+
${SCRIPTPATH}/wlst.sh /weblogic-operator/scripts/stop-server.py &>> /weblogic-operator/stopserver.out
65+
trace "After stop-server.py" &>> /weblogic-operator/stopserver.out
6666

6767
# at this point node manager should have terminated the server
6868
# but let's try looking for the server process and
6969
# kill the server if the process still exists,
7070
# just in case we failed to stop it via wlst
7171
pid=$(jps -v | grep " -Dweblogic.Name=${SERVER_NAME} " | awk '{print $1}')
7272
if [ ! -z $pid ]; then
73-
echo "Killing the server process $pid" &>> /u01/oracle/stopserver.out
73+
echo "Killing the server process $pid" &>> /weblogic-operator/stopserver.out
7474
kill -15 $pid
7575
fi
7676

77-
# stop node manager process
78-
#
79-
trace "Stopping NodeManager" &>> /u01/oracle/stopserver.out
80-
pid=$(jps | grep "weblogic.NodeManager" | awk '{print $1}')
81-
trace "PID=[${pid}]" &>> /u01/oracle/stopserver.out
82-
if [ ! -z $pid ]; then
83-
echo "Killing NodeManager process $pid" &>> /u01/oracle/stopserver.out
84-
kill -9 $pid
77+
touch /weblogic-operator/doShutdown
78+
if [ -f /weblogic-operator/pid ]; then
79+
kill -2 $(</weblogic-operator/pid)
8580
fi
8681

87-
trace "Exit script" &>> /u01/oracle/stopserver.out
82+
trace "Exit script" &>> /weblogic-operator/stopserver.out
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
7+
#
8+
# This script is used to tail the server log and is separate from
9+
# startServer.sh so that it is easier to quickly kill the process
10+
# running this script.
11+
#
12+
13+
echo $$ > /weblogic-operator/pid
14+
tail -F -n +0 $1

operator/src/test/java/oracle/kubernetes/operator/helpers/ConfigMapHelperTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public class ConfigMapHelperTest {
6868
"startNodeManager.sh",
6969
"traceUtils.py",
7070
"traceUtils.sh",
71-
"wlst.sh"
71+
"wlst.sh",
72+
"tailLog.sh"
7273
};
7374

7475
private static final String introspectResult =

0 commit comments

Comments
 (0)