[core]: tools.func - better verbose for postgresql (#7173)

This commit is contained in:
CanbiZ 2025-08-25 14:20:30 +02:00 committed by GitHub
parent 9a92df420e
commit 69dd06b107
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -161,19 +161,19 @@ function setup_postgresql() {
if [[ "$CURRENT_PG_VERSION" == "$PG_VERSION" ]]; then if [[ "$CURRENT_PG_VERSION" == "$PG_VERSION" ]]; then
: # PostgreSQL is already at the desired version no action needed : # PostgreSQL is already at the desired version no action needed
else else
msg_info "Detected PostgreSQL $CURRENT_PG_VERSION, preparing upgrade to $PG_VERSION" $STD msg_info "Detected PostgreSQL $CURRENT_PG_VERSION, preparing upgrade to $PG_VERSION"
NEED_PG_INSTALL=true NEED_PG_INSTALL=true
fi fi
else else
msg_info "Setup PostgreSQL $PG_VERSION"
NEED_PG_INSTALL=true NEED_PG_INSTALL=true
fi fi
if [[ "$NEED_PG_INSTALL" == true ]]; then if [[ "$NEED_PG_INSTALL" == true ]]; then
if [[ -n "$CURRENT_PG_VERSION" ]]; then if [[ -n "$CURRENT_PG_VERSION" ]]; then
msg_info "Dumping PostgreSQL $CURRENT_PG_VERSION data" $STD msg_info "Dumping PostgreSQL $CURRENT_PG_VERSION data"
su - postgres -c "pg_dumpall > /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql" su - postgres -c "pg_dumpall > /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql"
msg_ok "Data dump completed" $STD msg_ok "Data dump completed"
systemctl stop postgresql systemctl stop postgresql
fi fi
@ -186,29 +186,30 @@ function setup_postgresql() {
echo "deb https://apt.postgresql.org/pub/repos/apt ${DISTRO}-pgdg main" \ echo "deb https://apt.postgresql.org/pub/repos/apt ${DISTRO}-pgdg main" \
>/etc/apt/sources.list.d/pgdg.list >/etc/apt/sources.list.d/pgdg.list
$STD msg_ok "Repository added"
$STD apt-get update $STD apt-get update
$STD msg_ok "Repository added"
msg_info "Setup PostgreSQL $PG_VERSION" msg_info "Setup PostgreSQL $PG_VERSION"
$STD apt-get install -y "postgresql-${PG_VERSION}" "postgresql-client-${PG_VERSION}" $STD apt-get install -y "postgresql-${PG_VERSION}" "postgresql-client-${PG_VERSION}"
msg_ok "Setup PostgreSQL $PG_VERSION"
if [[ -n "$CURRENT_PG_VERSION" ]]; then if [[ -n "$CURRENT_PG_VERSION" ]]; then
$STD apt-get purge -y "postgresql-${CURRENT_PG_VERSION}" "postgresql-client-${CURRENT_PG_VERSION}" || true $STD apt-get purge -y "postgresql-${CURRENT_PG_VERSION}" "postgresql-client-${CURRENT_PG_VERSION}" || true
fi fi
$STD msg_info "Starting PostgreSQL $PG_VERSION"
systemctl enable -q --now postgresql systemctl enable -q --now postgresql
$STD msg_ok "PostgreSQL $PG_VERSION started"
if [[ -n "$CURRENT_PG_VERSION" ]]; then if [[ -n "$CURRENT_PG_VERSION" ]]; then
msg_info "Restoring dumped data" $STD msg_info "Restoring dumped data"
su - postgres -c "psql < /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql" su - postgres -c "psql < /var/lib/postgresql/backup_$(date +%F)_v${CURRENT_PG_VERSION}.sql"
msg_ok "Data restored" $STD msg_ok "Data restored"
fi fi
msg_ok "PostgreSQL $PG_VERSION installed" $STD msg_ok "PostgreSQL $PG_VERSION installed"
fi fi
# Install optional PostgreSQL modules # Install optional PostgreSQL modules
@ -216,13 +217,13 @@ function setup_postgresql() {
IFS=',' read -ra MODULES <<<"$PG_MODULES" IFS=',' read -ra MODULES <<<"$PG_MODULES"
for module in "${MODULES[@]}"; do for module in "${MODULES[@]}"; do
local pkg="postgresql-${PG_VERSION}-${module}" local pkg="postgresql-${PG_VERSION}-${module}"
msg_info "Setup PostgreSQL module/s: $pkg" $STD msg_info "Setup PostgreSQL module/s: $pkg"
$STD apt-get install -y "$pkg" || { $STD apt-get install -y "$pkg" || {
msg_error "Failed to install $pkg" msg_error "Failed to install $pkg"
continue continue
} }
done done
msg_ok "Setup PostgreSQL modules" $STD msg_ok "Setup PostgreSQL modules"
fi fi
} }