From a21b481b00acd2169eb1a90ecb547c4752904156 Mon Sep 17 00:00:00 2001 From: Amy Fong Date: Thu, 13 Mar 2014 13:57:39 -0400 Subject: OpenStack: Fix postgresql file permissions - make database directory to be configurable, defaulting to /var/lib/postgres/data - modify init scripts to create database's data directory if it doesn't exist Signed-off-by: Amy Fong Signed-off-by: Bruce Ashfield --- .../recipes-support/postgresql/postgresql/postgresql | 13 +++++++------ .../postgresql/postgresql/postgresql-init | 16 +++++++++++----- .../recipes-support/postgresql/postgresql_9.2.4.bbappend | 7 +++++-- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'meta-openstack/recipes-support') diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql b/meta-openstack/recipes-support/postgresql/postgresql/postgresql index 5a34ec0..cfff759 100644 --- a/meta-openstack/recipes-support/postgresql/postgresql/postgresql +++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql @@ -13,14 +13,15 @@ DAEMON=/usr/bin/postmaster DESC="PostgreSQL RDBMS server" +DEFAULT_DATA_DIR=%DB_DATADIR% -datadir=`grep ^data_directory /etc/postgresql/postgresql.conf |sed -e "s#^.*= '##; s#'.*##"` +datadir=`grep ^data_directory $DEFAULT_DATA_DIR/postgresql.conf |sed -e "s#^.*= '##; s#'.*##"` if [ "$datadir" = "" ] ; then - datadir=/etc/postgresql + datadir=$DEFAULT_DATA_DIR else if [ ! -e $datadir/postgresql.conf ] ; then - if [ -e /etc/postgresql/postgresql.conf -a -e $datadir ] ; then - ln -s /etc/postgresql/*.conf $datadir/ + if [ -e $DEFAULT_DATA_DIR/postgresql.conf -a -e $datadir ] ; then + ln -s $DEFAULT_DATA_DIR/*.conf $datadir/ fi fi fi @@ -55,9 +56,9 @@ stop () if [ $? -eq 0 ]; then echo "done." else - if [ -f /etc/postgresql/postmaster.pid -a "$datadir" != "/etc/postgresql" ] ; then + if [ -f $DEFAULT_DATA_DIR/postmaster.pid -a "$datadir" != "$DEFAULT_DATA_DIR" ] ; then # Special case for transition - sudo -u postgres /usr/bin/pg_ctl stop -w -D /etc/postgresql -m fast -s + sudo -u postgres /usr/bin/pg_ctl stop -w -D $DEFAULT_DATA_DIR -m fast -s fi if ! pidof ${DAEMON} > /dev/null; then echo "done." diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init index c9c3807..f5e7dfb 100644 --- a/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init +++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init @@ -6,16 +6,22 @@ CONTROLLER_IP=%CONTROLLER_IP% COMPUTE_IP=%COMPUTE_IP% DB_USER=%DB_USER% DB_PASSWORD=%DB_PASSWORD% +DATA_DIR=%DB_DATADIR% -if [ -e /etc/${PN}/PG_VERSION ]; then +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 -sudo -u postgres initdb -D /etc/${PN}/ -echo "listen_addresses = '*'" >> /etc/${PN}/postgresql.conf -echo "host all all ${CONTROLLER_IP}/32 trust" >> /etc/${PN}/pg_hba.conf -echo "host all all ${COMPUTE_IP}/32 trust" >> /etc/${PN}/pg_hba.conf +sudo -u postgres initdb -D $DATA_DIR +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 /etc/init.d/postgresql start count=0 diff --git a/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend b/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend index c485e2d..80bfe1e 100644 --- a/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend +++ b/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend @@ -6,9 +6,12 @@ SRC_URI += "file://postgresql \ inherit useradd update-rc.d identity hosts +# default +DB_DATADIR ?= "/var/lib/postgres/data" + do_install_append() { - install -d ${D}${sysconfdir}/${PN} - chown postgres ${D}${sysconfdir}/${PN} + sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${WORKDIR}/postgresql + sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${WORKDIR}/postgresql-init install -d ${D}${sysconfdir}/init.d/ install -m 0755 ${WORKDIR}/postgresql ${D}${sysconfdir}/init.d/postgresql -- cgit v1.2.3-54-g00ecf