25 lines
732 B
Bash
25 lines
732 B
Bash
#!/bin/bash
|
|
# to run this execute
|
|
# export PSQL_HOME_DIR=/home/user/pgsql-10.5.1; bash ./deploy/run_psql.sh
|
|
PSQL_DATA_DIR=./ng-tracker
|
|
PSQL_USER_NAME=postgres
|
|
PSQL_DB_NAME=ng-tracker
|
|
if [ ! -d "$PSQL_HOME_DIR" ]; then
|
|
echo "Directory $PSQL_HOME_DIR is not exists"
|
|
exit 0
|
|
fi
|
|
cd "$PSQL_HOME_DIR"
|
|
if [ ! -d "$PSQL_DATA_DIR" ]; then
|
|
./bin/initdb "$PSQL_DATA_DIR"
|
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" start
|
|
./bin/createuser -s "$PSQL_USER_NAME"
|
|
./bin/createdb -O "$PSQL_USER_NAME" "$PSQL_DB_NAME"
|
|
else
|
|
PSQL_STATUS=$(./bin/pg_ctl -D "$PSQL_DATA_DIR" status | wc -l)
|
|
if [ $PSQL_STATUS -eq 1 ]; then
|
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" start
|
|
else
|
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" stop
|
|
fi
|
|
fi
|