Newer
Older
# This file contains common functionality for all postgresql server
# package init.d scripts. It is usually included by
# /etc/init.d/postgresqlX.Y.
# Get $CONFIGDIR, $PGDATA, and $PGCTL paths, and $PG_VERSION from given version
# ($1) and cluster name ($2) and check that the cluster data exists.
prepare_cluster() {
CONFIGDIR="/etc/postgresql/$1/$2"
PGDATA="$CONFIGDIR/pgdata"
if [ ! -d "$PGDATA" ]; then
echo "Error: symbolic link $PGDATA to data directory does not exist, exiting" >&2
exit 1
fi
if [ ! -f "$PGDATA/PG_VERSION" ]; then
echo "Error: $PGDATA does not seem to contain a PostgreSQL cluster (PG_VERSION is missing)" >&2
exit 1
fi
PG_VERSION=$(< "$PGDATA/PG_VERSION")
if [ "$1" != "$PG_VERSION" ]; then
echo "Error: $PGDATA/PG_VERSION is $PG_VERSION, but configuration directory is for version $1)" >&2
exit 1
fi
PG_CTL="/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl"
# do command/function $1 to all clusters of version $2 with command
# description $3; output according to Debian Policy for init scripts
do_op_all() {
[ "$1" ] || { echo "Error: invalid command '$1'" >&2; exit 1; }
[ "$2" ] || { echo "Error: invalid version '$2'" >&2; exit 1; }
[ -d "/etc/postgresql/$2" ] || return
[ -z "$3" ] || echo -n "$3 PostgreSQL $2 database server:"
for c in /etc/postgresql/"$2"/*; do
echo -n " "$(basename "$c")
ERRMSG=$($1 "$2" "$(basename "$c")" 2>&1) || {
echo "(FAILED)"
[ -z "$ERRMSG" ] || echo "ERROR: $ERRMSG" >&2
exit 1
}
done
[ -z "$3" ] || echo "."
}
# start all clusters of version $1
# output according to Debian Policy for init scripts
start() {
do_op_all pg_startcluster "$1" "Starting"
}
# stop all clusters of version $1
# output according to Debian Policy for init scripts
stop() {
do_op_all pg_stopcluster "$1" "Stopping"
}
# reload all clusters of version $1
# output according to Debian Policy for init scripts
reload() {
do_op_all pg_reloadcluster "$1" "Reloading"
}
status() {
pg_lsclusters
}