You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
7 years ago
|
#!/bin/sh
|
||
|
##
|
||
|
## nats-streaming-server-setup.sh -- RDBMS Setup Utility for NATS Streaming Server
|
||
|
##
|
||
|
|
||
|
# command line argument sanity check
|
||
|
prg="$0"
|
||
|
if [ $# -eq 0 ]; then
|
||
|
echo "$prg:ERROR: invalid command line" 1>&2
|
||
|
echo "$prg:USAGE: $prg install [<database-directory>]" 1>&2
|
||
|
echo "$prg:USAGE: $prg uninstall" 1>&2
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# database configuration
|
||
|
db_dir="@l_prefix@/var/nats-streaming-server/data/db"
|
||
|
db_name="nats"
|
||
|
db_user="nats"
|
||
|
db_pass="nats"
|
||
|
|
||
|
# determine RDBMS-specific details
|
||
|
db_sname=`grep "^superuser_database" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
|
||
|
sed -e 's;^ *superuser_database="\(.*\)".*;\1;'`
|
||
|
db_suser=`grep "^superuser_username" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
|
||
|
sed -e 's;^ *superuser_username="\(.*\)".*;\1;'`
|
||
|
db_spass=`grep "^superuser_password" @l_prefix@/var/postgresql/db/pg_superuser.conf |\
|
||
|
sed -e 's;^ *superuser_password="\(.*\)".*;\1;'`
|
||
|
|
||
|
# dispatch operation
|
||
|
cmd="${1:-"install"}"
|
||
|
shift
|
||
|
case "$cmd" in
|
||
|
install )
|
||
|
##
|
||
|
## create the database
|
||
|
##
|
||
|
if [ $# -gt 0 ]; then
|
||
|
db_dir="$1"
|
||
|
shift
|
||
|
fi
|
||
|
( echo "CREATE ROLE $db_user LOGIN ENCRYPTED PASSWORD '$db_pass' NOCREATEDB NOCREATEROLE;"
|
||
|
echo "CREATE TABLESPACE $db_name OWNER $db_user LOCATION '$db_dir';"
|
||
|
echo "CREATE DATABASE $db_name WITH ENCODING 'UTF8' TEMPLATE template0 OWNER $db_user TABLESPACE $db_name;"
|
||
|
echo "GRANT ALL PRIVILEGES ON DATABASE $db_name TO $db_user;"
|
||
|
) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
|
||
|
PGPASSWORD="$db_pass" @l_prefix@/bin/psql -q -U "$db_user" -d "$db_name" -f- \
|
||
|
< @l_prefix@/share/nats-streaming-server/postgresql.sql
|
||
|
;;
|
||
|
|
||
|
uninstall )
|
||
|
##
|
||
|
## remove the database
|
||
|
##
|
||
|
( echo "DROP DATABASE $db_name;"
|
||
|
echo "DROP TABLESPACE $db_name;"
|
||
|
echo "DROP ROLE $db_user;"
|
||
|
) | PGPASSWORD="$db_spass" @l_prefix@/bin/psql -q -U "$db_suser" -d "$db_sname" -f-
|
||
|
;;
|
||
|
esac
|
||
|
|