From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Q16fy-0004Tf-AI for garchives@archives.gentoo.org; Sun, 20 Mar 2011 00:39:22 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A00061C020; Sun, 20 Mar 2011 00:39:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 60BAE1C020 for ; Sun, 20 Mar 2011 00:39:15 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C81671B40EA for ; Sun, 20 Mar 2011 00:39:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 3808D8006A for ; Sun, 20 Mar 2011 00:39:14 +0000 (UTC) From: "Aaron Swenson" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Aaron Swenson" Message-ID: <858da0576419b108f058d3ed6eef46f3cc40999c.titanofold@gentoo> Subject: [gentoo-commits] proj/pgsql-patches:initscripts commit in: / X-VCS-Repository: proj/pgsql-patches X-VCS-Files: postgresql.confd postgresql.init X-VCS-Directories: / X-VCS-Committer: titanofold X-VCS-Committer-Name: Aaron Swenson X-VCS-Revision: 858da0576419b108f058d3ed6eef46f3cc40999c Date: Sun, 20 Mar 2011 00:39:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: a611e3c1c3b262ec904ebcc5a8fae498 commit: 858da0576419b108f058d3ed6eef46f3cc40999c Author: Aaron W. Swenson gentoo org> AuthorDate: Sun Mar 20 00:37:42 2011 +0000 Commit: Aaron Swenson gentoo org> CommitDate: Sun Mar 20 00:37:42 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/pgsql-patches= .git;a=3Dcommit;h=3D858da057 Initial commit of initscript and related conf file for 8.2. --- postgresql.confd | 57 ++++++++++++++++++ postgresql.init | 173 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ 2 files changed, 230 insertions(+), 0 deletions(-) diff --git a/postgresql.confd b/postgresql.confd new file mode 100644 index 0000000..e306c96 --- /dev/null +++ b/postgresql.confd @@ -0,0 +1,57 @@ +# Which port and socket to bind PostgreSQL +PGPORT=3D"5432" + +# Allow *_TIMEOUT to run its course. +# Disable timeouts by changing to '-W' (capital W) +WAIT_FOR_START=3D"-w" +WAIT_FOR_STOP=3D"-w" + +# Ignore new connections and wait for clients to disconnect from server = before +# shutting down. +# Set NICE_QUIT to "NO" to disable. +NICE_QUIT=3D"YES" + +# Forecfully disconnect clients from server and shut down. This is perfo= rmed +# after NICE_QUIT. Terminating a client results in a rollback of open +# transactions for that client. +# Set RUDE_QUIT to "NO" to disable. +RUDE_QUIT=3D"YES" + +# If the server still fails to shutdown, you can force it to quit by set= ting +# this to yes and a recover-run will execute on the next startup. +# Set FORCE_QUIT to "YES" to enable. +FORCE_QUIT=3D"NO" + +# Extra options to run postmaster with, e.g.: +# -N is the maximal number of client connections +# -B is the number of shared buffers and has to be at least 2x the value= for -N +# Please read the man-page to postmaster for more options. Many of +# these options can be set directly in the configuration file. +#PGOPTS=3D"-N 512 -B 1024" + +# Pass extra environment variables. If you have to export environment +# variables for the database process, this can be done here. +# Don't forget to escape quotes. +#PG_EXTRA_ENV=3D"PGPASSFILE=3D\"/path/to/.pgpass\"" + +########################################################################= ###### +# +# The following values should not be arbitrarily changed. +# emerge --config dev-db/postgresql-server:8.2 uses these values to +# determine where to create the data directory, where to place the +# configuration files and any additional options you'd like to pass to i= nitdb. +# +# The init script also uses these variables to inform pg_ctl where to fi= nd +# the same data and configuration files. +# +########################################################################= ###### + +# Location of configuration files +PGDATA=3D"/etc/postgresql-8.2/" + +# Where the data directory is located/to be created +DATA_DIR=3D"/var/lib/postgresql/8.2/data" + +# Additional options to pass to initdb. +# See 'man initdb' for available options. +#PG_INITDB_OPTS=3D"--locale=3Den_US.UTF-8" diff --git a/postgresql.init b/postgresql.init new file mode 100644 index 0000000..d0ef87c --- /dev/null +++ b/postgresql.init @@ -0,0 +1,173 @@ +#!/sbin/runscript +# Copyright 1999-2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/dev-db/postgresql-server/files/postgr= esql.init,v 1.1 2010/06/04 14:18:52 patrick Exp $ + +opts=3D"${opts} reload" + +depend() { + use net + provide postgresql + provide postgresql-8.2 +} + +checkconfig() { + if [ ! -d $DATA_DIR ] ; then + eerror "Directory not found: $DATA_DIR" + eerror "Please make sure that DATA_DIR points to the right path." + eerror "You can run 'emerge --config dev-db/postgresql-server:8.2' to = setup a new" + eerror "database cluster." + return 1 + elif [ ! -f ${PGDATA%/}/postgresql.conf ] ; then + eerror "File not found: ${PGDATA%/}/postgresql.conf" + eerror "You may need to run:" + eerror "cp ${DATA_DIR%/}/postgresql.conf ${PGDATA%/}/postgresql.conf" + return 1 + elif [ ! -f ${PGDATA%/}/pg_hba.conf ] ; then + eerror "File not found: ${PGDATA%/}/pg_hba.conf" + eerror "You may need to run:" + eerror "cp ${DATA_DIR%/}/pg_hba.conf ${PGDATA%/}/pg_hba.conf" + return 1 + elif [ ! -f ${PGDATA%/}/pg_ident.conf ] ; then + eerror "File not found: ${PGDATA%/}/pg_ident.conf" + eerror "You may need to run:" + eerror "cp ${DATA_DIR%/}/pg_ident.conf ${PGDATA%/}/pg_ident.conf" + return 1 + elif [ -e /var/run/postgresql/.s.PGSQL.${PGPORT} ] ; then + eerror "Socket conflict." + eerror "A server is already listening on:" + eerror "/var/run/postgresql/.s.PGSQL.${PGPORT}." + eerror "Change PGPORT to listen on a different socket." + return 1 + fi +} + +start() { + checkconfig || return 1 + + ebegin "Starting PostgreSQL" + + if [ -f ${DATA_DIR%/}/postmaster.pid ] ; then + rm -f ${DATA_DIR%/}/postmaster.pid + fi + + local retval + + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + start ${WAIT_FOR_START} -s -D ${DATA_DIR} -o \ + '-D ${PGDATA} --data-directory=3D${DATA_DIR} --silent-mode=3Dtrue ${PG= OPTS}'" + retval=3D$? + + if [ $retval -ne 0 ] ; then + eend $retval + return $retval + fi + + # The following is to catch the case of an already running server + # in which pg_ctl doesn't know to which server it connected to and + # falsely reports the server as 'up' + if [ ! -f ${DATA_DIR}/postmaster.pid ] ; then + eerror "The PID file doesn't exist but pg_ctl reported a running serve= r." + eerror "Please check whether there is another server running on the sa= me port or read the log-file." + eend 1 + return 1 + fi + + eend $? +} + +stop() { + ebegin "Stopping PostgreSQL (this can take up to 90 seconds)" + + local retval + + if [ "${NICE_QUIT}" !=3D "NO" ] ; then + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + stop ${WAIT_FOR_STOP} -s -D ${DATA_DIR} -m smart" + retval=3D$? + + if [ $retval -eq 0 ] ; then + eend $retval + return $retval + fi + + ewarn "Shutting down the server gracefully failed." + ewarn "Probably because some clients did not disconnect within ${NICE_= TIMEOUT} seconds." + else + ewarn "NICE_QUIT disabled." + ewarn "You really should have it enabled." + fi + + if [ "${RUDE_QUIT}" !=3D "NO" ] ; then + ewarn "RUDE_QUIT enabled." + ewarn "Going to shutdown the server anyway." + + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + stop ${WAIT_FOR_STOP} -s -D ${DATA_DIR} -m fast" + retval=3D$? + + if [ $retval -eq 0 ] ; then + eend $retval + return $retval + fi + + eerror "Failed to shutdown server." + else + ewarn "RUDE_QUIT disabled." + fi + + if [ "${FORCE_QUIT}" =3D "YES" ] ; then + ewarn "FORCE_QUIT enabled." + ewarn "Forcing server to shutdown." + ewarn "A recover-run will be executed on the next startup." + + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + stop ${WAIT_FOR_STOP} -s -D ${DATA_DIR} -m immediate" + + retval=3D$? + + if [ $retval -eq 0 ] ; then + ewarn "Server forced down." + eend $retval + return $retval + fi + + eerror "Forced shutdown failed!!!" + eerror "Something is wrong with your system." + eerror "Please take care of it manually." + eerror "Unable to stop server." + eend $retval + return $retval + else + ewarn "FORCE_QUIT disabled." + eerror "Unable to shutdown server." + eend 1 + return 1 + fi +} + +reload() { + ebegin "Reloading PostgreSQL configuration" + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + reload -s -D ${DATA_DIR}" + eend $? +} + +status() { + ebegin "Reloading PostgreSQL configuration" + su -l postgres \ + -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ + /usr/lib/postgresql-8.2/bin/pg_ctl \ + status -D ${DATA_DIR}" + eend $? +}