aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron W. Swenson <titanofold@gentoo.org>2012-05-23 14:48:38 -0400
committerAaron W. Swenson <titanofold@gentoo.org>2012-05-23 14:48:38 -0400
commitd8732f86c3fe03b224bdeb5d7575de29ab8bc779 (patch)
tree7a8156f13d3edfb7c842b9432bc07ee5f6ab38bb
parentFixed passing environments issue. (Bug 394159) (diff)
downloadpatches-d8732f86c3fe03b224bdeb5d7575de29ab8bc779.tar.gz
patches-d8732f86c3fe03b224bdeb5d7575de29ab8bc779.tar.bz2
patches-d8732f86c3fe03b224bdeb5d7575de29ab8bc779.zip
Fixed startup command for 9.2. Refactored config file check.
-rwxr-xr-x[-rw-r--r--]postgresql.init200
1 files changed, 96 insertions, 104 deletions
diff --git a/postgresql.init b/postgresql.init
index 363ea1a..ec31748 100644..100755
--- a/postgresql.init
+++ b/postgresql.init
@@ -16,7 +16,7 @@ depend() {
provide postgresql
if [ "$(get_config log_destination)" = "syslog" ]; then
- use logger
+ use logger
fi
}
@@ -26,116 +26,108 @@ 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: Perhaps you need to update /etc/conf.d/postgresql-@SLOT@"
- fi
- if [ ! -d ${DATA_DIR} ] ; then
- eerror "Directory not found: ${DATA_DIR}"
- eerror "HINT: Ensure that DATA_DIR points to the right path."
- eerror "HINT: Or perhaps you need to create the database cluster:"
- eerror " emerge --config dev-db/postgresql-server:@SLOT@"
- return 1
- fi
-
- # Check for the existence of and PostgreSQL's ability to read the config files.
- if [ ! -f ${PGDATA}/postgresql.conf -o \
- ! -f ${PGDATA}/pg_hba.conf -o ! -f ${PGDATA}/pg_ident.conf ] ; then
- eerror "The following file(s) were not found in ${PGDATA}:"
- [ ! -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}"
- return 1
- fi
-
- local file
- local failed
- for file in pg_hba pg_ident postgresql ; do
- file="${PGDATA}/${file}.conf"
- su postgres -c "test -r ${file}" || failed="${file} ${failed}"
- done
- if [ -n "${failed}" ] ; then
- eerror "The following file(s) are not readable by 'postgres':"
- local x
- for x in ${failed} ; do
- eerror " ${x}"
- done
- eerror "HINT: Try: 'chmod 644 ${PGDATA}/*.conf'"
- return 1
- fi
-
- 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 " ${socket_path}/.s.PGSQL.${configured_port}"
- eerror "HINT: Change PGPORT to listen on a different socket."
- return 1
- fi
+ # Check that DATA_DIR has been set and exists
+ if [ -z ${DATA_DIR} ] ; then
+ eerror "DATA_DIR not set"
+ eerror "HINT: Perhaps you need to update /etc/conf.d/postgresql-@SLOT@"
+ fi
+ if [ ! -d ${DATA_DIR} ] ; then
+ eerror "Directory not found: ${DATA_DIR}"
+ eerror "HINT: Ensure that DATA_DIR points to the right path."
+ eerror "HINT: Or perhaps you need to create the database cluster:"
+ eerror " emerge --config dev-db/postgresql-server:@SLOT@"
+ return 1
+ fi
+
+ # Check for the existence of PostgreSQL's config files.
+ local file
+ local status=0
+ for file in postgresql pg_hba pg_ident ; do
+ file="${PGDATA}/${file}.conf"
+ if [ -f ${file} ] ; then
+ checkpath -f -m 0600 -o postgres:postgres ${file}
+ else
+ eerror "${file} not found"
+ status=1
+ fi
+ done
+ if [ ${status} ] ; then
+ eerror "HINT: Try:"
+ eerror " mv ${DATA_DIR}/*.conf ${PGDATA}"
+ return 1
+ fi
+
+ # Check the socket directory
+ 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 " ${socket_path}/.s.PGSQL.${configured_port}"
+ eerror "HINT: Change PGPORT to listen on a different socket."
+ return 1
+ fi
}
start() {
- checkconfig || return 1
-
- ebegin "Starting PostgreSQL"
-
- rm -f ${DATA_DIR}/postmaster.pid
-
- local extraenv
- local x
- for x in ${PG_EXTRA_ENV} ; do
- extraenv="${extraenv} --env ${x}"
- done
-
- start-stop-daemon --start \
- --user postgres \
- --exec /usr/lib/postgresql-@SLOT@/bin/postgres \
- --env "PGPORT=${configured_port}" \
- ${extraenv} \
- --wait $((${START_TIMEOUT}*1000)) \
- --pidfile ${DATA_DIR}/postmaster.pid \
- -- -D ${PGDATA} --data-directory=${DATA_DIR} --silent-mode=true ${PGOPTS}
- local retval=$?
-
- if [ $retval -ne 0 ] ; then
- eerror "Check the PostgreSQL @SLOT@ log for a detailed explanation of the above error."
- eend $retval
- return $retval
- fi
-
- eend $retval
+ checkconfig || return 1
+
+ ebegin "Starting PostgreSQL"
+
+ rm -f ${DATA_DIR}/postmaster.pid
+
+ local extraenv
+ local x
+ for x in ${PG_EXTRA_ENV} ; do
+ extraenv="${extraenv} --env ${x}"
+ done
+
+ start-stop-daemon --start \
+ --user postgres \
+ --env "PGPORT=${configured_port}" \
+ ${extraenv} \
+ --pidfile ${DATA_DIR}/postmaster.pid \
+ --exec /usr/bin/pg_ctl@SLOT@ \
+ -- start -s -l ${DATA_DIR}/postmaster.log -D ${PGDATA} \
+ -o "--data-directory=${DATA_DIR} ${PGOPTS}"
+ local retval=$?
+
+ if [ $retval -ne 0 ] ; then
+ eerror "Check the log for a possible explanation of the above error."
+ eerror " ${DATA_DIR}/postmaster.log"
+ eend $retval
+ return $retval
+ fi
+
+ eend $retval
}
stop() {
- local seconds=$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} ))
- ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)"
-
- local retval
- local retries=SIGTERM/${NICE_TIMEOUT}
-
- if [ "${RUDE_QUIT}" != "NO" ] ; then
- einfo "RUDE_QUIT enabled."
- retries="${retries}/SIGINT/${RUDE_TIMEOUT}"
- fi
- if [ "${FORCE_QUIT}" = "YES" ] ; then
- einfo "FORCE_QUIT enabled."
- ewarn "A recover-run might be executed on next startup."
- retries="${retries}/SIGQUIT/${FORCE_TIMEOUT}"
- fi
-
- start-stop-daemon --stop \
- --exec /usr/lib/postgresql-@SLOT@/bin/postgres \
- --retry ${retries} \
- --pidfile ${DATA_DIR}/postmaster.pid
-
- eend
+ local seconds=$(( ${NICE_TIMEOUT} + ${RUDE_TIMEOUT} + ${FORCE_TIMEOUT} ))
+ ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)"
+
+ local retval
+ local retries=SIGTERM/${NICE_TIMEOUT}
+
+ if [ "${RUDE_QUIT}" != "NO" ] ; then
+ einfo "RUDE_QUIT enabled."
+ retries="${retries}/SIGINT/${RUDE_TIMEOUT}"
+ fi
+ if [ "${FORCE_QUIT}" = "YES" ] ; then
+ einfo "FORCE_QUIT enabled."
+ ewarn "A recover-run might be executed on next startup."
+ retries="${retries}/SIGQUIT/${FORCE_TIMEOUT}"
+ fi
+
+ start-stop-daemon --stop \
+ --exec /usr/lib/postgresql-@SLOT@/bin/postgres \
+ --retry ${retries} \
+ --pidfile ${DATA_DIR}/postmaster.pid
+
+ eend
}
reload() {
- ebegin "Reloading PostgreSQL configuration"
- kill -HUP $(head -n1 ${DATA_DIR}/postmaster.pid)
- eend $?
+ ebegin "Reloading PostgreSQL configuration"
+ kill -HUP $(head -n1 ${DATA_DIR}/postmaster.pid)
+ eend $?
}