aboutsummaryrefslogtreecommitdiffstats
path: root/testing/pgbouncer/pgbouncer.initd
diff options
context:
space:
mode:
authorFrancesco Colista <fcolista@alpinelinux.org>2017-02-20 11:27:11 +0000
committerFrancesco Colista <fcolista@alpinelinux.org>2017-02-20 11:27:17 +0000
commite6de48d4857379d7e1d83c13a661503dd47fda0a (patch)
tree2e11e2692633604d64034a25c3f722750e864c6e /testing/pgbouncer/pgbouncer.initd
parent57241d9646f1db85174c810c86fe40b5daa1e65f (diff)
downloadaports-e6de48d4857379d7e1d83c13a661503dd47fda0a.tar.gz
aports-e6de48d4857379d7e1d83c13a661503dd47fda0a.tar.bz2
aports-e6de48d4857379d7e1d83c13a661503dd47fda0a.tar.xz
testing/pgbouncer: new aport. Fixes #6766
Diffstat (limited to 'testing/pgbouncer/pgbouncer.initd')
-rw-r--r--testing/pgbouncer/pgbouncer.initd88
1 files changed, 88 insertions, 0 deletions
diff --git a/testing/pgbouncer/pgbouncer.initd b/testing/pgbouncer/pgbouncer.initd
new file mode 100644
index 0000000000..20479dc22d
--- /dev/null
+++ b/testing/pgbouncer/pgbouncer.initd
@@ -0,0 +1,88 @@
+#!/sbin/openrc-run
+
+extra_started_commands="reload"
+
+depend() {
+ use net
+ after postgresql
+}
+
+get_config() {
+ [ -f "${INIFILE}" ] || eend 1 "'${INIFILE}' not found"
+
+ eval echo $(sed -e 's:;.*::' "${INIFILE}" | \
+ awk '$1 == "'$1'" { print ($2 == "=" ? $3 : $2) }')
+}
+
+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
+}
+
+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 $?
+}
+
+stop() {
+ local seconds=$(( ${NICE_TIMEOUT} + ${FORCE_QUIT_TIMEOUT} ))
+ ebegin "Stopping PgBouncer (this can take up to ${seconds} seconds)"
+
+ local retries=SIGINT/${NICE_TIMEOUT}
+
+ if [ "${FORCE_QUIT}" = "YES" ] ; then
+ einfo "FORCE_QUIT enabled."
+ retries="${retries}/SIGTERM/${FORCE_QUIT_TIMEOUT}"
+ fi
+
+ # Loops through nice and force quit in one go.
+ start-stop-daemon --stop \
+ --pidfile ${PIDFILE} \
+ --retry ${retries}
+
+ 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
+}
+
+reload() {
+ ebegin "Reloading PgBouncer configuration from '${INIFILE}'"
+ start-stop-daemon --signal HUP --pidfile ${PIDFILE}
+ eend $?
+}