postgres: Fix install error on none existent file
Required to complete postgres build and ported from upstream meta-cloud-services. This commit to be removed when moving to to dunfell or later. Upstream commit: 8516070112019bd7b3a5c41eb55a042808a13089 Closes-Bug: 1899552 Change-Id: I9ec82e41567a41734a0b10445e4ada661693c4d7 Signed-off-by: Babak Sarashki <babak.sarashki@windriver.com>
This commit is contained in:
parent
36b79bbf93
commit
d4ee391872
@ -44,3 +44,4 @@ BBMASK += "/meta-selinux/recipes-graphics/mesa/mesa_%.bbappend"
|
|||||||
BBMASK += "/meta-virtualization/recipes-containers/docker-distribution/docker-distribution_git.bb"
|
BBMASK += "/meta-virtualization/recipes-containers/docker-distribution/docker-distribution_git.bb"
|
||||||
BBMASK += "/meta-starlingX/recipes-containers/docker-distribution/docker-distribution_git.bbappend"
|
BBMASK += "/meta-starlingX/recipes-containers/docker-distribution/docker-distribution_git.bbappend"
|
||||||
BBMASK += "/meta-starlingX/recipes-support/puppet/puppetlabs-stdlib_git.bbappend"
|
BBMASK += "/meta-starlingX/recipes-support/puppet/puppetlabs-stdlib_git.bbappend"
|
||||||
|
BBMASK += "/meta-cloud-services/meta-openstack/recipes-dbs/postgresql/postgresql_%.bbappend"
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
PN=postgresql
|
||||||
|
CONTROLLER_IP=%CONTROLLER_IP%
|
||||||
|
COMPUTE_IP=%COMPUTE_IP%
|
||||||
|
DB_USER=%DB_USER%
|
||||||
|
DB_PASSWORD=%DB_PASSWORD%
|
||||||
|
DATA_DIR=%DB_DATADIR%
|
||||||
|
|
||||||
|
initdb(){
|
||||||
|
if [ ! -e $DATA_DIR ]; then
|
||||||
|
mkdir -p $DATA_DIR
|
||||||
|
chown postgres $DATA_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e $DATA_DIR/PG_VERSION ]; then
|
||||||
|
# the database has already been initialized, return
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the DB
|
||||||
|
sudo -u postgres initdb -D $DATA_DIR
|
||||||
|
|
||||||
|
# Allow readers/writers by IP
|
||||||
|
echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf
|
||||||
|
echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
|
||||||
|
echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" == "initdb" ]; then
|
||||||
|
initdb
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
count=0
|
||||||
|
done=0
|
||||||
|
while [ $count -le 10 ] && [ $done -eq 0 ]; do
|
||||||
|
sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
|
||||||
|
systemctl stop postresql
|
||||||
|
sleep 3
|
||||||
|
systemctl start postgresql
|
||||||
|
sleep 3
|
||||||
|
else
|
||||||
|
echo "[INFO] postgres: created account for ${DB_USER}, continuing .. "
|
||||||
|
done=1
|
||||||
|
fi
|
||||||
|
count=`expr $count + 1`
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $done -eq 0 ]; then
|
||||||
|
echo "[ERROR] postgres: unable to create admin account"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone || true
|
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Postgresql setup for OpenStack
|
||||||
|
After=postgresql.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=%SYSCONFIGDIR%/postgresql/postgresql-init
|
||||||
|
ExecStartPost=/bin/systemctl --no-reload disable postgresql-init.service
|
||||||
|
RemainAfterExit=No
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
COMPUTE_IP="127.0.0.1"
|
COMPUTE_IP="127.0.0.1"
|
||||||
CONTROLLER_IP="127.0.0.1"
|
CONTROLLER_IP="127.0.0.1"
|
||||||
|
|
||||||
FILESEXTRAPATHS_prepend := "${THISDIR}/postgresql:"
|
FILESEXTRAPATHS_prepend := "${THISDIR}/postgresql:"
|
||||||
|
|
||||||
|
require ${@bb.utils.contains('DISTRO_FEATURES', 'openstack', '${BPN}_openstack.inc', '', d)}
|
||||||
|
|
||||||
SRC_URI += " \
|
SRC_URI += " \
|
||||||
file://postgresql.service.update \
|
file://postgresql.service.update \
|
||||||
"
|
"
|
||||||
@ -14,4 +15,3 @@ do_install_append() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILES_${PN} += "${systemd_unitdir}/system/postgresql.service"
|
FILES_${PN} += "${systemd_unitdir}/system/postgresql.service"
|
||||||
|
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
FILESEXTRAPATHS_prepend := "${THISDIR}/postgresql:"
|
||||||
|
|
||||||
|
SRC_URI += " \
|
||||||
|
file://postgresql-init \
|
||||||
|
file://postgresql-init.service \
|
||||||
|
"
|
||||||
|
|
||||||
|
inherit identity hosts
|
||||||
|
|
||||||
|
SYSTEMD_AUTO_ENABLE_${PN} = "enable"
|
||||||
|
|
||||||
|
# default
|
||||||
|
DB_DATADIR ?= "/var/lib/postgres/data"
|
||||||
|
|
||||||
|
do_install_append() {
|
||||||
|
D_DEST_DIR=${D}${sysconfdir}/postgresql
|
||||||
|
|
||||||
|
install -d ${D_DEST_DIR}
|
||||||
|
install -m 0755 ${WORKDIR}/postgresql-init ${D_DEST_DIR}/postgresql-init
|
||||||
|
|
||||||
|
sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
|
||||||
|
sed -e "s:%DB_USER%:${DB_USER}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
|
||||||
|
sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
sed -e "s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
|
||||||
|
sed -e "s:%COMPUTE_IP%:${COMPUTE_IP}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
sed -e "s:%COMPUTE_HOST%:${COMPUTE_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
|
||||||
|
|
||||||
|
install -d ${D}${systemd_unitdir}/system/
|
||||||
|
PG_INIT_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql-init.service
|
||||||
|
install -m 644 ${WORKDIR}/postgresql-init.service ${PG_INIT_SERVICE_FILE}
|
||||||
|
sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE}
|
||||||
|
|
||||||
|
# Update PGDATA throughout
|
||||||
|
files="${D}${localstatedir}/lib/${BPN}/.profile"
|
||||||
|
files="$files ${D}${systemd_unitdir}/system/postgresql.service"
|
||||||
|
files="$files ${D}${bindir}/${BPN}-setup"
|
||||||
|
files="$files ${D}${sysconfdir}/init.d/${BPN}-server"
|
||||||
|
for f in $files
|
||||||
|
do
|
||||||
|
sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i $f
|
||||||
|
done
|
||||||
|
|
||||||
|
# Ensure DB is initialize before we attempt to start the service
|
||||||
|
FILE=${D}${systemd_unitdir}/system/postgresql.service
|
||||||
|
sed -e '/ExecStart=.*/i ExecStartPre=-${sysconfdir}/postgresql/postgresql-init initdb' -i $FILE
|
||||||
|
sed -e '/ExecStartPre=.*/i PermissionsStartOnly=true' -i $FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
PACKAGES += " ${PN}-setup"
|
||||||
|
|
||||||
|
SYSTEMD_PACKAGES += "${PN}-setup"
|
||||||
|
SYSTEMD_SERVICE_${PN}-setup = "postgresql-init.service"
|
||||||
|
|
||||||
|
FILES_${PN}-setup = " \
|
||||||
|
${systemd_unitdir}/system \
|
||||||
|
"
|
Loading…
Reference in New Issue
Block a user