public inbox for [email protected]  
help / color / mirror / Atom feed
From: Bernd Helmle <[email protected]>
To: [email protected]
Subject: systemd service files vs. postgresql9x-setup
Date: Wed, 12 Aug 2015 16:18:06 +0200
Message-ID: <[email protected]> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-pkg-yum>

Hi,

Looks like postgresql9[45]-setup is careless when someone tries to use them
in customized
systemd environments (e.g. via drop-in configurations[1]). Currently we do
this:

# 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`

[...some more code later...]

# Get data directory from the service file
PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`

So we obviously overwrite any PGDATA setting returned by 'systemctl show'
earlier. If someone uses service files only, this doesn't heavily matter,
since SERVICE_FILE is tested against multiple locations. However, drop-in
configurations are ignored/overwritten with this method. I don't
understand, why we do the sed approach anyways, since 'systemctl show'
already covers all cases, afaics. So i suggest to get rid of handling the
SERVICE_FILE directly and leave 'systemctl show' alone, patch attached.

Opinions?

[1] <http://www.freedesktop.org/software/systemd/man/systemd.unit.html;

-- 
Thanks

	Bernd

-- 
Sent via pgsql-pkg-yum mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-pkg-yum


Attachments:

  [application/octet-stream] 0001-Get-rid-of-sed-magic-to-retrieve-PGDATA-directly-fro.patch (2.7K, 2-0001-Get-rid-of-sed-magic-to-retrieve-PGDATA-directly-fro.patch)
  download | inline diff:
From a5a8f68ebcf5d2c2b4e680521c6fa916803e21a8 Mon Sep 17 00:00:00 2001
From: Bernd Helmle <[email protected]>
Date: Wed, 12 Aug 2015 15:28:51 +0200
Subject: [PATCH] Get rid of sed magic to retrieve PGDATA directly from systemd
 service files.

Instead rely on systemctl only, which also allows to use systemd drop-in
configuration directives.

The former coding also contains a bug, where PGDATA is always overwritten
by settings derived from service files directly.
---
 rpm/redhat/9.4/postgresql/EL-7/postgresql94-setup | 15 ---------------
 rpm/redhat/9.5/postgresql/EL-7/postgresql95-setup | 15 ---------------
 2 files changed, 30 deletions(-)

diff --git a/rpm/redhat/9.4/postgresql/EL-7/postgresql94-setup b/rpm/redhat/9.4/postgresql/EL-7/postgresql94-setup
index 1f0cb0f..3a745be 100644
--- a/rpm/redhat/9.4/postgresql/EL-7/postgresql94-setup
+++ b/rpm/redhat/9.4/postgresql/EL-7/postgresql94-setup
@@ -83,26 +83,11 @@ if [ x"$PGDATA" = x ]; then
     exit 1
 fi
 
-# Find the unit file for new version.
-if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
-elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
-else
-    echo "Could not find systemd unit file ${SERVICE_NAME}.service"
-    exit 1
-fi
-
 # Log file for pg_upgrade
 PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/pgupgrade.log
 # Log file for initdb
 PGLOG=/var/lib/pgsql/9.4/initdb.log
 
-# Get data directory from the service file
-PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`
-
 export PGDATA
 
 # For SELinux we need to use 'runuser' not 'su'
diff --git a/rpm/redhat/9.5/postgresql/EL-7/postgresql95-setup b/rpm/redhat/9.5/postgresql/EL-7/postgresql95-setup
index 697e0b4..0ede51e 100644
--- a/rpm/redhat/9.5/postgresql/EL-7/postgresql95-setup
+++ b/rpm/redhat/9.5/postgresql/EL-7/postgresql95-setup
@@ -83,26 +83,11 @@ if [ x"$PGDATA" = x ]; then
     exit 1
 fi
 
-# Find the unit file for new version.
-if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
-elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
-else
-    echo "Could not find systemd unit file ${SERVICE_NAME}.service"
-    exit 1
-fi
-
 # Log file for pg_upgrade
 PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/pgupgrade.log
 # Log file for initdb
 PGLOG=/var/lib/pgsql/9.5/initdb.log
 
-# Get data directory from the service file
-PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`
-
 export PGDATA
 
 # For SELinux we need to use 'runuser' not 'su'
-- 
1.8.3.1



view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: systemd service files vs. postgresql9x-setup
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox