[postgresql] Fix postgresql-setup to rely on systemd to parse the unit file
Tom Lane
tgl at fedoraproject.org
Sat Mar 17 16:48:29 UTC 2012
commit de5b387d8f78a230a679ee28733b920eb1849515
Author: Tom Lane <tgl at redhat.com>
Date: Sat Mar 17 12:47:37 2012 -0400
Fix postgresql-setup to rely on systemd to parse the unit file
postgresql-setup | 33 ++++++++++++++++++---------------
postgresql.service | 9 ++++++---
postgresql.spec | 7 ++++++-
3 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/postgresql-setup b/postgresql-setup
index 29da10a..132ef78 100644
--- a/postgresql-setup
+++ b/postgresql-setup
@@ -23,24 +23,27 @@ then
SERVICE_NAME=postgresql
fi
-if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
-then
- SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
-elif [ -f "/usr/lib/systemd/system/${SERVICE_NAME}.service" ]
-then
- SERVICE_FILE="/usr/lib/systemd/system/${SERVICE_NAME}.service"
-# this case should go away eventually, but not till F16 is dead:
-elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
+# this parsing technique fails for PGDATA pathnames containing spaces,
+# but there's not much I can do about it given systemctl's output format...
+PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" |
+ sed 's/^Environment=//' | tr ' ' '\n' |
+ sed -n 's/^PGDATA=//p' | tail -n 1`
+
+if [ x"$PGDATA" = x ]
then
- SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
-else
- echo "Could not find systemd unit file ${SERVICE_NAME}.service"
+ echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
exit 1
fi
-# Get port number and data directory from the service file
-PGPORT=`sed -n 's/^[ \t]*Environment=PGPORT=//p' "${SERVICE_FILE}"`
-PGDATA=`sed -n 's/^[ \t]*Environment=PGDATA=//p' "${SERVICE_FILE}"`
+PGPORT=`systemctl show -p Environment "${SERVICE_NAME}.service" |
+ sed 's/^Environment=//' | tr ' ' '\n' |
+ sed -n 's/^PGPORT=//p' | tail -n 1`
+
+if [ x"$PGPORT" = x ]
+then
+ echo "failed to find PGPORT setting in ${SERVICE_NAME}.service"
+ exit 1
+fi
# Log file for initdb
PGLOG=/var/lib/pgsql/initdb.log
@@ -48,8 +51,8 @@ PGLOG=/var/lib/pgsql/initdb.log
# Log file for pg_upgrade
PGUPLOG=/var/lib/pgsql/pgupgrade.log
-export PGPORT
export PGDATA
+export PGPORT
# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
diff --git a/postgresql.service b/postgresql.service
index 4414d11..123c4fe 100644
--- a/postgresql.service
+++ b/postgresql.service
@@ -14,6 +14,12 @@
# Environment=PGPORT=5433
# This will override the setting appearing below.
+# Note: do not use a PGDATA pathname containing spaces, or you will
+# break postgresql-setup.
+
+# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line
+# though /lib/... will still work.
+
[Unit]
Description=PostgreSQL database server
After=syslog.target
@@ -25,9 +31,6 @@ Type=forking
User=postgres
Group=postgres
-# Note: avoid inserting whitespace in these Environment= lines, or you may
-# break postgresql-setup.
-
# Port number for server to listen on
Environment=PGPORT=5432
diff --git a/postgresql.spec b/postgresql.spec
index 3bc92c4..3bebb5b 100644
--- a/postgresql.spec
+++ b/postgresql.spec
@@ -53,7 +53,7 @@ Summary: PostgreSQL client programs
Name: postgresql
%global majorversion 9.1
Version: 9.1.3
-Release: 2%{?dist}
+Release: 3%{?dist}
# The PostgreSQL license is very similar to other MIT licenses, but the OSI
# recognizes it as an independent license, so we do as well.
@@ -932,6 +932,11 @@ rm -rf $RPM_BUILD_ROOT
%endif
%changelog
+* Sat Mar 17 2012 Tom Lane <tgl at redhat.com> 9.1.3-3
+- Fix postgresql-setup to rely on systemd to parse the unit file, instead
+ of using ad-hoc code
+Resolves: #804290
+
* Tue Mar 13 2012 Tom Lane <tgl at redhat.com> 9.1.3-2
- Fix postgresql-setup to look for unit file in /usr/lib and to ignore
comments therein
More information about the scm-commits
mailing list