diff --git a/docs/deployment/SETUP.md b/docs/deployment/SETUP.md index 09d13e21..c5819da2 100644 --- a/docs/deployment/SETUP.md +++ b/docs/deployment/SETUP.md @@ -40,12 +40,19 @@ sudo ./setup.sh - `/etc/aitbc/` - Configuration files - Sets proper permissions and ownership -5. **Systemd Services** +5. **PostgreSQL Databases** + - Installs PostgreSQL if not present + - Creates databases: aitbc_coordinator, aitbc_exchange, aitbc_wallet, aitbc_marketplace, aitbc_governance, aitbc_trading, aitbc_gpu, aitbc_ai, aitbc_mempool + - Creates dedicated users for each database + - Grants necessary privileges + - Uses centralized script: `/opt/aitbc/infra/scripts/setup_postgresql_databases.sh` + +6. **Systemd Services** - Installs service files to `/etc/systemd/system/` - Enables auto-start on boot - Provides fallback manual startup -6. **Service Management** +7. **Service Management** - Creates `/opt/aitbc/start-services.sh` for manual control - Creates `/opt/aitbc/health-check.sh` for monitoring - Sets up logging to `/var/log/aitbc-*.log` diff --git a/infra/scripts/setup_postgresql_databases.sh b/infra/scripts/setup_postgresql_databases.sh index a2ac444f..20031aed 100755 --- a/infra/scripts/setup_postgresql_databases.sh +++ b/infra/scripts/setup_postgresql_databases.sh @@ -86,6 +86,7 @@ setup_database "aitbc_governance" "aitbc_governance" setup_database "aitbc_trading" "aitbc_trading" setup_database "aitbc_gpu" "aitbc_gpu" setup_database "aitbc_ai" "aitbc_ai" +setup_database "aitbc_mempool" "aitbc_mempool" echo "" echo -e "${BLUE}=== Database Summary ===${NC}" @@ -103,6 +104,7 @@ echo " - aitbc_governance (user: aitbc_governance)" echo " - aitbc_trading (user: aitbc_trading)" echo " - aitbc_gpu (user: aitbc_gpu)" echo " - aitbc_ai (user: aitbc_ai)" +echo " - aitbc_mempool (user: aitbc_mempool)" echo "" echo "To configure PostgreSQL for remote connections, run:" echo " $0 --remote-configure [network-cidr]" diff --git a/scripts/deployment/provision_node.sh b/scripts/deployment/provision_node.sh index 5c5521e9..d5991a63 100755 --- a/scripts/deployment/provision_node.sh +++ b/scripts/deployment/provision_node.sh @@ -10,7 +10,7 @@ fi echo "Provisioning node: $NODE_NAME" # Install dependencies -apt update && apt install -y python3 python3-venv redis-server +apt update && apt install -y python3 python3-venv redis-server postgresql postgresql-contrib # Setup directories mkdir -p /var/lib/aitbc/{data,keystore} @@ -25,6 +25,12 @@ scp aitbc1:/opt/aitbc/aitbc-cli-final /opt/aitbc/ cd /opt/aitbc git pull origin main +# Install psycopg for PostgreSQL +/opt/aitbc/venv/bin/pip install psycopg + +# Setup PostgreSQL databases +/opt/aitbc/infra/scripts/setup_postgresql_databases.sh + # Setup as follower sed -i 's|enable_block_production=true|enable_block_production=false|g' /etc/aitbc/blockchain.env sed -i 's|proposer_id=.*|proposer_id=follower-node-'$NODE_NAME'|g' /etc/aitbc/blockchain.env diff --git a/scripts/setup.sh b/scripts/setup.sh index fcb70274..e77c6922 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -183,6 +183,7 @@ setup_postgresql_databases() { "aitbc_trading:aitbc_trading" "aitbc_gpu:aitbc_gpu" "aitbc_ai:aitbc_ai" + "aitbc_mempool:aitbc_mempool" ) for db_user in "${databases[@]}"; do diff --git a/scripts/workflow/02_genesis_authority_setup.sh b/scripts/workflow/02_genesis_authority_setup.sh index d12941ea..b2215ade 100755 --- a/scripts/workflow/02_genesis_authority_setup.sh +++ b/scripts/workflow/02_genesis_authority_setup.sh @@ -16,7 +16,11 @@ git pull origin main # Install/update dependencies echo "2. Installing/updating dependencies..." -/opt/aitbc/venv/bin/pip install -r requirements.txt +/opt/aitbc/venv/bin/pip install -r requirements.txt psycopg + +# Setup PostgreSQL databases +echo "2.5. Setting up PostgreSQL databases..." +/opt/aitbc/infra/scripts/setup_postgresql_databases.sh # Check and create required directories if they don't exist echo "3. Creating required directories..." diff --git a/scripts/workflow/03_follower_node_setup.sh b/scripts/workflow/03_follower_node_setup.sh index 65617508..64e60e5b 100755 --- a/scripts/workflow/03_follower_node_setup.sh +++ b/scripts/workflow/03_follower_node_setup.sh @@ -13,7 +13,11 @@ git pull origin main # Install/update dependencies echo "2. Installing/updating dependencies..." -/opt/aitbc/venv/bin/pip install -r requirements.txt +/opt/aitbc/venv/bin/pip install -r requirements.txt psycopg + +# Setup PostgreSQL databases +echo "2.5. Setting up PostgreSQL databases..." +/opt/aitbc/infra/scripts/setup_postgresql_databases.sh # Check and create required directories if they don't exist echo "3. Creating required directories..."