Merge pull request #2775 from sachilles/fix-handle-db-clients-already-uninstalled

Fix unused client removal on restarted container (backport from #2774)
This commit is contained in:
Steven Achilles 2023-06-04 00:32:30 +02:00 committed by GitHub
commit c77bcb38fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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