From 5715de7283353d9708800f306bde8e8a37112bd94770854922251544222bdaa4 Mon Sep 17 00:00:00 2001 From: Reinhard Max Date: Fri, 22 Sep 2017 13:04:23 +0000 Subject: [PATCH] add postgresql-script OBS-URL: https://build.opensuse.org/package/show/server:database:postgresql/postgresql?expand=0&rev=86 --- postgresql-script | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 postgresql-script diff --git a/postgresql-script b/postgresql-script new file mode 100644 index 0000000..9eac0db --- /dev/null +++ b/postgresql-script @@ -0,0 +1,72 @@ +#!/bin/sh + +PG_SYSCONFIG=/etc/sysconfig/postgresql +test -f $PG_SYSCONFIG && . $PG_SYSCONFIG + +eval DATADIR=${POSTGRES_DATADIR:-~postgres/data} +OPTIONS=${POSTGRES_OPTIONS} +PIDFILE=$DATADIR/postmaster.pid + +# +if test -r $DATADIR/PG_VERSION ; then + DATA_VERSION=$(cat $DATADIR/PG_VERSION) + POSTGRES=/usr/lib/postgresql${DATA_VERSION/./}/bin/postgres +fi +if test -x /usr/bin/postgres; then + ACTIVE=$(readlink -q -f /usr/bin/postgres) + test -z "$POSTGRES" && POSTGRES="$ACTIVE" +fi +if test -n "$DATA_VERSION"; then + if test -z "$ACTIVE" -o "$ACTIVE" != "$POSTGRES"; then + echo " Your database files were created by PostgreSQL version $DATA_VERSION." + if test -x "$POSTGRES"; then + echo " Using the executables in $(dirname $POSTGRES)." + else + echo " Could not find executables for this version." + echo " Please install the PostgreSQL server package for version $DATA_VERSION." + fi + fi +elif test -z "$ACTIVE"; then + echo " Cannot find an active PostgreSQL server binary. Please install one of the PostgreSQL" + echo " server packages or activate an already installed version using update-alternatives." +fi +if test ! -x "$POSTGRES"; then + exit 1 +fi +BINDIR=$(dirname $POSTGRES) +VERSION=$($POSTGRES --version|awk '{print $NF}') +pg_ctl () { + $BINDIR/pg_ctl -s -D $DATADIR ${POSTGRES_TIMEOUT:+-t $POSTGRES_TIMEOUT} "$@" +} + +cd ~ +case "$1" in + start) + if [ ! -f $DATADIR/PG_VERSION ]; then + LANG_SYSCONFIG=/etc/sysconfig/language + test -f "$LANG_SYSCONFIG" && . $LANG_SYSCONFIG + LANG=${POSTGRES_LANG:-$RC_LANG} + V=$(printf "%02d%02d" $(echo $VERSION|awk -F. '{print $1, $2}')) + install -d -m 700 ${DATADIR} && + echo "Initializing PostgreSQL $VERSION at location ${DATADIR}" + /usr/bin/initdb --locale=$LANG --auth=ident $DATADIR &> initlog || { + echo "Initialisation failed. See $PWD/initlog ." + exit 1 + } + fi + pg_ctl start -w ${OPTIONS:+-o "$OPTIONS"} + ;; + + stop) + pg_ctl stop -m fast + ;; + + reload) + pg_ctl reload + ;; + + *) + echo "Usage: $0 {start|stop|reload}" + exit 1 + ;; +esac