~dricottone/huttese-apk

f23b7fc839c9bc4f90f0772d1543a927f066c493 — Drew DeVault 4 years ago 278a8e4
pgbouncer: import from aports
A sr.ht/pgbouncer/APKBUILD => sr.ht/pgbouncer/APKBUILD +54 -0
@@ 0,0 1,54 @@
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=pgbouncer
pkgver=1.14.0
pkgrel=1
pkgdesc="A lightweight connection pooler for PostgreSQL"
url="https://wiki.postgresql.org/wiki/PgBouncer"
arch="all"
license="BSD"
pkgusers="pgbouncer"
pkggroups="postgres"
install="$pkgname.pre-install"
makedepends="c-ares-dev libevent-dev openssl-dev udns-dev"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://pgbouncer.github.io/downloads/files/$pkgver/$pkgname-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate
	pgbouncer-dirs.patch
	"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	./configure \
		--prefix=/usr \
		--disable-debug
	make
}

check() {
	cd "$builddir"
	./pgbouncer --version
	make -C test
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"
	install -m 755 -D "$srcdir"/$pkgname.initd ./etc/init.d/$pkgname
	install -m 644 -D "$srcdir"/$pkgname.confd ./etc/conf.d/$pkgname
	install -m 644 -D "$srcdir"/$pkgname.logrotate ./etc/logrotate.d/$pkgname
	install -m 644 -D "$builddir"/etc/$pkgname.ini ./etc/$pkgname/$pkgname.ini

	install -d -m 755 -o $pkgusers -g $pkggroups ./var/log/$pkgname
}

sha512sums="506810c9896a45d67fbc97c3027572278b3857635c222cfaa53b4f3893069cfbee2ec92facd6f387de217bb3170045410b88a7cea09a45686661a2d2ccc85271  pgbouncer-1.14.0.tar.gz
c3b9766eab63e9bf7b21fff7859e094d71530f7e235668f416e81f988cce229835659ea78c22a44859ab116d6fe57c45f4df8acba475ef50835b3bbe3c154a19  pgbouncer.initd
808621351b0f5973427fa22f63128432b00ac20fd25af437e8148dad9e55185775aba612b6ecdd58e4a6f2450b8c7838fcace288845b9b3cd0236bbe168aa574  pgbouncer.confd
83b869466b59c1b1d6e316a9368f725181128c1f5a7af230e3fa9c58ccda1bc097db182806c1c51a5121692791ec83d9eb0f5718fb3031f521bb537001153e2d  pgbouncer.logrotate
f45170465fda5190257e3f4c10e22fe7df57657efc90bdd6a3f0727375a25143e07480ecd998995cec0ddb2ed2d472f996b21e4fe712681418215823b88d0fc3  pgbouncer-dirs.patch"

A sr.ht/pgbouncer/pgbouncer-dirs.patch => sr.ht/pgbouncer/pgbouncer-dirs.patch +26 -0
@@ 0,0 1,26 @@
diff --git a/etc/pgbouncer.ini b/etc/pgbouncer.ini
index fed4a9f..f5204c2 100644
--- a/etc/pgbouncer.ini
+++ b/etc/pgbouncer.ini
@@ -43,7 +43,7 @@
 ;;;
 
 logfile = /var/log/pgbouncer/pgbouncer.log
-pidfile = /var/run/pgbouncer/pgbouncer.pid
+pidfile =
 
 ;;;
 ;;; Where to wait for clients
@@ -55,9 +55,9 @@ listen_port = 6432
 
 ;; Unix socket is also used for -R.
 ;; On Debian it should be /var/run/postgresql
-;unix_socket_dir = /tmp
-;unix_socket_mode = 0777
-;unix_socket_group =
+unix_socket_dir = /run/postgresql
+unix_socket_mode = 0777
+unix_socket_group = postgres
 
 ;;;
 ;;; TLS settings for accepting clients

A sr.ht/pgbouncer/pgbouncer.confd => sr.ht/pgbouncer/pgbouncer.confd +19 -0
@@ 0,0 1,19 @@
# Configuration file for /etc/init.d/pgbouncer

# Location of configuration file for PgBouncer.
#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 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

A sr.ht/pgbouncer/pgbouncer.initd => sr.ht/pgbouncer/pgbouncer.initd +92 -0
@@ 0,0 1,92 @@
#!/sbin/openrc-run

extra_started_commands="reload"

: ${user:="pgbouncer"}
: ${group:="postgresql"}
: ${cfgfile:="/etc/pgbouncer/pgbouncer.ini"}
: ${nice_timeout:=60}
: ${force_quit:="no"}
: ${force_quit_timeout:=2}

name="PgBouncer"
command="/usr/bin/pgbouncer"
command_args="-q $cfgfile"
command_background="yes"

pidfile="/run/$RC_SVCNAME.pid"
start_stop_daemon_args="
	--user $user
	--group $group"

required_files="$cfgfile"

depend() {
	use net
	after postgresql
}

start_pre() {
	local socket_dir=$(get_config unix_socket_dir)
	if [ -n "$socket_dir" ]; then
		checkpath -d -m 0775 -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 retry="SIGINT/$nice_timeout"
	yesno "$force_quit" \
		&& retry="$retry/SIGTERM/$force_quit_timeout" \
		|| force_quit_timeout=0

	local seconds=$(( $nice_timeout + $force_quit_timeout ))

	ebegin "Stopping $seconds (this can take up to $seconds seconds)"

	start-stop-daemon --stop \
		--pidfile "$pidfile" \
		--retry "$retry" \
		--progress \
		--exec "$command"
	eend $?
}

restart() {
	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 $name configuration"
	start-stop-daemon --signal HUP --pidfile "$pidfile"
	eend $?
}

get_config() {
	local name="$1"
	local default="${2:-}"

	if [ ! -f "$cfgfile" ]; 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"
}

A sr.ht/pgbouncer/pgbouncer.logrotate => sr.ht/pgbouncer/pgbouncer.logrotate +7 -0
@@ 0,0 1,7 @@
/var/log/pgbouncer/pgbouncer.log {
	missingok
	sharedscripts
	postrotate
		/etc/init.d/pgbouncer --quiet --ifstarted reload
	endscript
}

A sr.ht/pgbouncer/pgbouncer.pre-install => sr.ht/pgbouncer/pgbouncer.pre-install +3 -0
@@ 0,0 1,3 @@
#!/bin/sh
adduser -S -D -H -h /dev/null -s /sbin/nologin -G postgres -g pgbouncer pgbouncer 2>/dev/null
exit 0