Commit dd85767e authored by Jakub Jirutka's avatar Jakub Jirutka

testing/pgbouncer: rewrite runscript

parent 0ee4b112
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Maintainer: Francesco Colista <fcolista@alpinelinux.org> # Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=pgbouncer pkgname=pgbouncer
pkgver=1.7.2 pkgver=1.7.2
pkgrel=1 pkgrel=2
pkgdesc="A lightweight connection pooler for PostgreSQL" pkgdesc="A lightweight connection pooler for PostgreSQL"
url="https://wiki.postgresql.org/wiki/PgBouncer" url="https://wiki.postgresql.org/wiki/PgBouncer"
arch="all" arch="all"
...@@ -53,8 +53,8 @@ package() { ...@@ -53,8 +53,8 @@ package() {
} }
sha512sums="11c89606599f424b34f39a4b072ec6293fea0b14ee52ae4fbc44775e6d83771a22d194f4e8eabe410e0d6a70657508cf1a3b1012543d91873c36f644afb5675d pgbouncer-1.7.2.tar.gz sha512sums="11c89606599f424b34f39a4b072ec6293fea0b14ee52ae4fbc44775e6d83771a22d194f4e8eabe410e0d6a70657508cf1a3b1012543d91873c36f644afb5675d pgbouncer-1.7.2.tar.gz
ecd34f017316b2c0aad172e5bf5393137da5ab841f4d6de93eb82a07abe9f234a2426ca7dada2dc047c33ea4c7dc0af3040b249ec1f9d7e0c1782fb0463a7293 pgbouncer.initd a6dbfa477c2f0a405e4bf9ee0037165531802366565d0f192931ccd8a7cb3edf9e9b628655e4169592e9370cc71fb73d4424bfd3f20bb5a43eb26a52251e539d pgbouncer.initd
dbcd7f5860b7f1ec6b6372b718678ba74c5268e89eed0fe291cd292a50460f0e81876367cb86e97f1cfefc0ace8d698c41a313642ec64d2de0747c348665afba pgbouncer.confd 808621351b0f5973427fa22f63128432b00ac20fd25af437e8148dad9e55185775aba612b6ecdd58e4a6f2450b8c7838fcace288845b9b3cd0236bbe168aa574 pgbouncer.confd
5aa4226ab2d168a88a3b64deb114d3901431d2afb2571cf8ae411c989549bc465ee05104a6863cc8fce6d769d809b4ab536973280f50cb4415c6698c34e1a5b8 pgbouncer.logrotate 5aa4226ab2d168a88a3b64deb114d3901431d2afb2571cf8ae411c989549bc465ee05104a6863cc8fce6d769d809b4ab536973280f50cb4415c6698c34e1a5b8 pgbouncer.logrotate
6a475bf5cff10b464177af619051529ad78e802c56655500ad23130c5989721f41592387f9bf6719810eae2d876a8dd36219b87ae1fdb29304b2adc98c49ae4c pgbouncer-dirs.patch fdee368ce422960ebc06547765a7e5eabc59d10ae8730948be1c5f9083adcac3aa373f41fd9972d1b9ef635a062f1e021d787085a5beb5d80edf4203f284c7c4 pgbouncer-dirs.patch
97caf142578f2f9d1500979ce88244554f316f999837707137dc4c3ec6ebc45bcef16678e61fdd1118bf4e26c7df733bd399f4a82b9b5a8e44c3497ab0922524 libressl-2.5.patch" 97caf142578f2f9d1500979ce88244554f316f999837707137dc4c3ec6ebc45bcef16678e61fdd1118bf4e26c7df733bd399f4a82b9b5a8e44c3497ab0922524 libressl-2.5.patch"
...@@ -6,7 +6,7 @@ diff -Naruw a/etc/pgbouncer.ini b/etc/pgbouncer.ini ...@@ -6,7 +6,7 @@ diff -Naruw a/etc/pgbouncer.ini b/etc/pgbouncer.ini
logfile = /var/log/pgbouncer/pgbouncer.log logfile = /var/log/pgbouncer/pgbouncer.log
-pidfile = /var/run/pgbouncer/pgbouncer.pid -pidfile = /var/run/pgbouncer/pgbouncer.pid
+pidfile = /run/pgbouncer/pgbouncer.pid +;pidfile = # do not set!
;;; ;;;
;;; Where to wait for clients ;;; Where to wait for clients
......
# Configuration file for /etc/init.d/pgbouncer
# Location of configuration file for 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 # How long to wait in seconds for a safe shutdown. Equivalent to
# issuing 'PAUSE;' and 'SHUTDOWN;' on psql console. (See 'man 1 pgbouncer'.) # issuing 'PAUSE;' and 'SHUTDOWN;' on psql console. See pgbouncer(1).
NICE_TIMEOUT=60 #nice_timeout=60
# Set to 'YES' to perform an immediate shutdown if the nice shutdown # Set to 'yes' to perform an immediate shutdown if the nice shutdown
# doesn't work. Same as issuing 'SHUTDOWN;' on console. (See 'man 1 # doesn't work. Same as issuing 'SHUTDOWN;' on console. See pgbouncer(1).
# pgbouncer'.) #force_quit=="no"
FORCE_QUIT="no" #force_quit_timeout=2
FORCE_QUIT_TIMEOUT=2
...@@ -2,87 +2,91 @@ ...@@ -2,87 +2,91 @@
extra_started_commands="reload" extra_started_commands="reload"
depend() { : ${user:="pgbouncer"}
use net : ${group:="postgresql"}
after postgresql : ${cfgfile:="/etc/pgbouncer/pgbouncer.ini"}
} : ${nice_timeout:=60}
: ${force_quit:="no"}
: ${force_quit_timeout:=2}
get_config() { name="PgBouncer"
[ -f "${INIFILE}" ] || eend 1 "'${INIFILE}' not found" command="/usr/bin/pgbouncer"
command_args="-q $cfgfile"
command_background="yes"
eval echo $(sed -e 's:;.*::' "${INIFILE}" | \ pidfile="/run/$RC_SVCNAME.pid"
awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }') start_stop_daemon_args="
} --user $user
--group $group"
PIDFILE="$(get_config pidfile)" required_files="$cfgfile"
UNIX_SOCKET_DIR="$(get_config unix_socket_dir)"
depend() {
prep() { use net
if [ -n "${UNIX_SOCKET_DIR}" ] ; then after postgresql
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
} }
start() { start_pre() {
ebegin "Starting PgBouncer" local socket_dir=$(get_config unix_socket_dir)
prep if [ -n "$socket_dir" ]; then
local ret=$? checkpath -d -m 0755 -o postgres:postgres "$socket_dir" || return 1
if [ $ret -ne 0 ] ; then fi
eend $ret
exit $ret local logfile="$(get_config logfile)"
fi if [ -n "$logfile" ]; then
start-stop-daemon --start \ checkpath -f -m 0640 -o $user:$group "$logfile" || return 1
--pidfile ${PIDFILE} \ fi
--user pgbouncer \
--exec /usr/bin/pgbouncer -- -q -d "${INIFILE}"
eend $?
} }
stop() { stop() {
local seconds=$(( ${NICE_TIMEOUT} + ${FORCE_QUIT_TIMEOUT} )) local retry="SIGINT/$nice_timeout"
ebegin "Stopping PgBouncer (this can take up to ${seconds} seconds)" 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 ebegin "Stopping $seconds (this can take up to $seconds seconds)"
einfo "FORCE_QUIT enabled."
retries="${retries}/SIGTERM/${FORCE_QUIT_TIMEOUT}"
fi
# Loops through nice and force quit in one go. start-stop-daemon --stop \
start-stop-daemon --stop \ --pidfile "$pidfile" \
--pidfile ${PIDFILE} \ --retry "$retry" \
--retry ${retries} --progress \
--exec "$command"
eend $? eend $?
} }
restart() { restart() {
if [ -n "${UNIX_SOCKET_DIR}" ] ; then local socket_dir=$(get_config unix_socket_dir)
ebegin "Performing online restart of PgBouncer"
start-stop-daemon --start \ if [ -n "$socket_dir" ]; then
--pidfile ${PIDFILE} \ ebegin "Performing online restart of $name"
--user pgbouncer \ "$command" -R "$command_args"
--exec /usr/bin/pgbouncer -- -q -d -R "${INIFILE}" eend $?
eend $? else
else stop && start
stop && start fi
fi
} }
reload() { reload() {
ebegin "Reloading PgBouncer configuration from '${INIFILE}'" ebegin "Reloading $name configuration"
start-stop-daemon --signal HUP --pidfile ${PIDFILE} start-stop-daemon --signal HUP --pidfile "$pidfile"
eend $? 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"
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment