#!/bin/bash
################################################################################
# Copyright (c) 2013-2016 VMware, Inc. All rights reserved.
################################################################################
# One-time stop command for Postgres. This script should be run as root.

ENCODING=UTF8
THIS_DIR=`dirname $0`

if [ -z $VMWARE_POSTGRES_BASE ]; then
   echo "VMWARE_POSTGRES_BASE is not set."
   echo "Check your installation."
   exit 1
fi
SANITY_FILE=$VMWARE_POSTGRES_BASE/scripts/vpostgres_sanity_checks
if [ -f $SANITY_FILE ]; then
   source $SANITY_FILE
else
   echo "Sanity check file for environment variables of VMware Postgres"
   echo "is not available. Check your installation."
   exit 1
fi

# Launch stop command
su -s /bin/bash - $VMWARE_POSTGRES_OS_ADMIN \
   -c "${VMWARE_POSTGRES_BIN}/pg_ctl stop -D '$VMWARE_POSTGRES_DATA' -s -m fast -w -t 300"
