Skip to content

Commit 7140f03

Browse files
committed
Fix unused client removal on restarted container
Handle the case where the target does not exist in the process of deleting unused clients. Such a situation will not occur in newly launched containers, but will occur if they are restarted. During container restarts, container status are preserved. If the unused database client was deleted in the last run, grep will not match anything. It returns non-zero code and the container stops there because entrypoint sets option `-e` (exit immediately on non-zero exit code excluding some special cases) This commit make the uninstall process to handle the case UNUSED_DB_CLIENTS is empty.
1 parent 456fc76 commit 7140f03

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

assets/runtime/functions

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,16 @@ gitlab_uninstall_unused_database_client() {
237237
REGEX_DB_CLIENT_VERSIONS_IN_USE="-common${DB_CLIENT_VERSIONS_IN_USE}"
238238

239239
# remove unused client using regex above
240-
UNUSED_DB_CLIENTS=$(apt-cache pkgnames postgresql-client | grep -v -e "${REGEX_DB_CLIENT_VERSIONS_IN_USE}" | tr '\n' ' ')
240+
# grep may return non-zero code on mo match, so fake the exit code with the `|| true` to swallow that
241+
UNUSED_DB_CLIENTS=$(apt-cache pkgnames postgresql-client | grep -v -e "${REGEX_DB_CLIENT_VERSIONS_IN_USE}" || true)
242+
if [[ "${UNUSED_DB_CLIENTS}" == "" ]]; then
243+
echo "- All installed version of clients are in use. Did not uninstalled any client..."
244+
return
245+
fi
246+
247+
# just to get clean log, convert newline (package name delimiter) to single whitespace
248+
UNUSED_DB_CLIENTS=$(echo ${UNUSED_DB_CLIENTS} | tr '\n' ' ')
249+
241250
echo "- Uninstalling unused client(s): ${UNUSED_DB_CLIENTS}"
242251
DEBIAN_FRONTEND=noninteractive apt-get -qq -y purge -- ${UNUSED_DB_CLIENTS} >/dev/null
243252
fi

0 commit comments

Comments
 (0)