diff options
Diffstat (limited to 'main/postgresql/postgresql.initd')
-rw-r--r-- | main/postgresql/postgresql.initd | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd index 23b0acff4..2de91d0df 100644 --- a/main/postgresql/postgresql.initd +++ b/main/postgresql/postgresql.initd @@ -2,6 +2,7 @@ # Copyright 1999-2008 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/dev-db/postgresql-server/files/postgresql.init-8.3,v 1.4 2008/09/28 22:53:02 caleb Exp $ +# Modifications to support Alpine Linux pg-restore opts="${opts} reload setup" @@ -11,10 +12,11 @@ depend() { } checkconfig() { - [ -d "$PGDATA" ] && return 0 + [ -d "$PGDATA/base" ] && return 0 + echo "checking config" - if [ -z "$AUTO_SETUP" ] || [ "$AUTO_SETUP" = "no" ]; then - eerror "Directory not found: $PGDATA" + if [ -z "$AUTO_SETUP" ] ; then + eerror "Database not found at: $PGDATA" eerror "Please make sure that PGDATA points to the right path." eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster." return 1 @@ -101,18 +103,36 @@ reload() { setup() { ebegin "Creating a new PostgreSQL database cluster" - rmdir "${PGDATA}" 2>/dev/null - if [ -d "${PGDATA}" ] ; then - eend 1 "${PGDATA} already exist" + + if [ -d "${PGDATA}/base" ] ; then + eend 1 "${PGDATA}/base already exists" return fi - mkdir -p "${PGDATA}" + + mkdir -p "${PGDATA}" 2>/dev/null + + # If the pg_hba.conf and friends exist, move them + local tmpdir="$( dirname "$PGDATA" )/tmp" + mkdir -p "${tmpdir}" >/dev/null + echo mv "${PGDATA}"/* "${tmpdir}" + mv "${PGDATA}"/* "${tmpdir}" 2>/dev/null + + rm -rf "${PGDATA}"/* 2>/dev/null chown -Rf postgres:postgres "${PGDATA}" chmod 0700 "${PGDATA}" cd "${PGDATA}" # to avoid the: could not change directory to "/root" su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres einfo "You can use the '/etc/init.d/postgresql' script to run PostgreSQL instead" einfo "of 'pg_ctl'." - eend $? + local res=$? + + # move the pg_hba.conf and friends + mv $tmpdir/* "$PGDATA" 2>/dev/null + rm -rf $tmpdir 2>/dev/null + + # Do not send a SIGHUP to postmaster; its not necessary for a new database + # and allows pg-restore to do a blind restore of an old database + + eend $res } |