#!/usr/bin/env bash # RasterizedDB: a server for development on this machine only. PostgreSQL on # 127.0.0.1:5432 and the native protocol on 127.0.0.1:61170, no TLS. # Runs in the foreground; Ctrl+C stops it cleanly. # # Every setting can be overridden from the environment, for example: # RDB_PG_PORT=55432 ./setup.sh set -euo pipefail RDB_BIN="${RDB_BIN:-rasterizeddb}" RDB_DATA="${RDB_DATA:-./data}" # the database directory; RDB_DATA=memory keeps everything in memory RDB_PG_PORT="${RDB_PG_PORT:-5432}" RDB_PORT="${RDB_PORT:-61170}" RDB_USER="${RDB_USER:-rasterized}" RDB_LOG_LEVEL="${RDB_LOG_LEVEL:-info}" command -v "$RDB_BIN" >/dev/null 2>&1 || { echo "error: '$RDB_BIN' not found; install it (see the install script) or set RDB_BIN to its path" >&2 exit 1 } # The first start creates the role RDB_USER with this password. Set # RASTERIZEDDB_PG_PASSWORD yourself, or one is made up and printed. if [ -z "${RASTERIZEDDB_PG_PASSWORD:-}" ]; then RASTERIZEDDB_PG_PASSWORD="dev-$(od -An -N6 -tx1 /dev/urandom | tr -d ' \n')" echo "RASTERIZEDDB_PG_PASSWORD was not set; using $RASTERIZEDDB_PG_PASSWORD" echo "(it only takes effect on a new data directory; an existing one keeps its role's password)" fi export RASTERIZEDDB_PG_PASSWORD if [ "$RDB_DATA" = memory ]; then where=(--in-memory) else mkdir -p "$RDB_DATA" RDB_DATA="$(cd "$RDB_DATA" && pwd)" where=(--location "$RDB_DATA") fi echo echo "PostgreSQL: postgresql://$RDB_USER:$RASTERIZEDDB_PG_PASSWORD@127.0.0.1:$RDB_PG_PORT/postgres?sslmode=disable" echo "Native: 127.0.0.1:$RDB_PORT (user $RDB_USER, same password)" echo "Stop with Ctrl+C." echo exec "$RDB_BIN" "${where[@]}" \ --protocol both \ --pg-addr 127.0.0.1 --pg-port "$RDB_PG_PORT" --pg-tls disable --pg-user "$RDB_USER" \ --rdb-addr 127.0.0.1 --rdb-port "$RDB_PORT" \ --log-level "$RDB_LOG_LEVEL"