diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2012-11-07 09:12:09 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2012-11-07 09:12:09 +0000 |
commit | 558388f10a0fd7b392d8ab5761ccfddf79485ede (patch) | |
tree | 528f0c4558792d25fd50168e6c23ef649c63397c /main/postgresql/postgresql.initd | |
parent | b3b060d72e80703b36092bce96ad5490b313eeb7 (diff) | |
download | aports-558388f10a0fd7b392d8ab5761ccfddf79485ede.tar.bz2 aports-558388f10a0fd7b392d8ab5761ccfddf79485ede.tar.xz |
main/postgresql: fix init scripts for 9.2
- change some variables, {NICE,RUDE,FORCE}_TIMEOUT to correspond with
gentoo variables, while still beeing backawards compatible
- change data dir to 9.2
- patch initdb to not suggest how to start postgresql
Diffstat (limited to 'main/postgresql/postgresql.initd')
-rw-r--r-- | main/postgresql/postgresql.initd | 124 |
1 files changed, 68 insertions, 56 deletions
diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd index 785826bd2f..6771c85045 100644 --- a/main/postgresql/postgresql.initd +++ b/main/postgresql/postgresql.initd @@ -12,10 +12,25 @@ depend() { after firewall } +get_config() { + [ -f ${PGDATA%/}/postgresql.conf ] || return 1 + eval echo $(sed -e 's:#.*::' ${PGDATA%/}/postgresql.conf | awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }') +} + + checkconfig() { - [ -d "$PGDATA/base" ] && return 0 - echo "checking config" + configured_port=$(get_config port) + : ${configured_port:=${PGPORT:-5432}} + socket_path=$(get_config unix_socket_directory) + : ${socket_path:=/var/run/postgresql} + checkpath -d -m 0770 -o postgres:postgres ${socket_path} + + if [ -n "$WAIT_FOR_START" ]; then + START_TIMEOUT=$WAIT_FOR_START + fi + + [ -d "$PGDATA/base" ] && return 0 if [ -z "$AUTO_SETUP" ] ; then eerror "Database not found at: $PGDATA" eerror "Please make sure that PGDATA points to the right path." @@ -34,72 +49,71 @@ start() { rm -f "$PGDATA/postmaster.pid" fi - local retval - - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl start ${WAIT_FOR_START} -o '--silent-mode=true ${PGOPTS}'" >/dev/null + local retval= x= extraenv= + for x in ${PG_EXTRA_ENV} ; do + extraenv="${extraenv} --env ${x}" + done + + start-stop-daemon --start \ + --user ${PGUSER:-postgres} \ + --group ${PGGROUP:-postgres} \ + --env "PGPORT=${configured_port}" \ + ${extraenv} \ + --pidfile ${PGDATA}/postmaster.pid \ + --wait 100 \ + --exec /usr/bin/pg_ctl \ + -- \ + start -s -w -t ${START_TIMEOUT:-10} \ + -l ${PGDATA}/postmaster.log \ + -D ${PGDATA} -o "--data-directory=${PGDATA} $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 - read pid < "$PGDATA/postmaster.pid" - test -d /proc/"${pid}" - eend $? + if [ $retval -ne 0 ] ; then + eerror "Check the log for a possible explanation of the above error." + eerror " ${PGDATA}/postmaster.log" + fi + eend $retval } stop() { - ebegin "Stopping PostgreSQL (this can take up to $(( ${WAIT_FOR_DISCONNECT} + ${WAIT_FOR_CLEANUP} )) seconds)" + if [ -n "$WAIT_FOR_DISCONNECT" ]; then + NICE_TIMEOUT=$WAIT_FOR_DISCONNECT + fi + if [ -n "$WAIT_FOR_CLEANUP" ]; then + RUDE_QUIT=YES + RUDE_TIMEOUT=$WAIT_FOR_CLEANUP + fi + if [ -n "$WAIT_FOR_QUIT" ] && [ $WAIT_FOR_QUIT -ne 0 ]; then + FORCE_QUIT=YES + FORCE_TIMEOUT=$WAIT_FOR_QUIT + fi + local seconds=${NICE_TIMEOUT} local retval - - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl stop -t ${WAIT_FOR_DISCONNECT} -m smart" >/dev/null - - 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/bin/pg_ctl stop -m fast" >/dev/null - - 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 + local retries=SIGTERM/${NICE_TIMEOUT} + if [ "${RUDE_QUIT}" != "NO" ] ; then + retries="${retries}/SIGINT/${RUDE_TIMEOUT}" + seconds=$(( $seconds + ${NICE_TIMEOUT} )) + fi + if [ "${FORCE_QUIT}" = "YES" ] ; then + retries="${retries}/SIGQUIT/${FORCE_TIMEOUT}" + seconds=$(( $seconds + ${FORCE_TIMEOUT} )) 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/bin/pg_ctl stop -m immediate" >/dev/null - - retval=$? - [ $retval -eq 0 ] && eend $retval && return $retval + ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)" - eerror "Forced shutdown failed!!! Something is wrong with your system, please take care of it manually." - eend $? + # Loops through nice, rude, and force quit in one go. + start-stop-daemon --stop \ + --exec /usr/bin/postgres \ + --retry ${retries} \ + --progress \ + --pidfile ${PGDATA}/postmaster.pid + eend } reload() { ebegin "Reloading PostgreSQL configuration" - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload" >/dev/null + kill -HUP $(head -n1 ${PGDATA}/postmaster.pid) eend $? } @@ -124,8 +138,6 @@ setup() { chmod 0700 "${PGDATA}" cd "${PGDATA}" # to avoid the: could not change directory to "/root" su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres - einfo "You can use the '/etc/init.d/postgresql' script to run PostgreSQL instead" - einfo "of 'pg_ctl'." local res=$? # move the pg_hba.conf and friends |