Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions libs/pgbouncer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=pgbouncer
PKG_VERSION:=1.25.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://www.pgbouncer.org/downloads/files/$(PKG_VERSION)/
PKG_HASH:=6e566ae92fe3ef7f6a1b9e26d6049f7d7ca39c40e29e7b38f6d5500ae15d8465

PKG_MAINTAINER:= Carson Wang <r03944040@g.ntu.edu.tw>
PKG_LICENSE:=ISC
PKG_LICENSE_FILES:=COPYRIGHT

PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk

define Package/pgbouncer
SECTION:=net
CATEGORY:=Network
SUBMENU:=Database
TITLE:=Lightweight connection pooler for PostgreSQL
URL:=https://www.pgbouncer.org/
DEPENDS:=+libevent2 +libc +libpthread +libopenssl +libpq +pgsql-cli +pgsql-server
endef

define Package/pgbouncer/description
PgBouncer is a lightweight connection pooler for PostgreSQL.
It can pool connections to one or more databases and serve clients
over TCP or Unix sockets.
endef

CONFIGURE_ARGS += \
--disable-debug \
--without-systemd \
--with-libevent=$(STAGING_DIR)/usr \

TARGET_CFLAGS += -std=gnu99

define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
$(TARGET_CONFIGURE_OPTS) \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)" \
pgbouncer
endef

define Build/Install
$(INSTALL_DIR) $(PKG_BUILD_DIR)/ipkg-install/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/pgbouncer $(PKG_BUILD_DIR)/ipkg-install/usr/bin/
Comment on lines +51 to +52
endef

define Package/pgbouncer/conffiles
/etc/pgbouncer/pgbouncer.ini
/etc/pgbouncer/userlist.txt
endef

define Package/pgbouncer/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/pgbouncer $(1)/usr/bin/
Comment on lines +60 to +62

$(INSTALL_DIR) $(1)/etc/pgbouncer
$(INSTALL_CONF) ./files/pgbouncer.ini $(1)/etc/pgbouncer/
$(INSTALL_CONF) ./files/userlist.txt $(1)/etc/pgbouncer/

$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/pgbouncer.init $(1)/etc/init.d/pgbouncer
endef

$(eval $(call BuildPackage,pgbouncer))
49 changes: 49 additions & 0 deletions libs/pgbouncer/files/pgbouncer.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
; Please refer to https://www.pgbouncer.org/config.html
[databases]
; database_name = host=localhost port=5432 dbname=database_name
* = host=127.0.0.1 port=5432

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 6432

; Unix socket (Optional)
;unix_socket_dir = /var/run/pgbouncer

auth_type = scram-sha-256
auth_file = /etc/pgbouncer/userlist.txt
auth_user = pgbouncer_auth
Comment on lines +13 to +15

admin_users = pgbouncer_admin
stats_users = pgbouncer_admin

pool_mode = transaction
max_client_conn = 100
default_pool_size = 20
min_pool_size = 5
reserve_pool_size = 5
reserve_pool_timeout = 5

logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid

max_db_connections = 50
max_user_connections = 50

server_lifetime = 3600
server_idle_timeout = 600
query_timeout = 0
query_wait_timeout = 120
client_idle_timeout = 0

server_reset_query = DISCARD ALL
server_check_delay = 30
server_check_query = select 1

; DNS setting
dns_max_ttl = 15
dns_zone_check_period = 0

; TLS (if need be)
;client_tls_sslmode = disable
;server_tls_sslmode = disable
79 changes: 79 additions & 0 deletions libs/pgbouncer/files/pgbouncer.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh /etc/rc.common

START=95
STOP=10

USE_PROCD=1
PROG=/usr/bin/pgbouncer
CONFIGFILE=/etc/pgbouncer/pgbouncer.ini
PGBOUNCER_USER=pgbouncer
PGBOUNCER_GROUP=pgbouncer

boot() {
setup_user
start "$@"
}

setup_user() {
if ! grep -q "^${PGBOUNCER_GROUP}:" /etc/group; then
echo "${PGBOUNCER_GROUP}:x:888:" >> /etc/group
fi

if ! grep -q "^${PGBOUNCER_USER}:" /etc/passwd; then
echo "${PGBOUNCER_USER}:x:888:888:PgBouncer:/var/lib/pgbouncer:/bin/false" >> /etc/passwd
fi
Comment on lines +17 to +24

mkdir -p /var/log/pgbouncer
mkdir -p /var/run/pgbouncer
mkdir -p /var/lib/pgbouncer

chown -R ${PGBOUNCER_USER}:${PGBOUNCER_GROUP} /var/log/pgbouncer
chown -R ${PGBOUNCER_USER}:${PGBOUNCER_GROUP} /var/run/pgbouncer
chown -R ${PGBOUNCER_USER}:${PGBOUNCER_GROUP} /var/lib/pgbouncer
chown -R ${PGBOUNCER_USER}:${PGBOUNCER_GROUP} /etc/pgbouncer

chmod 755 /var/log/pgbouncer
chmod 755 /var/run/pgbouncer
chmod 755 /var/lib/pgbouncer
chmod 755 /etc/pgbouncer
chmod 644 /etc/pgbouncer/pgbouncer.ini
Comment on lines +35 to +39
Comment on lines +35 to +39
chmod 600 /etc/pgbouncer/userlist.txt
}

start_service() {
setup_user

if [ -f /var/run/pgbouncer/pgbouncer.pid ]; then
local pid=$(cat /var/run/pgbouncer/pgbouncer.pid 2>/dev/null)
if [ -n "$pid" ] && ! kill -0 $pid 2>/dev/null; then
rm -f /var/run/pgbouncer/pgbouncer.pid
fi
fi

procd_open_instance
procd_set_param command $PROG $CONFIGFILE
procd_set_param user ${PGBOUNCER_USER}
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}

stop_service() {
if [ -f /var/run/pgbouncer/pgbouncer.pid ]; then
kill $(cat /var/run/pgbouncer/pgbouncer.pid) 2>/dev/null
rm -f /var/run/pgbouncer/pgbouncer.pid
fi
}

reload_service() {
if [ -f /var/run/pgbouncer/pgbouncer.pid ]; then
kill -HUP $(cat /var/run/pgbouncer/pgbouncer.pid)
else
start
fi
}

service_triggers() {
procd_add_reload_trigger "pgbouncer"
}
9 changes: 9 additions & 0 deletions libs/pgbouncer/files/userlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; PgBouncer User list
; Format: "username" "password_hash"
;
; Generate password hash:
; echo -n "passwordusername" | md5sum
; add "md5" before password string
;
; Example:
; "myuser" "md5d8578edf8458ce06fbc5bb76a58c5ca4"
Loading