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.