X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@lists.alpinelinux.org Received: from mail.squbes.com (squbes.com [208.74.142.49]) by lists.alpinelinux.org (Postfix) with ESMTP id 3B3AC3617A1B for ; Mon, 17 May 2010 07:23:11 +0000 (UTC) Received: from [10.252.6.46] (c-71-198-150-62.hsd1.ca.comcast.net [71.198.150.62]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: nangel@nothome.org) by mail.squbes.com (Postfix) with ESMTPSA id 0C0A950001CA1 for ; Mon, 17 May 2010 07:23:09 +0000 (UTC) Message-ID: <4BF0EEFB.2090108@nothome.org> Date: Mon, 17 May 2010 00:23:39 -0700 From: Nathan Angelacos User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100411 Icedove/3.0.4 X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 To: alpine-devel@lists.alpinelinux.org Subject: Re: [alpine-devel] Patch to postgresql init script References: <4BEB97F0.4060304@nothome.org> <4BECA826.70805@nothome.org> In-Reply-To: Content-Type: multipart/mixed; boundary="------------060602050207080706030009" This is a multi-part message in MIME format. --------------060602050207080706030009 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 05/13/10 23:40, Natanael Copa wrote: > On Fri, May 14, 2010 at 3:32 AM, Nathan Angelacos wrote: > >> Comments? > > I think its nice to have the scripts separated, but no strog feelings > there really. Do what you think is best. > > Thanks alot for following this up. > attached. --------------060602050207080706030009 Content-Type: text/x-patch; name="postgresql.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="postgresql.patch" diff --git a/main/postgresql/pg-restore.confd b/main/postgresql/pg-restore.confd index 18bff4c..84a179f 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 aaf07cb..91c69d1 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 4fe28a4..29ef20d 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 23b0acf..2de91d0 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 } --------------060602050207080706030009-- --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---