From e791f83899ca8924a6e0048109226a38e4f53355 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 2 Mar 2010 06:45:21 +0100 Subject: [PATCH] postgresql: improve rc service, INSTALL, add pam conf file. --HG-- extra : convert_revision : d5fe81f0ac5134f796f8e9fce96e53c764fbfacf --- srcpkgs/postgresql/INSTALL | 17 ++--- srcpkgs/postgresql/files/postgresql.confd | 40 +--------- srcpkgs/postgresql/files/postgresql.pam | 3 + srcpkgs/postgresql/files/postgresql.rc | 93 +++++------------------ srcpkgs/postgresql/template | 2 + 5 files changed, 33 insertions(+), 122 deletions(-) create mode 100644 srcpkgs/postgresql/files/postgresql.pam diff --git a/srcpkgs/postgresql/INSTALL b/srcpkgs/postgresql/INSTALL index 64fb82939a8..e0084967fbb 100644 --- a/srcpkgs/postgresql/INSTALL +++ b/srcpkgs/postgresql/INSTALL @@ -5,18 +5,17 @@ post) cat << _EOF ===================================================================== -Please note that to properly initialize the PostgreSQL server, -a configuration file should be copied to /var/lib/postgresql from -/usr/share/postgresql/postgresql.conf.sample. - -To initialize the PostgreSQL data directory, use this: - - $ sudo su -l postgres -c initdb -D /var/lib/postgresql/data - -To start the server finally use: +Please note that to properly start the PostgreSQL server, +a sample configuration file should be copied to +/var/lib/postgresql/data from +/usr/share/postgresql/postgresql.conf.sample, edit it accordingly +and use the following the command: $ /etc/init.d/postgresql start +The configuration file for starting the service is available in +/etc/conf.d/postgresql. + ===================================================================== _EOF ;; diff --git a/srcpkgs/postgresql/files/postgresql.confd b/srcpkgs/postgresql/files/postgresql.confd index efacaf595a7..3f5e46af734 100644 --- a/srcpkgs/postgresql/files/postgresql.confd +++ b/srcpkgs/postgresql/files/postgresql.confd @@ -3,6 +3,9 @@ # PostgreSQL's Database Directory PGDATA="/var/lib/postgresql/data" +# PostgreSQL's log file. +PGLOG="/var/log/postgresql.log" + # PostgreSQL User PGUSER="postgres" @@ -15,40 +18,3 @@ PGGROUP="postgres" # Please read the man-page to postmaster for more options. Many of these options # can be set directly in the configuration-file. #PGOPTS="-N 512 -B 1024" - - -# SERVER SHUTDOWN: -# The server will receive 3 signals in the worst case: -# 1. SIGTERM -# This signals the server to ignore new connections and to -# wait for all clients to end their transactions before shutting down. -# Use WAIT_FOR_DISCONNECT to control how much time the clients -# should have until the next signal is being sent. -# 2. SIGINT -# Tell the server to forcefully disconnect all clients. -# Terminating a client results in a rollback of the open transactions for this client. -# Use WAIT_FOR_CLEANUP to determine how much time the server has -# for cleanup. -# 3. SIGQUIT -# This will terminate the server immediately and results in a recovery run for the next start. - -# Wait for clients to disconnect -WAIT_FOR_DISCONNECT=30 - -# Time the server has to clean up -WAIT_FOR_CLEANUP=60 - -# Time the server has to quit (with a recover-run on next startup) -# Set to 0 to deactivate it -WAIT_FOR_QUIT=60 - -# Comment this out if you don't want to wait for the server to -# startup before continuing. For example, if this server is a -# PITR log shipping based replication standby -WAIT_FOR_START="-w" - -# If you have to export environment variables for the database process, -# this can be done here. -# -# Example: -# export R_HOME="/usr/lib/R" diff --git a/srcpkgs/postgresql/files/postgresql.pam b/srcpkgs/postgresql/files/postgresql.pam new file mode 100644 index 00000000000..53724d1f86a --- /dev/null +++ b/srcpkgs/postgresql/files/postgresql.pam @@ -0,0 +1,3 @@ +auth required pam_unix.so +account required pam_unix.so +session required pam_unix.so diff --git a/srcpkgs/postgresql/files/postgresql.rc b/srcpkgs/postgresql/files/postgresql.rc index 36da5f3b9c9..bed90702c38 100644 --- a/srcpkgs/postgresql/files/postgresql.rc +++ b/srcpkgs/postgresql/files/postgresql.rc @@ -1,9 +1,7 @@ #!/sbin/runscript -# Copyright 1999-2009 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Header: /var/www/viewcvs.gentoo.org/raw_cvs/gentoo-x86/dev-db/postgresql-server/files/postgresql.init-8.4,v 1.4 2010/01/26 22:01:21 patrick Exp $ -opts="${opts} reload" +: ${PGLOG:=/var/log/postgresql.log} +extra_commands="reload" depend() { @@ -11,96 +9,39 @@ depend() provide postgresql } -checkconfig() +start_pre() { if [ ! -d "$PGDATA" ] ; then - eerror "Directory not found: $PGDATA" - eerror "Please make sure that PGDATA points to the right path." - return 1 + einfo "Creating PostgreSQL dbdir: ${PGDATA}" + mkdir -p ${PGDATA} && \ + chown -R ${PGUSER}.${PGGROUP} ${PGDATA} + einfo "Initializing PostgreSQL dbdir: ${PGDATA}" + su -l ${PGUSER} -c "/usr/bin/initdb -D ${PGDATA}" + fi + if [ ! -e ${PGLOG} ]; then + touch -f ${PGLOG} + chown ${PGUSER} ${PGLOG} fi } start() { - checkconfig || return 1 - ebegin "Starting PostgreSQL" - - if [ -f "$PGDATA/postmaster.pid" ] ; then - rm -f "$PGDATA/postmaster.pid" - fi - - local retval - - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" ${PG_EXTRA_ENV} pg_ctl \ - start ${WAIT_FOR_START} -o '--silent-mode=true ${PGOPTS}'" - retval=$? - [ $retval -ne 0 ] && eend $retval && return $retval - - # 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 - # false reports the server as 'up' - sleep 2 - if [ ! -f "$PGDATA/postmaster.pid" ] ; then - eerror "The pid-file doesn't exist but pg_ctl reported \ -a running server." - eerror "Please check whether there is another server running \ -on the same port or read the log-file." - eend 1 - return 1 - fi - - local pid=$(grep "^[0-9]\+" "$PGDATA/postmaster.pid") - ps -p "${pid}" &> /dev/null + su -l ${PGUSER} -c "/usr/bin/pg_ctl -D ${PGDATA} -l ${PGLOG} \ + -W start ${PGOPTS}" eend $? } stop() { - ebegin "Stopping PostgreSQL (this can take up to \ -$(( ${WAIT_FOR_DISCONNECT} + ${WAIT_FOR_CLEANUP} )) seconds)" - - local retval - - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" pg_ctl \ - stop -t ${WAIT_FOR_DISCONNECT} -m smart" - - retval=$? - [ $retval -eq 0 ] && eend $retval && return $retval - - ewarn "Some clients did not disconnect within \ -${WAIT_FOR_DISCONNECT} seconds." - ewarn "Going to shutdown the server anyway." - - su -l ${PGUSER} -c "env PGDATA=\"${PGDATA}\" pg_ctl stop -m fast" - retval=$? - [ $retval -eq 0 ] && eend $retval && return $retval - - if [ ${WAIT_FOR_QUIT} -eq 0 ] ; then - eerror "Server did not shut down and sending the \ -SIGQUIT has been disabled." - eend $retval - return $retval - fi - - ewarn "Shutting down the server gracefully failed." - ewarn "Forcing it to shutdown which leads to a recover-run \ -on next startup." - - su -l ${PGUSER} -c "env PGDATA=\"${PGDATA}\" pg_ctl stop -m immediate" - retval=$? - [ $retval -eq 0 ] && eend $retval && return $retval - - eerror "Forced shutdown failed!!! Something is wrong with your \ -system, please take care of it manually." + ebegin "Stopping PostgreSQL" + su -l ${PGUSER} -c "/usr/bin/pg_ctl -D ${PGDATA} -l ${PGLOG} -w stop" eend $? } reload() { ebegin "Reloading PostgreSQL configuration" - su -l ${PGUSER} -c "env PGDATA=\"${PGDATA}\" pg_ctl reload" + su -l ${PGUSER} -c "/usr/bin/pg_ctl -D ${PGDATA} -l ${PGLOG} reload" eend $? } diff --git a/srcpkgs/postgresql/template b/srcpkgs/postgresql/template index 4b013bb79b2..b957f9604ad 100644 --- a/srcpkgs/postgresql/template +++ b/srcpkgs/postgresql/template @@ -54,4 +54,6 @@ post_install() ${DESTDIR}/etc/conf.d/postgresql install -D -m755 ${FILESDIR}/postgresql.rc \ ${DESTDIR}/etc/init.d/postgresql + install -D -m644 ${FILESDIR}/postgresql.pam \ + ${DESTDIR}/etc/pam.d/postgresql }