From 28af316a752401df3753873e060b3d299f75255b Mon Sep 17 00:00:00 2001 From: Mark Feit Date: Wed, 10 Jan 2024 22:39:35 +0000 Subject: [PATCH] Removed all EL7/8-specific accommodations for PostgreSQL. #1385 --- postgresql-init/Makefile | 2 - postgresql-init/postgresql-init/Makefile | 83 --------- .../postgresql-init/initialize-postgresql.raw | 54 ------ .../rpm/postgresql-init.spec | 89 ---------- .../postgresql-init/upgrade-postgresql.raw | 167 ------------------ .../rpm/postgresql-init.spec | 81 +++++++++ .../rpm/postgresql-load.spec | 2 +- .../rpm/pscheduler-rpm.spec | 17 +- .../rpm/pscheduler-server.spec | 22 +-- unibuild-order | 1 - 10 files changed, 95 insertions(+), 423 deletions(-) delete mode 100644 postgresql-init/postgresql-init/Makefile delete mode 100755 postgresql-init/postgresql-init/initialize-postgresql.raw delete mode 100644 postgresql-init/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec delete mode 100755 postgresql-init/postgresql-init/upgrade-postgresql.raw create mode 100644 postgresql-init/unibuild-packaging/rpm/postgresql-init.spec diff --git a/postgresql-init/Makefile b/postgresql-init/Makefile index 413b497973..25bcfb5e7d 100644 --- a/postgresql-init/Makefile +++ b/postgresql-init/Makefile @@ -2,6 +2,4 @@ # Makefile for Any Package # -AUTO_TARBALL := 1 - include unibuild/unibuild.make diff --git a/postgresql-init/postgresql-init/Makefile b/postgresql-init/postgresql-init/Makefile deleted file mode 100644 index 1ed3173039..0000000000 --- a/postgresql-init/postgresql-init/Makefile +++ /dev/null @@ -1,83 +0,0 @@ -# -# Makefile for postgresql-init -# - -PROGRAMS := \ - initialize-postgresql \ - upgrade-postgresql - -default: build - - -%: %.raw -ifndef PG_DATA_DIR - @echo No PG_DATA_DIR specified for installation - @false -endif -ifndef PG_GROUP - @echo No PG_GROUP specified for installation - @false -endif -ifndef PG_INITDB - @echo No PG_INITDB specified for installation - @false -endif -ifndef PG_LIB - @echo No PG_LIB specified for installation - @false -endif -ifndef PG_SERVICE - @echo No PG_SERVICE specified for installation - @false -endif -ifndef PG_USER - @echo No PG_USER specified for installation - @false -endif -ifndef PG_USER - @echo No PG_USER specified for installation - @false -endif -ifndef PG_VERSION_FILE - @echo No PG_VERSION_FILE specified for installation - @false -endif -ifndef USR - @echo No USR specified for installation - @false -endif - sed \ - -e "s|__PG_DATA_DIR__|$(PG_DATA_DIR)|g" \ - -e "s|__PG_GROUP__|$(PG_GROUP)|g" \ - -e "s|__PG_INITDB__|$(PG_INITDB)|g" \ - -e "s|__PG_LIB__|$(PG_LIB)|g" \ - -e "s|__PG_SERVICE__|$(PG_SERVICE)|g" \ - -e "s|__PG_VERSION_FILE__|$(PG_VERSION_FILE)|g" \ - -e "s|__PG_USER__|$(PG_USER)|g" \ - -e "s|__USR__|$(USR)|g" \ - $< > $@ - -build: $(PROGRAMS) -TO_CLEAN += $(PROGRAMS) - - -$(DESTDIR): - mkdir -p $@ - - -$(DESTDIR)/%: % - install -m 555 $< $@ - -INSTALLED := $(PROGRAMS:%=$(DESTDIR)/%) -$(INSTALLED): $(DESTDIR) - - -install: $(INSTALLED) -ifndef DESTDIR - @echo No DESTDIR specified for installation - @false -endif - - -clean: - rm -f $(TO_CLEAN) *~ diff --git a/postgresql-init/postgresql-init/initialize-postgresql.raw b/postgresql-init/postgresql-init/initialize-postgresql.raw deleted file mode 100755 index 7c70548d8c..0000000000 --- a/postgresql-init/postgresql-init/initialize-postgresql.raw +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -e -# -# Find the highest installed version of PostgreSQL and initialize it. -# - -if [ $(id -u) -ne 0 ] -then - echo "This program must be run as root." 1>&2 - exit 1 -fi - - -# These are wired in by the build process. -PG_DATA_DIR="__PG_DATA_DIR__" -PG_GROUP="__PG_GROUP__" -PG_INITDB="__PG_INITDB__" -PG_SERVICE="__PG_SERVICE__" -PG_USER="__PG_USER__" -PG_VERSION_FILE="__PG_VERSION_FILE__" - - -if [ -e "${PG_VERSION_FILE}" ] -then - exit 0 -fi - - -TMPBASE="${TMP:-/tmp}/${WHOAMI}.$$" -mkdir -p "${TMPBASE}" -# The upgrade process runs as PG_USER and writes here. -chown "${PG_USER}:${PG_GROUP}" "${TMPBASE}" - -cleanup() -{ - rm -rf ${TMPBASE} -} - -trap cleanup EXIT - - -# Initialize PostgreSQL - -systemctl stop "${PG_SERVICE}" - -echo "Initializing PostgreSQL." - -# TODO: Recreating the directory is really only necessary on EL7. -rm -rf "${PG_DATA_DIR}" -mkdir -p "${PG_DATA_DIR}" -chown -R "${PG_USER}:${PG_USER}" "${PG_DATA_DIR}" - -sh -c "${PG_INITDB}" - -systemctl start "${PG_SERVICE}" diff --git a/postgresql-init/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec b/postgresql-init/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec deleted file mode 100644 index b9740eb8cb..0000000000 --- a/postgresql-init/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec +++ /dev/null @@ -1,89 +0,0 @@ -# -# RPM Spec for PostgreSQL Initializer -# - -Name: postgresql-init - -# Note that the dot after this is for versions of this package rather -# than the Pg relese. -Version: %{_pscheduler_postgresql_version}.1 -Release: 1%{?dist} - -Summary: Initializes and upgrades PostgreSQL -BuildArch: noarch - -License: Apache 2.0 -Group: Unspecified - -Source: %{name}-%{version}.tar.gz - -Provides: %{name} = %{version}-%{release} -#As of 4.3 we can probably get rid of below, but keep around until 4.4 to handle strange upgrade paths. -Provides: pscheduler-database-init - - -# NOTE: This is something of a hack because it forces installation of -# all packages that are likely to be used. It's necessary because -# pg_upgrade will refuse to work if required libraries are absent. - -Requires: %{_pscheduler_postgresql_package} >= %{_pscheduler_postgresql_version} -Requires: %{_pscheduler_postgresql_package}-contrib >= %{_pscheduler_postgresql_version} -Requires: %{_pscheduler_postgresql_package}-devel >= %{_pscheduler_postgresql_version} -Requires: %{_pscheduler_postgresql_package}-libs >= %{_pscheduler_postgresql_version} - -Requires: %{_pscheduler_postgresql_plpython} >= %{_pscheduler_postgresql_version} -Requires: %{_pscheduler_postgresql_package}-server >= %{_pscheduler_postgresql_version} - - -BuildRequires: pscheduler-rpm - - -# NOTE: It would be nice if this version could obsolete older packages -# so they're uninstalled. There's a conflict with packages that -# haven't been upgraded yet and still depend on the old one, so the -# best thing that can be done is disabling the older one and enabling -# the newer one. - - - -%description -Installing this package initializes the PostgreSQL server, upgrades -the data from and disables any previous versions, starts it and makes -sure it runs at boot. - - -%define libexec %{_libexecdir}/%{name} - -%prep -%setup -q - - -%build -make \ - DESTDIR="${RPM_BUILD_ROOT}/%{libexec}" \ - PG_DATA_DIR="%{_pscheduler_postgresql_data}" \ - PG_GROUP="%{_pscheduler_postgresql_group}" \ - PG_INITDB="%{_pscheduler_postgresql_initdb}" \ - PG_LIB="%{_pscheduler_postgresql_data_top}" \ - PG_SERVICE="%{_pscheduler_postgresql_service}" \ - PG_USER="%{_pscheduler_postgresql_user}" \ - PG_VERSION_FILE="%{_pscheduler_postgresql_version_file}" \ - USR="%{_usr}" \ - install - - - -%post - -# TODO: If any of this fails, the install doesn't. Find a way around this. - -set -e - -%{libexec}/initialize-postgresql - -# Set up run at boot -systemctl enable --now %{_pscheduler_postgresql_service} - - -%files -%{libexec} diff --git a/postgresql-init/postgresql-init/upgrade-postgresql.raw b/postgresql-init/postgresql-init/upgrade-postgresql.raw deleted file mode 100755 index 29a13661b3..0000000000 --- a/postgresql-init/postgresql-init/upgrade-postgresql.raw +++ /dev/null @@ -1,167 +0,0 @@ -#!/bin/sh -e -# -# Find the two installed versions of PostgreSQL and upgrade the -# earlier to the later. Note that this will upgrade across more than -# one major version, which postgresql-xx-setup doesn't. -# - -# NOTE: This script should only be run on EL7; EL8 self-upgrades. - -# These are wired in by the build process. -PG_LIB="__PG_LIB__" -USR="__USR__" -PG_USR_PATTERN="pgsql-%s" -PG_BIN="${USR}/${PG_USR_PATTERN}/bin" -PG_USER="__PG_USER__" - - -[ $(id -u) -eq 0 ] \ - || die "This program must be run as root." - - -TMPBASE="${TMP:-/tmp}/$(basename $0).$$" -mkdir -p "${TMPBASE}" -# The upgrade process runs as PG_USER and writes here. -chown "${PG_USER}:${PG_USER}" "${TMPBASE}" - -cleanup() -{ - rm -rf ${TMPBASE} -} - -trap cleanup EXIT - - -die() -{ - echo "$@" 1>&2 - exit 1 -} - - -# -# Figure out what versions of PostgreSQL are installed -# - -VERSIONS="${TMPBASE}/versions" - -CHOP=$(echo "$PG_USR_PATTERN" | sed -e 's|%.*$||') - -ls "${USR}" \ - | egrep -e "^${CHOP}" \ - | sed -e "s|${CHOP}||g" \ - | sort -n \ - | uniq \ - > "${VERSIONS}" - - -case $(wc -l "${VERSIONS}" | awk '{ print $1 }') in - 0|1) - exit 0 - ;; - 2) - # Two is the magic number. - true - ;; - - *) - die "Can't handle more than two installed versions of PostgreSQL." - ;; -esac - - -# -# Figure out versions and paths -# - -# What we're upgrading from - -FROM=$(head -1 "${VERSIONS}") -FROM_BIN=$(printf "${PG_BIN}" "${FROM}") -FROM_DATA="${PG_LIB}/${FROM}/data" -if [ ! -e "${FROM_DATA}/PG_VERSION" ] -then - echo "Old PostgreSQL ${FROM} is not initialized; no upgrade needed." - exit 0 -fi - -FROM_ENCODING=$(su - "${PG_USER}" \ - -c "'${FROM_BIN}/psql' --single-line --no-align --tuples-only -c 'SHOW server_encoding;'") - -FROM_LOCALE=$(su - "${PG_USER}" \ - -c "'${FROM_BIN}/psql' --single-line --no-align --tuples-only -c 'SHOW lc_collate;'") - - - -# What we're upgrading to. - -TO=$(tail -1 "${VERSIONS}") -TO_BIN=$(printf "${PG_BIN}" "${TO}") -TO_DATA="${PG_LIB}/${TO}/data" -[ -d "${TO_DATA}" ] \ - || die "No data directory for new ${TO} (expected ${TO_DATA})" - - - -# -# Do the deed -# - -# The new and old versions must be stopped for this operation -# TODO: This will vary by distro -systemctl stop "postgresql-${FROM}" -systemctl stop "postgresql-${TO}" - -# If the new version has been initialized, back it up instead of clobbering it. -if [ -e "${TO_DATA}/PG_VERSION" ] -then - echo "Warning: Postgresql ${TO} is already initialized. Backing that up first." - mv "${TO_DATA}" "${TO_DATA}-$(date +%Y-%m-%dT%T)" - mkdir -p "${TO_DATA}" - chown "${PG_USER}:${PG_USER}" "${TO_DATA}" -fi - - -echo -echo "#" -echo "# Upgrading PostgreSQL ${FROM} to ${TO}" -echo "#" -echo - -# Initialize the database -echo "Initializing ${TO} with encoding '${FROM_ENCODING}' and locale '${FROM_LOCALE}'" -su - "${PG_USER}" \ - -c "'${TO_BIN}/initdb' --pgdata '${TO_DATA}' --encoding '${FROM_ENCODING}' --locale '${FROM_LOCALE}'" -echo - -# Do the upgrade -su - "${PG_USER}" -c \ - "cd '${TMPBASE}' && '${TO_BIN}/pg_upgrade' \ - -d '${FROM_DATA}' \ - -D '${TO_DATA}' \ - -b '${FROM_BIN}' \ - -B '${TO_BIN}' \ - -U '${PG_USER}' \ - --retain" - - -# Disable the old and restart the new version -# TODO: This will vary by distro -systemctl disable --now "postgresql-${FROM}" -systemctl enable --now "postgresql-${TO}" - - -# These two scripts are written by pg_upgrade. - -# Make the new version ready for action -su - "${PG_USER}" -c "${TMPBASE}/analyze_new_cluster.sh" - -# Remove the old one -su - "${PG_USER}" -c "${TMPBASE}/delete_old_cluster.sh" - - -echo -echo "#" -echo "# Successfully Upgraded PostgreSQL ${FROM} to ${TO}" -echo "#" -echo diff --git a/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec b/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec new file mode 100644 index 0000000000..1641aa0f42 --- /dev/null +++ b/postgresql-init/unibuild-packaging/rpm/postgresql-init.spec @@ -0,0 +1,81 @@ +# +# RPM Spec for PostgreSQL Initializer +# + +Name: postgresql-init + +# Note that the dot after this is for versions of this package rather +# than the Pg relese. +Version: %{_pscheduler_postgresql_version}.1 +Release: 1%{?dist} + +Summary: Initializes PostgreSQL +BuildArch: noarch + +License: Apache 2.0 +Group: Unspecified + +# No source file. +# Source: %{name}-%{version}.tar.gz + +Provides: %{name} = %{version}-%{release} + +# TODO: This isn't harmful but can probably go. + +# NOTE: This is something of a hack because it forces installation of +# all packages that are likely to be used. It's necessary because +# pg_upgrade will refuse to work if required libraries are absent. + +Requires: postgresql >= %{_pscheduler_postgresql_version} +Requires: postgresql-contrib >= %{_pscheduler_postgresql_version} +Requires: postgresql-devel >= %{_pscheduler_postgresql_version} +Requires: postgresql-libs >= %{_pscheduler_postgresql_version} +Requires: postgresql-plpython3 >= %{_pscheduler_postgresql_version} +Requires: postgresql-server >= %{_pscheduler_postgresql_version} + + +BuildRequires: pscheduler-rpm + + + +%description +Installing this package initializes the PostgreSQL server, starts it +and makes sure it runs at boot. + + +%define version_file %%{_pscheduler_postgresql_data}/PG_VERSION + + +# No prep or build. + + +%post + +# Note that if any of this fails, the install doesn't. This is an +# problem inherent in RPM that the developers won't fix. + +set -e + + +if [ -e "${PG_VERSION_FILE}" ] +then + echo "PostgreSQL is already initialized. Doing nothing." + exit 0 +fi + + +# Initialize PostgreSQL + +systemctl stop postgresql + +echo 'Initializing PostgreSQL.' +postgresql-setup --initdb + +systemctl start postgresql + +# Set up run at boot +systemctl enable postgresql + + +%files +# No files. diff --git a/postgresql-load/postgresql-load/unibuild-packaging/rpm/postgresql-load.spec b/postgresql-load/postgresql-load/unibuild-packaging/rpm/postgresql-load.spec index 13f3d79fdb..7292915202 100644 --- a/postgresql-load/postgresql-load/unibuild-packaging/rpm/postgresql-load.spec +++ b/postgresql-load/postgresql-load/unibuild-packaging/rpm/postgresql-load.spec @@ -18,7 +18,7 @@ Source0: %{name}-%{version}.tar.gz Provides: %{name} = %{version}-%{release} -Requires: %{_pscheduler_postgresql_package}-server +Requires: postgresql-server Requires: procps-ng BuildRequires: pscheduler-rpm diff --git a/pscheduler-rpm/unibuild-packaging/rpm/pscheduler-rpm.spec b/pscheduler-rpm/unibuild-packaging/rpm/pscheduler-rpm.spec index 7320f5765b..8cf4030933 100644 --- a/pscheduler-rpm/unibuild-packaging/rpm/pscheduler-rpm.spec +++ b/pscheduler-rpm/unibuild-packaging/rpm/pscheduler-rpm.spec @@ -39,25 +39,12 @@ cat > $RPM_BUILD_ROOT/%{macro_prefix}%{name} <= %{_pscheduler_postgresql_version} BuildRequires: postgresql-load >= 1.2 -BuildRequires: %{_pscheduler_postgresql_package}-server >= %{_pscheduler_postgresql_version} -BuildRequires: %{_pscheduler_postgresql_package}-contrib >= %{_pscheduler_postgresql_version} -BuildRequires: %{_pscheduler_postgresql_plpython} >= %{_pscheduler_postgresql_version} +BuildRequires: postgresql-server >= %{_pscheduler_postgresql_version} +BuildRequires: postgresql-contrib >= %{_pscheduler_postgresql_version} +BuildRequires: postgresql-plpython3 >= %{_pscheduler_postgresql_version} Requires: drop-in Requires: gzip -Requires: %{_pscheduler_postgresql_package}-server >= %{_pscheduler_postgresql_version} +Requires: postgresql-server >= %{_pscheduler_postgresql_version} # This is for pgcrypto -Requires: %{_pscheduler_postgresql_package}-contrib >= %{_pscheduler_postgresql_version} -Requires: %{_pscheduler_postgresql_plpython} >= %{_pscheduler_postgresql_version} +Requires: postgresql-contrib >= %{_pscheduler_postgresql_version} +Requires: postgresql-plpython3 >= %{_pscheduler_postgresql_version} Requires: postgresql-load >= 1.2 Requires: pscheduler-account Requires: pscheduler-core @@ -157,7 +157,7 @@ make -C daemons \ LOGDIR=%{_pscheduler_log_dir} \ PGDATABASE=%{database_name} \ PGPASSFILE=%{_pscheduler_database_pgpass_file} \ - PGSERVICE=%{_pscheduler_postgresql_service}.service \ + PGSERVICE=postgresql.service \ PGUSER=%{_pscheduler_database_user} \ PSUSER=%{_pscheduler_user} \ ARCHIVERDEFAULTDIR=%{archiver_default_dir} \ @@ -363,7 +363,7 @@ EOF NEW_CONF_DIGEST=$(sha256sum "%{pgsql_conf}" | awk '{ print $1 }') -systemctl enable --now "%{_pscheduler_postgresql_service}" +systemctl enable --now postgresql # Restart the server only if the configuration has changed as a result # of what we did to it. This is more for development convenience than @@ -372,7 +372,7 @@ systemctl enable --now "%{_pscheduler_postgresql_service}" if [ "${NEW_CONF_DIGEST}" != "${OLD_CONF_DIGEST}" ] then echo "Restarting PostgreSQL after configuration change." - systemctl restart "%{_pscheduler_postgresql_service}" + systemctl restart postgresql fi @@ -538,7 +538,7 @@ if [ "$1" = "0" ]; then # Removing the max_connections change requires a restart, which # will also catch the HBA changes. - systemctl reload-or-try-restart "%{_pscheduler_postgresql_service}" + systemctl reload-or-try-restart postgresql @@ -584,7 +584,7 @@ fi # because Pg doesn't see module upgrades. %triggerin -- python-pscheduler -systemctl reload-or-try-restart "%{_pscheduler_postgresql_service}" +systemctl reload-or-try-restart postgresql # ------------------------------------------------------------------------------ %files diff --git a/unibuild-order b/unibuild-order index 963a486b22..8199654e54 100755 --- a/unibuild-order +++ b/unibuild-order @@ -52,7 +52,6 @@ ifelse(PACKAGING,rpm,pscheduler-rpm) # PostgreSQL and Additions -# TODO: Need to see how relevant this still is, especially w/r/t upgrades postgresql-init postgresql-load