aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-04-15 21:11:13 +0200
committerJakub Jirutka <jakub@jirutka.cz>2017-04-15 23:37:29 +0200
commit10d9cc8000c7da49bf13e516928f30fc80b1cf9f (patch)
tree120655923e3fb61f93bfa09fbc7a6f08fd38a1a3
parentd698c1e58c607861670cd94c9b8cb22f97555a88 (diff)
downloadaports-10d9cc8000c7da49bf13e516928f30fc80b1cf9f.tar.bz2
aports-10d9cc8000c7da49bf13e516928f30fc80b1cf9f.tar.xz
main/postgresql: rewrite runscript
But keep it backward compatible with old confd.
-rw-r--r--main/postgresql/APKBUILD25
-rw-r--r--main/postgresql/postgresql.confd76
-rw-r--r--main/postgresql/postgresql.initd269
3 files changed, 209 insertions, 161 deletions
diff --git a/main/postgresql/APKBUILD b/main/postgresql/APKBUILD
index 3d7a02d641..cdda829fa7 100644
--- a/main/postgresql/APKBUILD
+++ b/main/postgresql/APKBUILD
@@ -3,7 +3,7 @@
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
pkgname=postgresql
pkgver=9.6.2
-pkgrel=1
+pkgrel=2
pkgdesc="A sophisticated object-relational DBMS"
url="http://www.postgresql.org/"
arch="all"
@@ -33,15 +33,11 @@ builddir="$srcdir/$pkgname-$pkgver"
prepare() {
default_prepare || return 1
+ cd "$builddir"
- # sanity check of conf.d
- (
- . "$srcdir"/postgresql.confd
- _datadir=/var/lib/postgresql/${pkgver%.*}/data
- if [ "$_datadir" != "$PGDATA" ]; then
- die "PGDATA is $PGDATA while $_datadir is expected"
- fi
- ) || return 1
+ local file; for file in $pkgname.initd $pkgname.confd; do
+ sed "s|@VERSION@|${pkgver%.*}|" "$srcdir"/$file > $file || return 1
+ done
cp -al "$builddir" "$builddir"~py3
}
@@ -96,10 +92,11 @@ package() {
install -d -m755 -o postgres -g postgres \
"$pkgdir"/var/lib/postgresql || return 1
- install -D -m755 "$srcdir"/postgresql.initd \
+ install -D -m755 postgresql.initd \
"$pkgdir"/etc/init.d/postgresql || return 1
- install -D -m644 "$srcdir"/postgresql.confd \
- "$pkgdir"/etc/conf.d/postgresql || return 1
+ install -D -m644 postgresql.confd \
+ "$pkgdir"/etc/conf.d/postgresql || return 1
+
install -D -m755 "$srcdir"/pg-restore.initd \
"$pkgdir"/etc/init.d/pg-restore || return 1
install -D -m644 "$srcdir"/pg-restore.confd \
@@ -243,8 +240,8 @@ _submv() {
sha512sums="7c9d61a591408e29d7dc70d6b28ecdf06edf7f8fbf4e014e60a1e4f841fd5734c74a820094f6153e10ef633d48ea73f2a85194f6d2cd519a8f7087a261e9e02b postgresql-9.6.2.tar.bz2
0b88eee78380ed6cf543c851ac1cea5fc50bb6ef1bb51e03694003f43d2bf4e117ff06657f958d0e9c00ace3b8a6bab6ed0bd017d23f80cfd203dab33da81d46 initdb.patch
5f9d8bb4957194069d01af8ab3abc6d4d83a7e7f8bd7ebe1caae5361d621a3e58f91b14b952958138a794e0a80bc154fbb7e3e78d211e2a95b9b7901335de854 perl-rpath.patch
-af37b100cc67769817e4c9e997abecf50475d7f0bf9b0f1d51bf8454d45abd6c87d5d315ed6cafd14e0dd059e96723a6203b756236070d12968816666e63e522 postgresql.initd
-5b2fe18e38b5bef6fc289ff7701148dd5608d98002db046b183d715b718f96e22c01ba0adc5b590c386694c3eefae1a0a30425b985965ed2238e3858923b91ec postgresql.confd
+73807f0d6ddc239c0fc2308164cf3e6ef361f98553ec24408afc4aeb1db9aea24746caf57e2cd1405eddaac4f26e9a55bf5aa1abcf08cd9ce3e9818754d4746a postgresql.initd
+34912a2f9c5f660055cdf182f023981bf23f1995c2ba7b1172007dd90df9684952964ce574cfd86d6854bd6d057fd9dda67d6055dd765a65d03c1eaf5b33d22e postgresql.confd
f5a1cba051e7d846c2d16703514601cb25729ed96b677c9bd0c199d64552120a8b14b238af01917fdb87106681e12dee6fff7447558155ba273e4f96be5e2892 pg-restore.initd
c14a5684e914abb3b0ee71bbf15eed71a9264deacaa404a6e3af6bfc330d93e7598624d0ed11a94263106cc660f7f54c8ff57e759033cf606a795f69ff6c1c7c pg-restore.confd
5c9bfd9e295dcf678298bf0aa974347a7c311d6e7c2aa76a6920fcb751d01fd1ab77abbec11f3c672f927ad9deaa88e04e370c0b5cd1b60087554c474b748731 pltcl_create_tables.sql"
diff --git a/main/postgresql/postgresql.confd b/main/postgresql/postgresql.confd
index 3e59532224..b5b57329a9 100644
--- a/main/postgresql/postgresql.confd
+++ b/main/postgresql/postgresql.confd
@@ -1,55 +1,53 @@
-# 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
+# Which port and socket to bind PostgreSQL.
+# This may be overriden in postgresql.conf.
+#port="5432"
+
+# How long to wait for server to start in seconds.
+#start_timeout=10
+
+# Number of seconds to wait for clients to disconnect from the server before
+# shutting down. Set to zero to disable this timeout.
+#nice_timeout=60
+
+# Timeout in seconds for rude quit - forecfully disconnect clients from server
+# and shut down. This is performed after nice_timeout exceeded. Terminated
+# client connections have their open transactions rolled back.
+# Set "rude_quit=no" to disable.
+#rude_quit="yes"
+#rude_timeout=30
+
+# Timeout in seconds for force quit - if the server still fails to shutdown,
+# you can force it to quit and a recover-run will execute on the next startup.
+# Set "force_quit=yes" to enable.
+#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.
-#PGOPTS="-N 512 -B 1024"
+# -N is the maximal number of client connections
+# -B is the number of shared buffers (has to be at least 2x the value for -N)
+# Please read man postgres(1) for more options. Many of these options can be
+# set directly in the configuration file.
+#pg_opts="-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\""
+#env_vars="PGPASSFILE=\"/path/to/.pgpass\""
+
+# Automatically set up a new database if missing on startup.
+#auto_setup="yes"
+
##############################################################################
#
-# The following values should not be arbitrarily changed.
+# 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.
-#
-##############################################################################
# PostgreSQL's Database Directory
-PGDATA="/var/lib/postgresql/9.6/data"
+#PGDATA="/var/lib/postgresql/@VERSION@/data"
# Additional options to pass to initdb.
-# See `man initdb' for available options.
-#PG_INITDB_OPTS="--locale=en_US.UTF-8"
-
-# Automatically set up a new database if missing on startup
-AUTO_SETUP=yes
-
+# See man initdb(1) for available options.
+#initdb_opts="--locale=en_US.UTF-8"
diff --git a/main/postgresql/postgresql.initd b/main/postgresql/postgresql.initd
index b89fe9c78d..63b4f0c522 100644
--- a/main/postgresql/postgresql.initd
+++ b/main/postgresql/postgresql.initd
@@ -1,152 +1,205 @@
#!/sbin/openrc-run
-# Copyright 1999-2008 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.3,v 1.4 2008/09/28 22:53:02 caleb Exp $
-# Modifications to support Alpine Linux pg-restore
extra_started_commands="reload"
+description_reload="Reload configuration"
+
extra_stopped_commands="setup"
+description_setup="Initialize a new PostgreSQL cluster"
+
+# Note: Uppercase variables are here for backward compatibility.
+
+: ${user:=${PGUSER:-"postgres"}}
+: ${group:=${PGGROUP:-"postgres"}}
+
+: ${auto_setup:=${AUTO_SETUP:-"yes"}}
+: ${start_timeout:=${START_TIMEOUT:-10}}
+: ${nice_timeout:=${NICE_TIMEOUT:-60}}
+: ${rude_quit:=${RUDE_QUIT:-"yes"}}
+: ${rude_timeout:=${RUDE_TIMEOUT:-30}}
+: ${force_quit:=${FORCE_QUIT:-"no"}}
+: ${force_timeout:=${FORCE_TIMEOUT:-2}}
+
+: ${env_vars:=${PG_EXTRA_ENV:-}}
+: ${initdb_opts:=${PG_INITDB_OPTS:-}}
+: ${logfile:="$PGDATA/postmaster.log"}
+: ${pg_opts:=${PGOPTS:-}}
+: ${port:=${PGPORT:-5432}}
+: ${PGDATA:="/var/lib/postgresql/@VERSION@/data"}
+
+command="/usr/bin/postgres"
+
+conffile="$PGDATA/postgresql.conf"
+pidfile="$PGDATA/postmaster.pid"
+start_stop_daemon_args="
+ --user $user
+ --group $group
+ --pidfile $pidfile
+ --wait 100"
depend() {
use net
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) }')
+ if [ "$(get_config log_destination)" = "syslog" ]; then
+ use logger
+ fi
}
-
-checkconfig() {
- configured_port=$(get_config port)
- : ${configured_port:=${PGPORT:-5432}}
- socket_path=$(get_config unix_socket_directories)
- : ${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
+start_pre() {
+ check_deprecated_var WAIT_FOR_START start_timeout
+ check_deprecated_var WAIT_FOR_DISCONNECT nice_timeout
+ check_deprecated_var WAIT_FOR_CLEANUP rude_timeout
+ check_deprecated_var WAIT_FOR_QUIT force_timeout
+
+ if [ ! -d "$PGDATA/base" ]; then
+ if yesno "$auto_setup"; then
+ setup || return 1
+ else
+ eerror "Database not found at: $PGDATA"
+ eerror "Please make sure that PGDATA points to the right path."
+ eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster."
+ return 1
+ fi
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."
- eerror "You can run '/etc/init.d/postgresql setup' to setup a new database cluster."
- return 1
- fi
- setup
+ local socket_dirs=$(get_config "unix_socket_directories" "/run/postgresql")
+ local port=$(get_config "port" "$port")
+
+ start_stop_daemon_args="$start_stop_daemon_args --env PGPORT=$port"
+
+ (
+ # Set the proper permission for the socket paths and create them if
+ # then don't exist.
+ set -f; IFS=","
+ for dir in $socket_dirs; do
+ if [ -e "${dir%/}/.s.PGSQL.$port" ]; then
+ eerror "Socket conflict. A server is already listening on:"
+ eerror " ${dir%/}/.s.PGSQL.$port"
+ eerror "Hint: Change 'port' to listen on a different socket."
+ return 1
+ elif [ "${dir%/}" != "/tmp" ]; then
+ checkpath -d -m 1775 -o $user:$group "$dir"
+ fi
+ done
+ )
}
start() {
- checkconfig || return 1
+ local retval
ebegin "Starting PostgreSQL"
- if [ -f "$PGDATA/postmaster.pid" ] ; then
- rm -f "$PGDATA/postmaster.pid"
- fi
-
- local retval= x= extraenv=
- for x in ${PG_EXTRA_ENV} ; do
- extraenv="${extraenv} --env ${x}"
+ local var; for var in $env_vars; do
+ start_stop_daemon_args="$start_stop_daemon_args --env $var"
done
+ rm -f "$pidfile"
start-stop-daemon --start \
- --user ${PGUSER:-postgres} \
- --group ${PGGROUP:-postgres} \
- --env "PGPORT=${configured_port}" \
- ${extraenv} \
- --pidfile ${PGDATA}/postmaster.pid \
- --wait 100 \
+ $start_stop_daemon_args \
--exec /usr/bin/pg_ctl \
- -- \
- start -s -w -t ${START_TIMEOUT:-10} \
- -l ${PGDATA}/postmaster.log \
- -D ${PGDATA} -o "$PGOPTS"
+ -- start \
+ --silent \
+ -w --timeout="$start_timeout" \
+ --log="$logfile" \
+ --pgdata="$PGDATA" \
+ -o "$pg_opts"
retval=$?
- if [ $retval -ne 0 ] ; then
- eerror "Check the log for a possible explanation of the above error."
- eerror " ${PGDATA}/postmaster.log"
+ if [ $retval -ne 0 ]; then
+ eerror "Check the log for a possible explanation of the above error:"
+ eerror " $logfile"
fi
eend $retval
}
stop() {
- 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 retry="SIGTERM/$nice_timeout"
- local seconds=${NICE_TIMEOUT}
- local 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
+ yesno "$rude_quit" \
+ && retry="$retry/SIGINT/$rude_timeout" \
+ || rude_timeout=0
- ebegin "Stopping PostgreSQL (this can take up to ${seconds} seconds)"
+ yesno "$force_quit" \
+ && retry="$retry/SIGQUIT/$force_timeout" \
+ || force_timeout=0
+
+ local seconds=$(( $nice_timeout + $rude_timeout + $force_timeout ))
+
+ ebegin "Stopping PostgreSQL (this can take up to $seconds seconds)"
- # Loops through nice, rude, and force quit in one go.
start-stop-daemon --stop \
- --exec /usr/bin/postgres \
- --retry ${retries} \
+ --exec "$command" \
+ --retry "$retry" \
--progress \
- --pidfile ${PGDATA}/postmaster.pid
- eend
+ --pidfile "$pidfile"
+ eend $?
}
reload() {
ebegin "Reloading PostgreSQL configuration"
- kill -HUP $(head -n1 ${PGDATA}/postmaster.pid)
+
+ start-stop-daemon --signal HUP --pidfile "$pidfile"
eend $?
}
-setup() {
- ebegin "Creating a new PostgreSQL database cluster"
-
- if [ -d "${PGDATA}/base" ] ; then
- eend 1 "${PGDATA}/base already exists"
- return
- fi
-
- mkdir -p "${PGDATA}" 2>/dev/null
-
- # If the pg_hba.conf and friends exist, move them
- local tmpdir="$( dirname "$PGDATA" )/tmp"
- mkdir -p "${tmpdir}" >/dev/null
- echo mv "${PGDATA}"/* "${tmpdir}"
- mv "${PGDATA}"/* "${tmpdir}" 2>/dev/null
-
- rm -rf "${PGDATA}"/* 2>/dev/null
- chown -Rf postgres:postgres "${PGDATA}"
- chmod 0700 "${PGDATA}"
- cd "${PGDATA}" # to avoid the: could not change directory to "/root"
- su -c "/usr/bin/initdb --pgdata ${PGDATA}" postgres
- local res=$?
-
- # move the pg_hba.conf and friends
- mv $tmpdir/* "$PGDATA" 2>/dev/null
- rm -rf $tmpdir 2>/dev/null
-
- # Do not send a SIGHUP to postmaster; its not necessary for a new database
- # and allows pg-restore to do a blind restore of an old database
-
- eend $res
+setup() {
+ local bkpdir
+
+ ebegin "Creating a new PostgreSQL database cluster"
+
+ if [ -d "$PGDATA/base" ]; then
+ eend 1 "$PGDATA/base already exists!"; return 1
+ fi
+
+ # If the pg_hba.conf and friends exist, backup them.
+ if [ -d "$PGDATA" ]; then
+ bkpdir="$(mktemp -d)"
+ mv "$PGDATA"/* "$bkpdir"/
+ rm -rf "$PGDATA"/*
+ fi
+
+ install -d -m 0700 -o $user -g $group "$PGDATA"
+
+ cd "$PGDATA" # to avoid the: could not change directory to "/root"
+ su $user -c "/usr/bin/initdb $initdb_opts --pgdata $PGDATA"
+ local retval=$?
+
+ if [ -d "$bkpdir" ]; then
+ # Move the pg_hba.conf and friends back.
+ mv "$bkpdir"/* "$PGDATA"/ 2>/dev/null
+ rm -rf "$bkpdir"
+ fi
+
+ eend $retval
}
+
+get_config() {
+ local name="$1"
+ local default="${2:-}"
+
+ if [ ! -f "$conffile" ]; then
+ printf '%s\n' "$default"
+ return 1
+ fi
+ sed -En "/^\s*${name}\b/{ # find line starting with the name
+ s/^\s*${name}\s*=?\s*([^#]+).*/\1/; # capture the value
+ s/\s*$//; # trim trailing whitespaces
+ s/^['\"](.*)['\"]$/\1/; # remove delimiting quotes
+ p
+ }" "$conffile" \
+ | grep . || printf '%s\n' "$default"
+}
+
+check_deprecated_var() {
+ local old_name="$1"
+ local new_name="$2"
+
+ if [ -n "$(getval "$old_name")" ]; then
+ ewarn "Variable '$old_name' has been removed, please use '$new_name' instead."
+ fi
+}
+
+getval() {
+ eval "printf '%s\n' \"\$$1\""
+}