summaryrefslogtreecommitdiffstats
path: root/postgresql-setup.in
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2015-09-22 16:12:45 +0200
committerPavel Raiskup <praiskup@redhat.com>2015-09-22 18:17:40 +0200
commitcfbcc14c3264ef73f510baee1120de0351d1ab6d (patch)
tree5b064644d4cb49117e4f871709b7677ea5986fcd /postgresql-setup.in
parent9cea22e1d0501f749e6d2a3140892f74f05dc2df (diff)
downloadpostgresql-setup-cfbcc14c3264ef73f510baee1120de0351d1ab6d.tar.gz
postgresql-setup-cfbcc14c3264ef73f510baee1120de0351d1ab6d.tar.xz
postgresql-setup-cfbcc14c3264ef73f510baee1120de0351d1ab6d.zip
postgresql-setup: fix upgrade bug with non-default unit names
We can't always use '$upgradefrom_id' as "default" previous service name. This broken in-place upgrades with '--unit postgresqlPORT' (old style service files layout) or 'postgresql@port'. Now, by default, use the same service name for both older and newer PG stack. While we are on it, make it a bit more automatic and pick 'postgresql92@second' as "older stack" if upgrading into unit 'postgresql93@second'. Add new option --upgrade-from-unit which allows us to override default decision. * postgresql-setup.in: Set 'option_upgradefrom_unit' to hopefully correct default. Add new info message in case we are not upgrading from differently named unit. (USAGE_STRING): Document new --upgrade-from-unit option. (service_configuration): Don't fork based on $mode and simply use fourth parameter as 'service'. Fix the debug message a bit. (long_opts): Add new option upgrade-from-unit. * NEWS: Document.
Diffstat (limited to 'postgresql-setup.in')
-rw-r--r--postgresql-setup.in44
1 files changed, 38 insertions, 6 deletions
diff --git a/postgresql-setup.in b/postgresql-setup.in
index 0337bdd..fdccd72 100644
--- a/postgresql-setup.in
+++ b/postgresql-setup.in
@@ -28,6 +28,9 @@ PGPORT_DEF=5432
# We upgrade by default from system's default PostgreSQL installation
option_upgradefrom="@NAME_DEFAULT_PREV_SERVICE@"
+srvsuff=
+test 0 -eq @WANT_SYSVINIT@ && srvsuff=".service"
+
USAGE_STRING=$"\
Usage: $0 MODE_OPTION [--unit=UNIT_NAME] [OPTION...]
@@ -66,6 +69,8 @@ USAGE_STRING+="
--datadir and --port."
USAGE_STRING+="
+ --upgrade-from-unit=UNIT Select proper unit name to upgrade from. This
+ has similar semantics as --unit option.
--upgrade-ids Print list of available IDs of upgrade scenarios to
standard output.
--upgrade-from=ID Specify id \"old\" postgresql stack to upgrade
@@ -461,10 +466,7 @@ service_configuration()
local mode="$1" datavar="$2" portvar="$3" service="$4"
- debug "running service_configuration() for $mode"
-
- local service="$service"
- test upgrade = "$mode" && service="$option_upgradefrom"
+ debug "running service_configuration() for $service, mode: $mode"
if test "@WANT_SYSVINIT@" = 1; then
# Sysvinit has the default PGDATA (for default unit name only)
@@ -560,6 +562,7 @@ option_service="@NAME_SERVICE@"
option_port=
option_pgdata=
option_debug=0
+option_upgradefrom_unit=
# Content of EnvironmentFile= files fills those:
envfile_pgdata=
@@ -585,7 +588,7 @@ short_opts=""
long_opts="\
initdb,upgrade,\
new-systemd-unit,upgrade-ids,\
-unit:,service:,port:,datadir:,upgrade-from:,\
+unit:,service:,port:,datadir:,upgrade-from:,upgrade-from-unit:,\
debug,\
version,help,usage"
@@ -640,6 +643,11 @@ while true; do
shift 2
;;
+ --upgrade-from-unit)
+ option_upgradefrom_unit="$2"
+ shift 2
+ ;;
+
--upgrade-ids)
parse_upgrade_setup help
exit 0
@@ -720,7 +728,31 @@ test -n "$option_port" && pgport=$option_port
if test upgrade = "$option_mode"; then
upgradefrom_data="$upgradefrom_data_default"
- service_configuration upgrade upgradefrom_data pgport "$option_upgradefrom"
+
+ if test -z "$option_upgradefrom_unit"; then
+ if test "@NAME_DEFAULT_PREV_SERVICE@" = "@NAME_SERVICE@"; then
+ # Fedora usecase -> upgrade while keeping the same name of
+ # service/unit.
+ option_upgradefrom_unit=$option_service
+ else
+ # PGRPMs/RHSCL usecase -> we upgrade from one service/unit name to
+ # a different one, e.g. from postgresql92 to postgresql93, or from
+ # postgresql (system version) to postgresql94 (scl).
+ option_upgradefrom_unit=$upgradefrom_id
+
+ # Try to predict situations: postgresql93@second -> postgresql94@second
+ if [[ "$option_service" =~ ^@NAME_SERVICE@@(.*)$ ]]; then
+ option_upgradefrom_unit="$upgradefrom_id@${BASH_REMATCH[1]}"
+ fi
+ fi
+ fi
+
+ test "$option_service" = "$option_upgradefrom_unit" \
+ || info "upgrading from '$option_upgradefrom_unit$srvsuff'" \
+ "to '$option_service$srvsuff'"
+
+ service_configuration upgrade upgradefrom_data pgport \
+ "$option_upgradefrom_unit"
test -n "$option_port" -a "$option_port" != "$pgport" \
&& warn "Old pgport $pgport has bigger priority than --pgport value."
fi