diff options
-rw-r--r-- | main/postgresql/APKBUILD | 10 | ||||
-rw-r--r-- | main/postgresql/pg-restore.confd | 2 | ||||
-rw-r--r-- | main/postgresql/pg-restore.initd | 20 | ||||
-rw-r--r-- | main/postgresql/postgresql.confd | 2 | ||||
-rw-r--r-- | main/postgresql/postgresql.initd | 36 |
5 files changed, 48 insertions, 22 deletions
diff --git a/main/postgresql/APKBUILD b/main/postgresql/APKBUILD index d82ee7862..ca034faed 100644 --- a/main/postgresql/APKBUILD +++ b/main/postgresql/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: Natanael Copa <ncopa@alpinelinux.org> pkgname=postgresql pkgver=8.4.3 -pkgrel=2 +pkgrel=3 pkgdesc="A sophisticated object-relational DBMS" url="http://www.postgresql.org/" license="BSD" @@ -57,7 +57,7 @@ client() { md5sums="7f70e7b140fb190f268837255582b07e postgresql-8.4.3.tar.bz2 -740bc8414ee27b4c81dee1690c32679f postgresql.initd -d6b58fc2411fdadcb9b762464c5bee7d postgresql.confd -e64d0ab26b077ed80d883c0c40704ff4 pg-restore.initd -8d1b69ac56a1a0d1cfd7da337bf6c5e2 pg-restore.confd" +66c197b8186a6df0752fe2aed40c90c4 postgresql.initd +12199d445bfa42aafc2a958012737107 postgresql.confd +7f8de63848c51c8a30c39bec6b1b1606 pg-restore.initd +bf45384752b320b369f1425939763178 pg-restore.confd" diff --git a/main/postgresql/pg-restore.confd b/main/postgresql/pg-restore.confd index 18bff4c2a..84a179f6c 100644 --- a/main/postgresql/pg-restore.confd +++ b/main/postgresql/pg-restore.confd @@ -10,7 +10,7 @@ # #KEEP_DUMP=yes -# If you enable the KEEP_DUMP bove you probably also want the --clean option +# If you enable KEEP_DUMP above you probably also want the --clean option # the the pg_dumpall command. #PG_DUMPALL_OPTS="--clean" diff --git a/main/postgresql/pg-restore.initd b/main/postgresql/pg-restore.initd index aaf07cbe7..91c69d18f 100644 --- a/main/postgresql/pg-restore.initd +++ b/main/postgresql/pg-restore.initd @@ -1,5 +1,7 @@ #!/sbin/runscript +. /etc/conf.d/postgresql + opts="${opts} dump restore" depend() { @@ -7,18 +9,22 @@ depend() { } restore() { - [ -z "$PGDUMP" ] && return 0 + yesno "$PGDUMP" && return 0 ebegin "Restoring PostgreSQL $PGDUMP" - psql -U ${PG_USER:-postgres} ${PSQL_OPTS} -f "$PGDUMP" - eend $? - if [ -z "$KEEP_DUMP" ]; then - rm -f "$PGDUMP" - fi + psql -U ${PG_USER:-postgres} ${PSQL_OPTS} -f "$PGDUMP" >/dev/null 2>/dev/null + yesno "$KEEP_DUMP" || rm -f "$PGDUMP" + + su -l ${PGUSER} \ + -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload " >/dev/null + eend $res } dump() { - [ -z "$PGDUMP" ] && return 0 + yesno "$PGDUMP" && return 0 + mkdir -p "$( dirname "$PGDUMP" )" + ebegin "Saving PostgreSQL databases to $PGDUMP" pg_dumpall -U ${PG_USER:-postgres} ${PG_DUMPALL_OPTS} -f "$PGDUMP" + eend $? } start() { diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd index 4fe28a458..29ef20d94 100644 --- a/main/postgresql/postgresql.confd +++ b/main/postgresql/postgresql.confd @@ -52,5 +52,5 @@ WAIT_FOR_START="-w" # export R_HOME="/usr/lib/R" # Automatically set up a new database if missing on startup -#AUTO_SETUP=yes +AUTO_SETUP=yes 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 } |