Skip to content

Create documentdb-setup CLI tool for one-command setup #562

Closed

Description

@guanzhousongmicrosoft

Parent Issue

Part of #561 (Make DocumentDB usable from package install)

Summary

Create a documentdb-setup bash script that automates the full DocumentDB setup in a single command. This is the core deliverable that bridges the gap between package installation and a working DocumentDB instance.

What It Does

The script performs 7 steps in sequence:

  1. Detect PostgreSQL -- auto-detects PG version and binary paths (Debian/RHEL layout)
  2. Initialize cluster -- runs initdb, creates data directory, starts PG on port 9712
  3. Configure PostgreSQL -- writes drop-in conf.d/documentdb.conf with all required GUCs, adds HBA entries for TCP localhost, sets listen_addresses
  4. Create extensions -- CREATE EXTENSION documentdb CASCADE (+ extended RUM when available)
  5. Create users -- creates documentdb PG superuser role (gateway system user) + MongoDB-compatible application user via documentdb_api.create_user()
  6. Configure gateway -- updates SetupConfiguration.json with correct ports
  7. Start gateway -- enables systemd service (or manual start without systemd)

Design Decisions

  • Always requires root -- simpler than split root/non-root flow
  • Drop-in conf.d -- reversible, does not clobber postgresql.conf
  • Merges shared_preload_libraries -- reads existing config, deduplicates
  • SQL injection prevention -- uses jq for JSON construction + psql variables with heredoc (not -c) + explicit ::documentdb_core.bson cast
  • Behavioral parity with Docker -- same GUCs as emulator entrypoint (indexBuildsScheduledOnBgWorker=false, ssl=off, extended RUM GUCs, etc.)
  • Idempotent -- safe to re-run (skips existing cluster, user, extensions)
  • --skip-pg-init -- supports existing PostgreSQL clusters
  • Port collision detection -- verifies running instance data_directory matches expected
  • Gateway readiness check -- 60s timeout, fatal on failure

CLI Interface

Usage: documentdb-setup --username <USER> --password <PASS> [OPTIONS]

Required:
  --username <USER>       MongoDB-compatible username to create
  --password <PASS>       Password for the user

Options:
  --pg-version <VER>      PostgreSQL version (auto-detected if not specified)
  --pg-port <PORT>        PostgreSQL port (default: 9712)
  --gateway-port <PORT>   Gateway listen port (default: 10260)
  --data-dir <DIR>        PostgreSQL data directory (default: /var/lib/documentdb/data)
  --skip-pg-init          Use an existing PostgreSQL cluster
  --no-enable             Don't start the gateway service
  --load-sample-data      Load built-in sample data after setup
  --pg-owner <USER>       PostgreSQL superuser (default: auto-detect)
  --verbose               Show detailed output

File

scripts/documentdb-setup.sh (~600 lines), installed to /usr/bin/documentdb-setup (755) by the gateway package.

Key Technical Details

  • psql -c does NOT perform variable interpolation -- must use heredoc/stdin for :var syntax
  • documentdb_api.create_user() takes documentdb_core.bson, not text -- requires explicit cast
  • Gateway connects via TCP as user documentdb -- needs HBA entries + PG role with LOGIN SUPERUSER
  • Debian PG config lives at /etc/postgresql/<ver>/<cluster>/, not data_directory -- detect via SHOW config_file

Activity

  1. added
    enhancement
    gateway
    on Apr 7, 2026
  2. added this to the 0.111-0 milestone on Apr 7, 2026
  3. removed
    gateway
    on Apr 29, 2026
  4. documentdb-triage-tool commented on May 30, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 30 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  5. documentdb-triage-tool commented on Jun 13, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  6. documentdb-triage-tool commented on Jun 28, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  7. documentdb-triage-tool commented on Jul 13, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 15 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  8. modified the milestones: 0.111-0, 0.117-0 on Jul 24, 2026
  9. documentdb-triage-tool commented on Aug 8, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  10. documentdb-triage-tool commented on Aug 23, 2026

    @documentdb-triage-tool

    👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.

  11. guanzhousongmicrosoft commented on Aug 31, 2026

    @guanzhousongmicrosoft
    MemberAuthor

    Fixed in v0.116-0: documentdb-setup ships in DEB/RPM packages and works end to end. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

documentdb-1.0enhancementmergedpackaging

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions