Skip to content

Commit 0807f48

Browse files
authored
Merge pull request #2774 from kkimurak/issue/2773-handle-db-clients-already-uninstalled
Fix unused client removal on restarted container
2 parents 456fc76 + 7140f03 commit 0807f48

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)