From 765c5354616244a3d4ef9e92892f8e4af9c9f0cf Mon Sep 17 00:00:00 2001 From: Lars van der Zande Date: Sat, 13 Sep 2025 23:10:07 -0500 Subject: [PATCH 1/2] add: --with-graphql & --with-indexer Signed-off-by: Lars van der Zande --- scripts/common/__globals.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common/__globals.sh b/scripts/common/__globals.sh index da9e80b5..25acecdd 100644 --- a/scripts/common/__globals.sh +++ b/scripts/common/__globals.sh @@ -2594,7 +2594,7 @@ start_sui_process() { if $SUI_BASE_NET_MOCK; then SUI_PROCESS_PID=$SUI_BASE_NET_MOCK_PID else - nohup env SUI_PROTOCOL_CONFIG_OVERRIDE_ENABLE=1 SUI_PROTOCOL_CONFIG_OVERRIDE_min_checkpoint_interval_ms=1000 RUST_LOG="error" "$SUI_BIN_DIR/sui" start --network.config "$NETWORK_CONFIG" >"$CONFIG_DATA_DIR/sui-process.log" 2>&1 & + nohup env SUI_PROTOCOL_CONFIG_OVERRIDE_ENABLE=1 SUI_PROTOCOL_CONFIG_OVERRIDE_min_checkpoint_interval_ms=1000 RUST_LOG="error" "$SUI_BIN_DIR/sui" start --with-indexer --with-graphql --network.config "$NETWORK_CONFIG" >"$CONFIG_DATA_DIR/sui-process.log" 2>&1 & fi #NEW_PID=$! From ae298fce9537be8f742bb53947bf3fb48302c421 Mon Sep 17 00:00:00 2001 From: Lars van der Zande Date: Sat, 13 Sep 2025 23:10:47 -0500 Subject: [PATCH 2/2] add: postgres install & indexer db setup Signed-off-by: Lars van der Zande --- scripts/common/sui-indexer-postgres.sh | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 scripts/common/sui-indexer-postgres.sh diff --git a/scripts/common/sui-indexer-postgres.sh b/scripts/common/sui-indexer-postgres.sh new file mode 100755 index 00000000..06c6ae36 --- /dev/null +++ b/scripts/common/sui-indexer-postgres.sh @@ -0,0 +1,75 @@ +#!/bin/bash +set -e + +# --- Configuration Variables --- +PG_USER="postgres" +PG_DB="sui_indexer" +PG_PASSWORD="postgrespw" +PG_VERSION=$(dpkg-query -W -f='${Version}\n' postgresql | cut -d'.' -f1) + +if [[ -z "$PG_VERSION" ]]; then + echo "PostgreSQL is not installed or version could not be determined. Proceeding with installation." +fi + +# --- Helper functions --- +# Function to execute psql commands as the postgres user +run_psql() { + sudo -u postgres psql -c "$1" +} + +# --- 1. Install PostgreSQL (if not already installed) --- +if ! command -v psql &> /dev/null +then + echo "Installing PostgreSQL..." + sudo apt update + sudo apt install -y postgresql postgresql-contrib + echo "PostgreSQL installation complete." +else + echo "PostgreSQL is already installed." +fi + +# Get the major version of PostgreSQL +PG_VERSION=$(dpkg-query -W -f='${Version}\n' postgresql | cut -d'.' -f1) + +# Ensure the service is running +echo "Checking PostgreSQL service status..." +if ! systemctl is-active --quiet postgresql; then + echo "PostgreSQL service is not running. Starting it now..." + sudo systemctl start postgresql + sudo systemctl enable postgresql + sleep 5 # Give the service time to start +else + echo "PostgreSQL service is already running." +fi + +# --- 2. Setup user and password --- +echo "Setting password for user '$PG_USER'..." +run_psql "ALTER USER $PG_USER WITH ENCRYPTED PASSWORD '$PG_PASSWORD';" + +# --- 3. Create database if it doesn't exist --- +echo "Creating database '$PG_DB' if it doesn't exist..." +if ! run_psql "\\l" | grep -q "$PG_DB"; then + run_psql "CREATE DATABASE $PG_DB;" + echo "Database '$PG_DB' created successfully." +else + echo "Database '$PG_DB' already exists. Skipping creation." +fi + +# --- 4. Configure authentication for local connections --- +# The default `peer` authentication method on a fresh install prevents +# password-based connections. We will modify `pg_hba.conf`. +echo "Configuring pg_hba.conf for password authentication..." + +# Path to the config file depends on the version +HBA_CONF="/etc/postgresql/$PG_VERSION/main/pg_hba.conf" +if [[ -f "$HBA_CONF" ]]; then + # Replace `peer` with `md5` for local connections + sudo sed -i "s/local\s\+all\s\+all\s\+peer/local all all md5/" "$HBA_CONF" +else + echo "Warning: pg_hba.conf not found at $HBA_CONF. Manual configuration may be required." +fi + +# --- 5. Restart PostgreSQL to apply changes --- +echo "Restarting PostgreSQL service to apply configuration changes..." +sudo systemctl restart postgresql +echo "PostgreSQL setup complete. You can now connect using the provided db_url." \ No newline at end of file