From: "Aaron Swenson" <titanofold@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pgsql-patches:initscripts commit in: /
Date: Wed, 30 Nov 2011 20:26:16 +0000 (UTC) [thread overview]
Message-ID: <4795d6dffdd82a8948ff95d39ec23266094d983c.titanofold@gentoo> (raw)
commit: 4795d6dffdd82a8948ff95d39ec23266094d983c
Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org>
AuthorDate: Wed Nov 30 13:50:33 2011 +0000
Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org>
CommitDate: Wed Nov 30 13:50:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pgsql-patches.git;a=commit;h=4795d6df
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: $
-opts="${opts} reload"
+extra_started_command="reload"
+
+get_config() {
+ [ -f ${PGDATA}/postgresql.conf ] || return 1
+
+ eval echo $(sed -e 's:#.*::' ${PGDATA}/postgresql.conf | awk '$1 == "'$1'" { print $2 == "=" ? $3 : $2 }')
+}
depend() {
- use net
- provide postgresql
- provide postgresql-@SLOT@
+ use net
+ provide postgresql
+
+ if [ "$(get_config log_destination)" = "syslog" ]; then
+ use logger
+ fi
}
+configured_port=$(get_config port)
+: ${configured_port:=${PGPORT}}
+socket_path=$(get_config unix_socket_path)
+: ${socket_path:=@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
- # 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() {
ebegin "Starting PostgreSQL"
- if [ -f ${DATA_DIR}/postmaster.pid ] ; then
- rm -f ${DATA_DIR}/postmaster.pid
- fi
+ rm -f ${DATA_DIR}/postmaster.pid
local retval
- su -l postgres \
- -c "env PGPORT=\"${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=${DATA_DIR} --silent-mode=true ${PGOPTS}'"
+ start-stop-daemon --start \
+ --user postgres \
+ --exec /usr/lib/postgresql-@SLOT@/bin/postgres \
+ --env "PGPORT=${configured_port} ${PG_EXTRA_ENV}" \
+ --wait $((${START_TIMEOUT}*1000)) \
+ --pidfile ${DATA_DIR}/postmaster.pid \
+ -- -D ${PGDATA} --data-directory=${DATA_DIR} --silent-mode=true ${PGOPTS}
retval=$?
if [ $retval -ne 0 ] ; then
@@ -90,112 +101,36 @@ start() {
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 server."
- eerror "Please check whether there is another server running on the same port or read the log-file."
- eend 1
- return 1
- fi
-
eend $retval
}
stop() {
- ebegin "Stopping PostgreSQL (this can take up to $(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} )) seconds)"
+ local seconds=$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} ))
+ ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)"
local retval
-
- if [ "${NICE_QUIT}" != "NO" ] ; then
- su -l postgres \
- -c "env PGPORT=\"${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=$?
-
- 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=SIGTERM/$((${NICE_TIMEOUT}*1000))
if [ "${RUDE_QUIT}" != "NO" ] ; then
- ewarn "RUDE_QUIT enabled."
- ewarn "Going to shutdown the server anyway."
-
- su -l postgres \
- -c "env PGPORT=\"${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=$?
-
- 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="${retries}/SIGINT/$((${RUDE_TIMEOUT}*1000))"
fi
-
if [ "${FORCE_QUIT}" = "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=\"${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=$?
-
- 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="${retries}/SIGQUIT/$((${FORCE_TIMEOUT}*1000))"
fi
-}
-reload() {
- ebegin "Reloading PostgreSQL configuration"
- su -l postgres \
- -c "env PGPORT=\"${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
}
-status() {
+reload() {
ebegin "Reloading PostgreSQL configuration"
- su -l postgres \
- -c "env PGPORT=\"${PGPORT}\" ${PG_EXTRA_ENV} \
- /usr/lib/postgresql-@SLOT@/bin/pg_ctl \
- status -D ${DATA_DIR}"
+ kill -HUP $(head -n1 ${DATA_DIR}/postmaster.pid)
eend $?
}
next reply other threads:[~2011-11-30 20:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-30 20:26 Aaron Swenson [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-04-23 1:52 [gentoo-commits] proj/pgsql-patches:initscripts commit in: / Mike Gilbert
2013-08-21 0:59 Aaron Swenson
2013-06-09 2:36 Aaron Swenson
2013-06-09 2:36 Aaron Swenson
2013-03-09 15:01 Aaron Swenson
2013-02-08 14:46 Aaron Swenson
2013-02-08 13:01 Aaron Swenson
2013-02-03 15:22 Aaron Swenson
2013-01-19 20:50 Aaron Swenson
2012-11-11 14:49 Aaron Swenson
2012-06-08 15:04 Aaron Swenson
2012-06-08 15:04 Aaron Swenson
2012-06-08 15:04 Aaron Swenson
2012-06-08 15:04 Aaron Swenson
2012-06-08 15:04 Aaron Swenson
2012-05-27 14:00 Aaron Swenson
2012-05-24 19:58 Aaron Swenson
2012-05-24 19:58 Aaron Swenson
2012-05-24 19:58 Aaron Swenson
2012-05-24 19:58 Aaron Swenson
2012-05-24 19:23 Aaron Swenson
2012-05-24 19:23 Aaron Swenson
2011-12-24 13:47 Aaron Swenson
2011-12-24 13:47 Aaron Swenson
2011-11-30 20:26 Aaron Swenson
2011-09-18 19:56 Aaron Swenson
2011-09-18 19:26 Aaron Swenson
2011-03-26 23:25 Aaron Swenson
2011-03-26 22:34 Aaron Swenson
2011-03-26 2:13 Aaron Swenson
2011-03-24 22:41 Aaron Swenson
2011-03-23 3:19 Aaron Swenson
2011-03-20 1:36 Aaron Swenson
2011-03-20 0:39 Aaron Swenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4795d6dffdd82a8948ff95d39ec23266094d983c.titanofold@gentoo \
--to=titanofold@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox