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 | |
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')
-rw-r--r-- | main/postgresql/APKBUILD | 24 | ||||
-rw-r--r-- | main/postgresql/initdb.patch | 18 | ||||
-rw-r--r-- | main/postgresql/pg-restore.initd | 9 | ||||
-rw-r--r-- | main/postgresql/postgresql.confd | 87 | ||||
-rw-r--r-- | main/postgresql/postgresql.initd | 124 |
5 files changed, 148 insertions, 114 deletions
diff --git a/main/postgresql/APKBUILD b/main/postgresql/APKBUILD index e792fcd2f7..d77f797c1e 100644 --- a/main/postgresql/APKBUILD +++ b/main/postgresql/APKBUILD @@ -1,7 +1,7 @@ # Maintainer: Natanael Copa <ncopa@alpinelinux.org> pkgname=postgresql pkgver=9.2.1 -pkgrel=0 +pkgrel=1 pkgdesc="A sophisticated object-relational DBMS" url="http://www.postgresql.org/" arch="all" @@ -11,15 +11,26 @@ install="$pkgname.pre-upgrade" depends_dev="readline-dev openssl-dev zlib-dev libxml2-dev" makedepends="$depends_dev" subpackages="$pkgname-dev $pkgname-doc libpq $pkgname-client" +patches="initdb.patch" source="ftp://ftp.$pkgname.org/pub/source/v$pkgver/$pkgname-$pkgver.tar.bz2 + $patches $pkgname.initd $pkgname.confd pg-restore.initd pg-restore.confd " +_builddir="$srcdir"/$pkgname-$pkgver +prepare() { + cd "$_builddir" + for i in $patches; do + msg $i + patch -p1 -i "$srcdir"/$i || return 1 + done +} + build() { - cd "$srcdir"/$pkgname-$pkgver || return 1 + cd "$_builddir" ./configure --prefix=/usr \ --mandir=/usr/share/man \ --with-openssl \ @@ -29,7 +40,7 @@ build() { } package() { - cd "$srcdir"/$pkgname-$pkgver || return 1 + cd "$_builddir" make DESTDIR="$pkgdir" install install-docs || return 1 install -D -m755 "$srcdir"/postgresql.initd \ @@ -58,7 +69,8 @@ client() { md5sums="c0b4799ea9850eae3ead14f0a60e9418 postgresql-9.2.1.tar.bz2 -4d2f5be74fae4895db3d993e69bbda10 postgresql.initd -b609795f715cefcc30b08e4ed01f4416 postgresql.confd -df2d90fc713b4e89fd21abb9e36cd688 pg-restore.initd +de29e4cea00a3318a77587fbbc7b6243 initdb.patch +01cc8d4a4cbc77a7b6f84344155232d5 postgresql.initd +ca9759d29dc86402858821d5fdec48a1 postgresql.confd +d2a51db4436e550d56bb1e96699faef4 pg-restore.initd bf45384752b320b369f1425939763178 pg-restore.confd" diff --git a/main/postgresql/initdb.patch b/main/postgresql/initdb.patch new file mode 100644 index 0000000000..f2fad3f028 --- /dev/null +++ b/main/postgresql/initdb.patch @@ -0,0 +1,18 @@ +--- ./src/bin/initdb/initdb.c.orig ++++ ./src/bin/initdb/initdb.c +@@ -3317,14 +3317,6 @@ + strlcpy(bin_dir, argv[0], sizeof(bin_dir)); + get_parent_directory(bin_dir); + +- printf(_("\nSuccess. You can now start the database server using:\n\n" +- " %s%s%spostgres%s -D %s%s%s\n" +- "or\n" +- " %s%s%spg_ctl%s -D %s%s%s -l logfile start\n\n"), +- QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH, +- QUOTE_PATH, pg_data_native, QUOTE_PATH, +- QUOTE_PATH, bin_dir, (strlen(bin_dir) > 0) ? DIR_SEP : "", QUOTE_PATH, +- QUOTE_PATH, pg_data_native, QUOTE_PATH); +- ++ printf(_("\nSuccess.\n\n")); + return 0; + } diff --git a/main/postgresql/pg-restore.initd b/main/postgresql/pg-restore.initd index 1cc4da5c8f..f6075bca2d 100644 --- a/main/postgresql/pg-restore.initd +++ b/main/postgresql/pg-restore.initd @@ -1,8 +1,6 @@ #!/sbin/runscript -. /etc/conf.d/postgresql - -opts="${opts} dump restore purge" +extra_commands="${opts} dump restore purge" depend() { need postgresql @@ -12,11 +10,10 @@ restore() { yesno "$PGDUMP" && return 0 ebegin "Restoring PostgreSQL $PGDUMP" psql -U ${PG_USER:-postgres} ${PSQL_OPTS} -f "$PGDUMP" >/dev/null 2>/dev/null + local res=$? yesno "$KEEP_DUMP" || rm -f "$PGDUMP" - - su -l ${PGUSER} \ - -c "env PGDATA=\"${PGDATA}\" /usr/bin/pg_ctl reload " >/dev/null eend $res + /etc/init.d/postgresql reload } dump() { diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd index 0bf3350b63..7313984024 100644 --- a/main/postgresql/postgresql.confd +++ b/main/postgresql/postgresql.confd @@ -1,56 +1,51 @@ -# PostgreSQL's Database Directory -PGDATA="/var/lib/postgresql/9.1/data" - -# PostgreSQL User -PGUSER="postgres" - -# PostgreSQL Group -PGGROUP="postgres" +# Which port and socket to bind PostgreSQL +PGPORT="5432" + +# How long to wait for server to start in seconds +START_TIMEOUT=10 + +# NICE_QUIT ignores new connections and wait for clients to disconnect from +# server before shutting down. NICE_TIMEOUT in seconds determines how long to +# wait for this to succeed. +NICE_TIMEOUT=60 + +# Forecfully disconnect clients from server and shut down. This is performed +# after NICE_QUIT. Terminated client connections have their open transactions +# rolled back. +# Set RUDE_QUIT to "NO" to disable. RUDE_TIMEOUT in seconds. +RUDE_QUIT="YES" +RUDE_TIMEOUT=30 + +# If the server still fails to shutdown, you can force it to quit by setting +# this to YES and a recover-run will execute on the next startup. +# Set FORCE_QUIT to "YES" to enable. FORCE_TIMEOUT in seconds. +FORCE_QUIT="NO" +FORCE_TIMEOUT=2 # Extra options to run postmaster with, e.g.: # -N is the maximal number of client connections # -B is the number of shared buffers and has to be at least 2x the value for -N -# Please read the man-page to postmaster for more options. Many of these options -# can be set directly in the configuration-file. +# Please read the man-page to postmaster for more options. Many of these +# options can be set directly in the configuration file. #PGOPTS="-N 512 -B 1024" +# Pass extra environment variables. If you have to export environment variables +# for the database process, this can be done here. +# Don't forget to escape quotes. +#PG_EXTRA_ENV="PGPASSFILE=\"/path/to/.pgpass\"" -# SERVER SHUTDOWN: -# The server will receive 3 signals in the worst case: -# 1. SIGTERM -# This signals the server to ignore new connections and to -# wait for all clients to end their transactions before shutting down. -# Use WAIT_FOR_DISCONNECT to control how much time the clients -# should have until the next signal is being sent. -# 2. SIGINT -# Tell the server to forcefully disconnect all clients. -# Terminating a client results in a rollback of the open transactions for this client. -# Use WAIT_FOR_CLEANUP to determine how much time the server has -# for cleanup. -# 3. SIGQUIT -# This will terminate the server immediately and results in a recovery run for the next start. - -# Wait for clients to disconnect -WAIT_FOR_DISCONNECT=30 - -# Time the server has to clean up -WAIT_FOR_CLEANUP=60 - -# Time the server has to quit (with a recover-run on next startup) -# Set to 0 to deactivate it -WAIT_FOR_QUIT=60 - -# Comment this out if you don't want to wait for the server to -# startup before continuing. For example, if this server is a -# PITR log shipping based replication standby -WAIT_FOR_START="-w" - -# If you have to export environment variables for the database process, -# this can be done here. +############################################################################## # -# Example: -# export R_HOME="/usr/lib/R" +# The following values should not be arbitrarily changed. +# +# The initscript uses these variables to inform PostgreSQL where to find +# its data directory and configuration files. +# +############################################################################## -# Automatically set up a new database if missing on startup -AUTO_SETUP=yes +# PostgreSQL's Database Directory +PGDATA="/var/lib/postgresql/9.2/data" +# Additional options to pass to initdb. +# See `man initdb' for available options. +#PG_INITDB_OPTS="--locale=en_US.UTF-8" 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 |