Merge "Enhance k8s-container-cleanup.sh to operate during upgrade abort"
This commit is contained in:
commit
e103183164
|
@ -26,27 +26,43 @@ function ERROR {
|
||||||
logger -p daemon.error -t "${NAME}($$): " "${@}"
|
logger -p daemon.error -t "${NAME}($$): " "${@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
state=$(timeout 10 systemctl is-system-running)
|
function do_force_clean {
|
||||||
RC=$?
|
LOG "Stopping all containers."
|
||||||
LOG "System state is: ${state}, RC = ${RC}."
|
# Use crictl to gracefully stop each container. If specified timeout is
|
||||||
case ${RC} in
|
# reached, it forcibly kills the container. There is no need to check
|
||||||
124)
|
# return code since there is nothing more we can do, and crictl already
|
||||||
# systemctl hung.
|
# logs to daemon.log.
|
||||||
ERROR "systemctl timed out. System state unknown."
|
crictl ps -q | xargs -n 10 -r crictl stop --timeout 5
|
||||||
;;
|
LOG "Stopping all containers completed."
|
||||||
|
}
|
||||||
|
|
||||||
[01])
|
case "$1" in
|
||||||
# 0 - running; 1 - initializing, starting, degraded, maintenance, stopping
|
|
||||||
if [ "${state}" = "stopping" ]; then
|
"")
|
||||||
LOG "Stopping all containers."
|
state=$(timeout 10 systemctl is-system-running)
|
||||||
# Use crictl to gracefully stop each container. If specified timeout is
|
RC=$?
|
||||||
# reached, it forcibly kills the container. There is no need to check
|
LOG "System state is: ${state}, RC = ${RC}."
|
||||||
# return code since there is nothing more we can do, and crictl already
|
case ${RC} in
|
||||||
# logs to daemon.log.
|
124)
|
||||||
crictl ps -q | xargs -r -I {} crictl stop --timeout 5 {}
|
# systemctl hung.
|
||||||
LOG "Stopping all containers completed."
|
ERROR "systemctl timed out. System state unknown."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
;;
|
||||||
|
|
||||||
|
1)
|
||||||
|
# 1 - initializing, starting, degraded, maintenance, stopping
|
||||||
|
if [ "${state}" = "stopping" ]; then
|
||||||
|
do_force_clean
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
force-clean)
|
||||||
|
do_force_clean
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "usage: $0 { force-clean }" >&2
|
||||||
|
exit 3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue