aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-05-02 00:56:31 +0200
committerJakub Jirutka <jakub@jirutka.cz>2017-05-02 01:01:45 +0200
commitdd85767efb1182d3d0beca780bd3b9ba9e05d57e (patch)
tree6fac9611675a932e62a06bfb91afc01d7355890f /testing
parent0ee4b1128d7f6a182bcfe95f35ee26b28f232dba (diff)
downloadaports-dd85767efb1182d3d0beca780bd3b9ba9e05d57e.tar.bz2
aports-dd85767efb1182d3d0beca780bd3b9ba9e05d57e.tar.xz
testing/pgbouncer: rewrite runscript
Diffstat (limited to 'testing')
-rw-r--r--testing/pgbouncer/APKBUILD8
-rw-r--r--testing/pgbouncer/pgbouncer-dirs.patch2
-rw-r--r--testing/pgbouncer/pgbouncer.confd25
-rw-r--r--testing/pgbouncer/pgbouncer.initd136
4 files changed, 91 insertions, 80 deletions
diff --git a/testing/pgbouncer/APKBUILD b/testing/pgbouncer/APKBUILD
index 4659e23da9..1ee881585d 100644
--- a/testing/pgbouncer/APKBUILD
+++ b/testing/pgbouncer/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=pgbouncer
pkgver=1.7.2
-pkgrel=1
+pkgrel=2
pkgdesc="A lightweight connection pooler for PostgreSQL"
url="https://wiki.postgresql.org/wiki/PgBouncer"
arch="all"
@@ -53,8 +53,8 @@ package() {
}
sha512sums="11c89606599f424b34f39a4b072ec6293fea0b14ee52ae4fbc44775e6d83771a22d194f4e8eabe410e0d6a70657508cf1a3b1012543d91873c36f644afb5675d pgbouncer-1.7.2.tar.gz
-ecd34f017316b2c0aad172e5bf5393137da5ab841f4d6de93eb82a07abe9f234a2426ca7dada2dc047c33ea4c7dc0af3040b249ec1f9d7e0c1782fb0463a7293 pgbouncer.initd
-dbcd7f5860b7f1ec6b6372b718678ba74c5268e89eed0fe291cd292a50460f0e81876367cb86e97f1cfefc0ace8d698c41a313642ec64d2de0747c348665afba pgbouncer.confd
+a6dbfa477c2f0a405e4bf9ee0037165531802366565d0f192931ccd8a7cb3edf9e9b628655e4169592e9370cc71fb73d4424bfd3f20bb5a43eb26a52251e539d pgbouncer.initd
+808621351b0f5973427fa22f63128432b00ac20fd25af437e8148dad9e55185775aba612b6ecdd58e4a6f2450b8c7838fcace288845b9b3cd0236bbe168aa574 pgbouncer.confd
5aa4226ab2d168a88a3b64deb114d3901431d2afb2571cf8ae411c989549bc465ee05104a6863cc8fce6d769d809b4ab536973280f50cb4415c6698c34e1a5b8 pgbouncer.logrotate
-6a475bf5cff10b464177af619051529ad78e802c56655500ad23130c5989721f41592387f9bf6719810eae2d876a8dd36219b87ae1fdb29304b2adc98c49ae4c pgbouncer-dirs.patch
+fdee368ce422960ebc06547765a7e5eabc59d10ae8730948be1c5f9083adcac3aa373f41fd9972d1b9ef635a062f1e021d787085a5beb5d80edf4203f284c7c4 pgbouncer-dirs.patch
97caf142578f2f9d1500979ce88244554f316f999837707137dc4c3ec6ebc45bcef16678e61fdd1118bf4e26c7df733bd399f4a82b9b5a8e44c3497ab0922524 libressl-2.5.patch"
diff --git a/testing/pgbouncer/pgbouncer-dirs.patch b/testing/pgbouncer/pgbouncer-dirs.patch
index 62bcd0b844..7945376d87 100644
--- a/testing/pgbouncer/pgbouncer-dirs.patch
+++ b/testing/pgbouncer/pgbouncer-dirs.patch
@@ -6,7 +6,7 @@ diff -Naruw a/etc/pgbouncer.ini b/etc/pgbouncer.ini
logfile = /var/log/pgbouncer/pgbouncer.log
-pidfile = /var/run/pgbouncer/pgbouncer.pid
-+pidfile = /run/pgbouncer/pgbouncer.pid
++;pidfile = # do not set!
;;;
;;; Where to wait for clients
diff --git a/testing/pgbouncer/pgbouncer.confd b/testing/pgbouncer/pgbouncer.confd
index 84961a83c9..c5408bbe31 100644
--- a/testing/pgbouncer/pgbouncer.confd
+++ b/testing/pgbouncer/pgbouncer.confd
@@ -1,12 +1,19 @@
+# Configuration file for /etc/init.d/pgbouncer
+
# Location of configuration file for PgBouncer.
-INIFILE="/etc/pgbouncer/pgbouncer.ini"
+#cfgfile="/etc/pgbouncer/pgbouncer.ini"
+
+# The user to run PgBouncer as.
+#user=pgbouncer
+
+# The group to run PgBouncer as.
+#group=postgresql
# How long to wait in seconds for a safe shutdown. Equivalent to
-# issuing 'PAUSE;' and 'SHUTDOWN;' on psql console. (See 'man 1 pgbouncer'.)
-NICE_TIMEOUT=60
-
-# Set to 'YES' to perform an immediate shutdown if the nice shutdown
-# doesn't work. Same as issuing 'SHUTDOWN;' on console. (See 'man 1
-# pgbouncer'.)
-FORCE_QUIT="no"
-FORCE_QUIT_TIMEOUT=2
+# issuing 'PAUSE;' and 'SHUTDOWN;' on psql console. See pgbouncer(1).
+#nice_timeout=60
+
+# Set to 'yes' to perform an immediate shutdown if the nice shutdown
+# doesn't work. Same as issuing 'SHUTDOWN;' on console. See pgbouncer(1).
+#force_quit=="no"
+#force_quit_timeout=2
diff --git a/testing/pgbouncer/pgbouncer.initd b/testing/pgbouncer/pgbouncer.initd
index 20479dc22d..a44f6aeeb8 100644
--- a/testing/pgbouncer/pgbouncer.initd
+++ b/testing/pgbouncer/pgbouncer.initd
@@ -2,87 +2,91 @@
extra_started_commands="reload"
-depend() {
- use net
- after postgresql
-}
+: ${user:="pgbouncer"}
+: ${group:="postgresql"}
+: ${cfgfile:="/etc/pgbouncer/pgbouncer.ini"}
+: ${nice_timeout:=60}
+: ${force_quit:="no"}
+: ${force_quit_timeout:=2}
-get_config() {
- [ -f "${INIFILE}" ] || eend 1 "'${INIFILE}' not found"
+name="PgBouncer"
+command="/usr/bin/pgbouncer"
+command_args="-q $cfgfile"
+command_background="yes"
- eval echo $(sed -e 's:;.*::' "${INIFILE}" | \
- awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
-}
+pidfile="/run/$RC_SVCNAME.pid"
+start_stop_daemon_args="
+ --user $user
+ --group $group"
-PIDFILE="$(get_config pidfile)"
-UNIX_SOCKET_DIR="$(get_config unix_socket_dir)"
-
-prep() {
- if [ -n "${UNIX_SOCKET_DIR}" ] ; then
- checkpath -o postgres:postgres -m 0775 -d "${UNIX_SOCKET_DIR}" \
- || return 1
- fi
- checkpath -o pgbouncer:postgres -m 0755 -d "$(dirname ${PIDFILE})" \
- || return 1
- checkpath -o pgbouncer:postgres -m 0644 -f "${PIDFILE}" \
- || return 1
- checkpath -o pgbouncer:postgres -m 0755 -d "$(dirname $(get_config logfile))" \
- || return 1
- checkpath -o pgbouncer:postgres -m 0640 -f "$(get_config logfile)" \
- || return 1
-
- return 0
+required_files="$cfgfile"
+
+depend() {
+ use net
+ after postgresql
}
-start() {
- ebegin "Starting PgBouncer"
- prep
- local ret=$?
- if [ $ret -ne 0 ] ; then
- eend $ret
- exit $ret
- fi
- start-stop-daemon --start \
- --pidfile ${PIDFILE} \
- --user pgbouncer \
- --exec /usr/bin/pgbouncer -- -q -d "${INIFILE}"
- eend $?
+start_pre() {
+ local socket_dir=$(get_config unix_socket_dir)
+ if [ -n "$socket_dir" ]; then
+ checkpath -d -m 0755 -o postgres:postgres "$socket_dir" || return 1
+ fi
+
+ local logfile="$(get_config logfile)"
+ if [ -n "$logfile" ]; then
+ checkpath -f -m 0640 -o $user:$group "$logfile" || return 1
+ fi
}
stop() {
- local seconds=$(( ${NICE_TIMEOUT} + ${FORCE_QUIT_TIMEOUT} ))
- ebegin "Stopping PgBouncer (this can take up to ${seconds} seconds)"
+ local retry="SIGINT/$nice_timeout"
+ yesno "$force_quit" \
+ && retry="$retry/SIGTERM/$force_quit_timeout" \
+ || force_quit_timeout=0
- local retries=SIGINT/${NICE_TIMEOUT}
+ local seconds=$(( $nice_timeout + $force_quit_timeout ))
- if [ "${FORCE_QUIT}" = "YES" ] ; then
- einfo "FORCE_QUIT enabled."
- retries="${retries}/SIGTERM/${FORCE_QUIT_TIMEOUT}"
- fi
+ ebegin "Stopping $seconds (this can take up to $seconds seconds)"
- # Loops through nice and force quit in one go.
- start-stop-daemon --stop \
- --pidfile ${PIDFILE} \
- --retry ${retries}
-
- eend $?
+ start-stop-daemon --stop \
+ --pidfile "$pidfile" \
+ --retry "$retry" \
+ --progress \
+ --exec "$command"
+ eend $?
}
restart() {
- if [ -n "${UNIX_SOCKET_DIR}" ] ; then
- ebegin "Performing online restart of PgBouncer"
- start-stop-daemon --start \
- --pidfile ${PIDFILE} \
- --user pgbouncer \
- --exec /usr/bin/pgbouncer -- -q -d -R "${INIFILE}"
- eend $?
- else
- stop && start
- fi
+ local socket_dir=$(get_config unix_socket_dir)
+
+ if [ -n "$socket_dir" ]; then
+ ebegin "Performing online restart of $name"
+ "$command" -R "$command_args"
+ eend $?
+ else
+ stop && start
+ fi
}
reload() {
- ebegin "Reloading PgBouncer configuration from '${INIFILE}'"
- start-stop-daemon --signal HUP --pidfile ${PIDFILE}
- eend $?
+ ebegin "Reloading $name configuration"
+ start-stop-daemon --signal HUP --pidfile "$pidfile"
+ eend $?
+}
+
+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"
}