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 1RVqjj-0001Y2-JC for garchives@archives.gentoo.org; Wed, 30 Nov 2011 20:26:35 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3EF4621C0CD; Wed, 30 Nov 2011 20:26:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 028D021C0CD for ; Wed, 30 Nov 2011 20:26:17 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 39DC91B4012 for ; Wed, 30 Nov 2011 20:26:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 614D680044 for ; Wed, 30 Nov 2011 20:26:16 +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: <4795d6dffdd82a8948ff95d39ec23266094d983c.titanofold@gentoo> Subject: [gentoo-commits] proj/pgsql-patches:initscripts commit in: / X-VCS-Repository: proj/pgsql-patches X-VCS-Files: postgresql.init X-VCS-Directories: / X-VCS-Committer: titanofold X-VCS-Committer-Name: Aaron Swenson X-VCS-Revision: 4795d6dffdd82a8948ff95d39ec23266094d983c Date: Wed, 30 Nov 2011 20:26:16 +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: c28c98de-7976-4c99-8530-d59db4a9864a X-Archives-Hash: 1708f8adf47e71eca300d316a405665a commit: 4795d6dffdd82a8948ff95d39ec23266094d983c Author: Aaron W. Swenson gentoo org> AuthorDate: Wed Nov 30 13:50:33 2011 +0000 Commit: Aaron Swenson gentoo org> CommitDate: Wed Nov 30 13:50:33 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/pgsql-patches= .git;a=3Dcommit;h=3D4795d6df Move to start-stop-daemon. Create run directory if it doesn't exist. Parse postgresql.conf for port, unix_socket_directory, and log_destination allowing postgresql.conf to override /etc/conf.d/postgresql. --- postgresql.init | 165 +++++++++++++++++--------------------------------= ------ 1 files changed, 50 insertions(+), 115 deletions(-) diff --git a/postgresql.init b/postgresql.init index fa0f90c..a00c9c9 100644 --- a/postgresql.init +++ b/postgresql.init @@ -3,19 +3,33 @@ # Distributed under the terms of the GNU General Public License v2 # $Header: $ =20 -opts=3D"${opts} reload" +extra_started_command=3D"reload" + +get_config() { + [ -f ${PGDATA}/postgresql.conf ] || return 1 + + eval echo $(sed -e 's:#.*::' ${PGDATA}/postgresql.conf | awk '$1 =3D= =3D "'$1'" { print $2 =3D=3D "=3D" ? $3 : $2 }') +} =20 depend() { - use net - provide postgresql - provide postgresql-@SLOT@ + use net + provide postgresql + + if [ "$(get_config log_destination)" =3D "syslog" ]; then + use logger + fi } =20 +configured_port=3D$(get_config port) +: ${configured_port:=3D${PGPORT}} +socket_path=3D$(get_config unix_socket_path) +: ${socket_path:=3D@RUNDIR@/run/postgresql} + checkconfig() { # Check that DATA_DIR has been set and exists if [ -z ${DATA_DIR} ] ; then eerror "DATA_DIR not set" - eerror "HINT: Did you not update /etc/conf.d/postgresql-@SLOT@" + eerror "HINT: Perhaps you need to update /etc/conf.d/postgresql-@SLOT@= " fi if [ ! -d ${DATA_DIR} ] ; then eerror "Directory not found: ${DATA_DIR}" @@ -32,10 +46,11 @@ checkconfig() { [ ! -f ${PGDATA}/postgresql.conf ] && eerror " postgresql.conf" [ ! -f ${PGDATA}/pg_hba.conf ] && eerror " pg_hba.conf" [ ! -f ${PGDATA}/pg_ident.conf ] && eerror " pg_ident.conf" - eerror "HINT: Try:" - eerror "mv ${DATA_DIR}/*.conf ${PGDATA}" + eerror "HINT: Try:" + eerror " mv ${DATA_DIR}/*.conf ${PGDATA}" return 1 fi + local file local failed for file in pg_hba pg_ident postgresql ; do @@ -52,15 +67,11 @@ checkconfig() { return 1 fi =20 - # Ensures @RUN@ exists for those who have it on tmpfs. - if [ ! -d @RUN@ ] ; then - mkdir -p @RUN@ - chown postgres:postgres @RUN@ - fi - if [ -e @RUN@/.s.PGSQL.${PGPORT} ] ; then - eerror "Socket conflict." + checkpath -d -m 0770 -o postgres:postgres ${socket_path} + if [ -e ${socket_path}/.s.PGSQL.${configured_port} ] ; then + eerror "Socket conflict." eerror "A server is already listening on:" - eerror " @RUN@/.s.PGSQL.${PGPORT}" + eerror " ${socket_path}/.s.PGSQL.${configured_port}" eerror "HINT: Change PGPORT to listen on a different socket." return 1 fi @@ -71,17 +82,17 @@ start() { =20 ebegin "Starting PostgreSQL" =20 - if [ -f ${DATA_DIR}/postmaster.pid ] ; then - rm -f ${DATA_DIR}/postmaster.pid - fi + rm -f ${DATA_DIR}/postmaster.pid =20 local retval =20 - su -l postgres \ - -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ - /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ - start ${WAIT_FOR_START} -t ${START_TIMEOUT} -s -D ${DATA_DIR} \ - -o '-D ${PGDATA} --data-directory=3D${DATA_DIR} --silent-mode=3Dtrue $= {PGOPTS}'" + start-stop-daemon --start \ + --user postgres \ + --exec /usr/lib/postgresql-@SLOT@/bin/postgres \ + --env "PGPORT=3D${configured_port} ${PG_EXTRA_ENV}" \ + --wait $((${START_TIMEOUT}*1000)) \ + --pidfile ${DATA_DIR}/postmaster.pid \ + -- -D ${PGDATA} --data-directory=3D${DATA_DIR} --silent-mode=3Dtrue ${= PGOPTS} retval=3D$? =20 if [ $retval -ne 0 ] ; then @@ -90,112 +101,36 @@ start() { return $retval fi =20 - # 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 $retval } =20 stop() { - ebegin "Stopping PostgreSQL (this can take up to $(( ${NICE_TIMEOUT} + = ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} )) seconds)" + local seconds=3D$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT= } )) + ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)" =20 local retval - - if [ "${NICE_QUIT}" !=3D "NO" ] ; then - su -l postgres \ - -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ - /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ - stop ${WAIT_FOR_STOP} -t ${NICE_TIMEOUT} -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 + local retries=3DSIGTERM/$((${NICE_TIMEOUT}*1000)) =20 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-@SLOT@/bin/pg_ctl \ - stop ${WAIT_FOR_STOP} -t ${RUDE_TIMEOUT} -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." + einfo "RUDE_QUIT enabled." + retries=3D"${retries}/SIGINT/$((${RUDE_TIMEOUT}*1000))" 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-@SLOT@/bin/pg_ctl \ - stop ${WAIT_FOR_STOP} -t ${FORCE_TIMEOUT} -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 + einfo "FORCE_QUIT enabled." + ewarn "A recover-run might be executed on next startup." + retries=3D"${retries}/SIGQUIT/$((${FORCE_TIMEOUT}*1000))" fi -} =20 -reload() { - ebegin "Reloading PostgreSQL configuration" - su -l postgres \ - -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ - /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ - reload -s -D ${DATA_DIR}" - eend $? + start-stop-daemon --stop \ + --exec /usr/lib/postgresql-@SLOT@/bin/postgres \ + --retry ${retries} \ + --pidfile ${DATA_DIR}/postmaster.pid + + eend } =20 -status() { +reload() { ebegin "Reloading PostgreSQL configuration" - su -l postgres \ - -c "env PGPORT=3D\"${PGPORT}\" ${PG_EXTRA_ENV} \ - /usr/lib/postgresql-@SLOT@/bin/pg_ctl \ - status -D ${DATA_DIR}" + kill -HUP $(head -n1 ${DATA_DIR}/postmaster.pid) eend $? }