#Requires -Version 5.1 <# .SYNOPSIS 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.ps1. Needs release 1.1.0 or later. .EXAMPLE $env:RASTERIZEDDB_PG_PASSWORD = 'use-a-long-secret' .\setup.ps1 -RdbBin .\rasterizeddb-enterprise.exe #> [CmdletBinding()] param( [string]$RdbBin = $(if ($env:RDB_BIN) { $env:RDB_BIN } else { 'rasterizeddb-enterprise.exe' }), [string]$Data = $(if ($env:RDB_DATA) { $env:RDB_DATA } else { '.\data' }), # enterprise.conf and the tenant directory. [string]$ConfigDir = $(if ($env:RDB_CONFIG_DIR) { $env:RDB_CONFIG_DIR } else { '.\enterprise' }), [string]$Listen = $(if ($env:RDB_LISTEN) { $env:RDB_LISTEN } else { '127.0.0.1' }), [string]$CertPath = $env:RDB_TLS_CERT, [string]$KeyPath = $env:RDB_TLS_KEY ) $ErrorActionPreference = 'Stop' $cmd = Get-Command $RdbBin -ErrorAction SilentlyContinue if (-not $cmd) { throw "'$RdbBin' not found; pass -RdbBin with the enterprise server binary." } if (-not ((& $cmd.Source --help) -match '--enterprise-config')) { throw "$RdbBin is not the enterprise server (it has no --enterprise-config)." } if (-not $env:RASTERIZEDDB_PG_PASSWORD) { throw 'Set $env:RASTERIZEDDB_PG_PASSWORD for the operator role rasterized.' } New-Item -ItemType Directory -Force -Path $Data, $ConfigDir | Out-Null $Data = (Resolve-Path -LiteralPath $Data).Path $ConfigDir = (Resolve-Path -LiteralPath $ConfigDir).Path $conf = Join-Path $ConfigDir 'enterprise.conf' if (-not (Test-Path -LiteralPath $conf)) { @( '# RasterizedDB enterprise configuration, written by the enterprise-tenants setup script.', 'tenant_mode strict', 'operator_database postgres', "tenants_file $(Join-Path $ConfigDir 'tenants')", '# limit connections | statement_timeout_ms | max_bytes ', '# outbound_hosts ...' ) | Set-Content -LiteralPath $conf -Encoding ascii Write-Host "Wrote $conf" } else { Write-Host "Using $conf" } $serverArgs = @('--enterprise-config', $conf, '--location', $Data, '--protocol', 'both', '--pg-default-db', 'postgres', '--pg-auth', 'scram-sha-256', '--pg-addr', $Listen, '--rdb-addr', $Listen) if ($CertPath) { $c = (Resolve-Path -LiteralPath $CertPath).Path $k = (Resolve-Path -LiteralPath $KeyPath).Path $serverArgs += @('--pg-cert', $c, '--pg-key', $k, '--rdb-cert', $c, '--rdb-key', $k) } Write-Host "Operator: psql `"postgresql://rasterized@${Listen}:5432/postgres?sslmode=require`" -c 'SHOW TENANTS'" Write-Host 'Customers: .\create-tenant.ps1 -Tenant acme -Owner acme_admin (password from $env:RDB_TENANT_PASSWORD)' Write-Host 'Stop with Ctrl+C.' Write-Host '' & $cmd.Source @serverArgs exit $LASTEXITCODE