#!/usr/bin/env bash # RasterizedDB Enterprise: one server shared by many customers, each in a # database of its own (strict tenant mode). Writes the enterprise # configuration file if there is none and starts the enterprise server in the # foreground. Add customers with create-tenant.sh. # Needs release 1.1.0 or later. # # Every setting can be overridden from the environment, for example: # RDB_BIN=./rasterizeddb-enterprise RDB_LISTEN=0.0.0.0 ./setup.sh set -euo pipefail RDB_BIN="${RDB_BIN:-rasterizeddb-enterprise}" RDB_DATA="${RDB_DATA:-./data}" RDB_CONFIG_DIR="${RDB_CONFIG_DIR:-./enterprise}" # enterprise.conf and the tenant directory RDB_LISTEN="${RDB_LISTEN:-127.0.0.1}" RDB_TLS_CERT="${RDB_TLS_CERT:-}" RDB_TLS_KEY="${RDB_TLS_KEY:-}" die() { echo "error: $*" >&2; exit 1; } command -v "$RDB_BIN" >/dev/null 2>&1 || die "'$RDB_BIN' not found; set RDB_BIN to the enterprise server binary" case "$("$RDB_BIN" --help)" in *--enterprise-config*) ;; *) die "$RDB_BIN is not the enterprise server (it has no --enterprise-config)" ;; esac : "${RASTERIZEDDB_PG_PASSWORD:?set RASTERIZEDDB_PG_PASSWORD for the operator role rasterized}" export RASTERIZEDDB_PG_PASSWORD mkdir -p "$RDB_DATA" "$RDB_CONFIG_DIR" RDB_DATA="$(cd "$RDB_DATA" && pwd)" RDB_CONFIG_DIR="$(cd "$RDB_CONFIG_DIR" && pwd)" conf="$RDB_CONFIG_DIR/enterprise.conf" if [ ! -f "$conf" ]; then umask 077 cat > "$conf" < connections | statement_timeout_ms | max_bytes # outbound_hosts ... EOF echo "Wrote $conf" else echo "Using $conf" fi args=(--enterprise-config "$conf" --location "$RDB_DATA" --protocol both --pg-default-db postgres --pg-auth scram-sha-256 --pg-addr "$RDB_LISTEN" --rdb-addr "$RDB_LISTEN") if [ -n "$RDB_TLS_CERT" ]; then args+=(--pg-cert "$RDB_TLS_CERT" --pg-key "$RDB_TLS_KEY" --rdb-cert "$RDB_TLS_CERT" --rdb-key "$RDB_TLS_KEY") fi echo "Operator: psql \"postgresql://rasterized@$RDB_LISTEN:5432/postgres?sslmode=require\" -c 'SHOW TENANTS'" echo "Customers: RDB_TENANT=acme RDB_TENANT_OWNER=acme_admin RDB_TENANT_PASSWORD=… ./create-tenant.sh" echo "Stop with Ctrl+C." echo exec "$RDB_BIN" "${args[@]}"