diff --git a/botserver b/botserver index 4ca7e5d..c264ad1 160000 --- a/botserver +++ b/botserver @@ -1 +1 @@ -Subproject commit 4ca7e5da40a3d642bfc1af5fb65b709550c93e59 +Subproject commit c264ad1294a4b62db9ad007c5675b66f48165a30 diff --git a/restart.sh b/restart.sh new file mode 100755 index 0000000..345b964 --- /dev/null +++ b/restart.sh @@ -0,0 +1,59 @@ +#!/bin/bash +set -e + +echo "๐Ÿ›‘ Stopping existing processes..." +pkill -f "botserver --noconsole" || true +pkill -f botui || true +pkill -f rustc || true +# Note: PostgreSQL, Vault, and Valkey are managed by botserver bootstrap, don't kill them + +echo "๐Ÿงน Cleaning logs..." +rm -f botserver.log botui.log + +echo "๐Ÿ”จ Building botserver..." +cargo build -p botserver + +echo "๐Ÿ”จ Building botui..." +cargo build -p botui + +echo "๐Ÿ—„๏ธ Starting PostgreSQL..." +./botserver-stack/bin/tables/bin/postgres -D botserver-stack/data/tables/pgdata -c config_file=botserver-stack/conf/postgresql.conf > botserver-stack/logs/tables/postgres.log 2>&1 & +echo " PostgreSQL PID: $!" +sleep 2 + +echo "๐Ÿ”‘ Starting Valkey (cache)..." +./botserver-stack/bin/cache/valkey-server --daemonize no --dir botserver-stack/data/cache > /dev/null 2>&1 & +echo " Valkey started" +sleep 2 + +echo "๐Ÿš€ Starting botserver..." +export VAULT_ADDR="https://localhost:8200" +export VAULT_TOKEN="hvs.JjKHlEzycO2jvKdhhlRAoODu" +export VAULT_CACERT="./botserver-stack/conf/system/certificates/ca/ca.crt" +export VAULT_CACHE_TTL="300" +RUST_LOG=info ./target/debug/botserver --noconsole > botserver.log 2>&1 & +BOTSERVER_PID=$! + +echo "โณ Waiting for Vault to start (unsealing in background)..." +( + sleep 8 + echo "๐Ÿ”“ Unsealing Vault..." + UNSEAL_KEY=$(python3 -c "import json; print(json.load(open('botserver-stack/conf/vault/init.json'))['unseal_keys_b64'][0])" 2>/dev/null) + if [ -n "$UNSEAL_KEY" ]; then + curl -s --cacert botserver-stack/conf/system/certificates/ca/ca.crt \ + -X POST \ + -H "X-Vault-Token: hvs.JjKHlEzycO2jvKdhhlRAoODu" \ + -d "{\"key\": \"$UNSEAL_KEY\"}" \ + https://localhost:8200/v1/sys/unseal 2>/dev/null && echo "โœ… Vault unsealed" || echo "โš ๏ธ Unseal failed" + else + echo "โš ๏ธ Could not extract unseal key" + fi +) & + +echo "๐Ÿš€ Starting botui..." +BOTSERVER_URL="http://localhost:8080" ./target/debug/botui > botui.log 2>&1 & +BOTUI_PID=$! + +echo "โœ… Started botserver (PID: $BOTSERVER_PID) and botui (PID: $BOTUI_PID)" +echo "๐Ÿ“Š Monitor with: tail -f botserver.log botui.log" +echo "๐ŸŒ Access at: http://localhost:3000" diff --git a/start-and-unseal.sh b/start-and-unseal.sh new file mode 100755 index 0000000..897d5d7 --- /dev/null +++ b/start-and-unseal.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +echo "๐Ÿ”“ Unsealing Vault..." +UNSEAL_KEY="$(cat botserver-stack/conf/vault/init.json | grep -o '"unseal_keys_b64":\["[^"]*"' | cut -d'"' -f4)" + +# Wait for Vault to start +for i in {1..30}; do + if curl -sfk --cacert botserver-stack/conf/system/certificates/ca/ca.crt \ + https://localhost:8200/v1/sys/health > /dev/null 2>&1; then + echo "โœ… Vault is running" + break + fi + echo "โณ Waiting for Vault... ($i/30)" + sleep 1 +done + +# Unseal Vault +echo "๐Ÿ”“ Unsealing..." +curl -s --cacert botserver-stack/conf/system/certificates/ca/ca.crt \ + -X POST \ + -H "X-Vault-Token: hvs.JjKHlEzycO2jvKdhhlRAoODu" \ + -d "{\"key\": \"$UNSEAL_KEY\"}" \ + https://localhost:8200/v1/sys/unseal + +echo "โœ… Vault unsealed"