#!/bin/sh
#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright The DBT-2 Authors
#

if [ -z "${DBT2PGDATA}" ]; then
	echo "DBT2PGDATA not defined."
	exit 1
fi

if [ ! -d "${DBT2PGDATA}" ]; then
	echo "Postgres instance does not exist at $DBT2PGDATA, run dbt2-build-db"
	exit 1
fi

# We only need to stop the database if it's running.
if [ -f "${DBT2PGDATA}/postmaster.pid" ]; then
	# shellcheck disable=SC2086 # optional extra pg_ctl stop arguments
	pg_ctl -D "${DBT2PGDATA}" -w stop ${1}
fi
