From 26914bdffa7aa3eff4da9e93a59aa212ceab02e1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 17 Mar 2012 12:47:37 -0400 Subject: Fix postgresql-setup to rely on systemd to parse the unit file --- postgresql-setup | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'postgresql-setup') 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 ] -- cgit