Created
September 17, 2009 17:15
-
-
Save damm/188597 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sbin/runscript | |
# Copyright 1999-2009 Gentoo Foundation | |
# Distributed under the terms of the GNU General Public License v2 | |
# $Header: /var/cvsroot/gentoo-x86/dev-db/postgresql-server/files/postgresql.init-8.4,v 1.1 2009/09/09 21:41:25 patrick Exp $ | |
opts="${opts} reload" | |
depend() { | |
use net | |
if [ -L /etc/eselect/postgresql/service ] ; then | |
local p_service="$(for f in /etc/eselect/postgresql/service/* ; do source $f ; done ; echo $postgres_service )" | |
test "${p_service}" = "${SVCNAME}" && provide postgresql | |
fi | |
} | |
checkconfig() { | |
if [ ! -d "$PGDATA" ] ; then | |
eerror "Directory not found: $PGDATA" | |
eerror "Please make sure that PGDATA points to the right path." | |
eerror "You can run 'emerge postgresql-server --config' to setup a new database cluster." | |
return 1 | |
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}\" /usr/lib/postgresql-8.4/bin/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 | |
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}\" /usr/lib/postgresql-8.4/bin/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}\" /usr/lib/postgresql-8.4/bin/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}\" /usr/lib/postgresql-8.4/bin/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." | |
eend $? | |
} | |
reload() { | |
ebegin "Reloading PostgreSQL configuration" | |
su -l ${PGUSER} \ | |
-c "env PGDATA=\"${PGDATA}\" /usr/lib/postgresql-8.4/bin/pg_ctl reload" | |
eend $? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment