BUG #13612: postgresql94-setup initdb in kickstart fails - Mailing list pgsql-bugs

From allan.kristsensen@schneider-electric.com
Subject BUG #13612: postgresql94-setup initdb in kickstart fails
Date
Msg-id 20150910081312.2597.31540@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #13612: postgresql94-setup initdb in kickstart fails  (Bruce Momjian <bruce@momjian.us>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      13612
Logged by:          Allan Kristensen
Email address:      allan.kristsensen@schneider-electric.com
PostgreSQL version: 9.4.4
Operating system:   Centos 7
Description:

Running "/usr/pgsql-9.4/bin/postgresql94-setup initdb" during Kickstart
install of a Centos/RHEL 7 will through the following error.

failed to find PGDATA setting in postgresql-9.4.service
Running in chroot, ignoring request.

In bin/postgresql94-setup the problematic lines are:
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
    echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
    exit 1
fi

systemctl returns an empty result as it won't run in a chroot.

Besides the above. What puzzles me is that PGDATA is overwritten further
down in the script.

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

I have put things together to the following:

# 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/^PGDATAA=//p' | tail -n 1`
if [ x"$PGDATA" = x ]; then
    # 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

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

    if [ x"$PGDATA" = x ]; then
        echo "Failed to find PGDATA setting in ${SERVICE_NAME}.service"
        exit 1
    fi
fi

export PGDATA


If systemctl does not find a path then try the searching in files and exit
if none of the methods provides a valid path.

pgsql-bugs by date:

Previous
From: kondo@sraoss.co.jp
Date:
Subject: BUG #13611: test_postmaster_connection failed (Windows, listen_addresses = '0.0.0.0' or '::')
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #13612: postgresql94-setup initdb in kickstart fails