-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_server.sh
More file actions
executable file
Β·158 lines (126 loc) Β· 4.22 KB
/
setup_server.sh
File metadata and controls
executable file
Β·158 lines (126 loc) Β· 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bash
# ORCA server bootstrap script
# Use this when setting up ORCA on a fresh machine for the first time.
set -e # Exit immediately if a command fails (easier debugging)
echo "============================================================"
echo "π³ ORCA setup"
echo "============================================================"
# ---- Conda ----
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate orca311
echo "Using python: $(which python)"
echo "Using pip: $(which pip)"
# ---- Python deps ----
echo "π¦ Installing Python dependencies..."
python -m pip install --upgrade pip setuptools wheel
# Install requirements (assumes requirements.txt is valid for this OS)
python -m pip install -r requirements.txt
# (Optional) Fix commonly flaky deps explicitly
python -m pip install PyYAML psycopg2-binary
# ---- Node.js / npm (REEF seed) ----
echo "π Setting up Node.js environment..."
# Check nvm
if ! command -v nvm >/dev/null 2>&1; then
echo "π¦ nvm not found. Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Load nvm into current shell
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
else
echo "β
nvm is already installed."
fi
# Install & use LTS Node
nvm install --lts
nvm use --lts
echo "Node: $(node -v)"
echo "npm: $(npm -v)"
SEED_DIR="REEF/seed_R1"
cd "$SEED_DIR" || exit 1
if [ ! -f "package.json" ]; then
echo "π¦ package.json not found. Creating and installing seed dependencies..."
npm init -y
npm install @faker-js/faker pg dotenv uuid seedrandom
elif [ -f "package-lock.json" ]; then
echo "π¦ package-lock.json found β running npm ci"
npm ci
else
echo "π¦ package.json found β running npm install"
npm install
fi
cd - >/dev/null
echo "π Starting ORCA server bootstrap..."
# ---- Step 1: env ----
echo "π Step 1: Environment variables"
if [ ! -f ".env" ]; then
echo "β οΈ .env not found. Copying env.example β .env"
cp env.example .env
echo "β οΈ Please edit .env with your local configuration before continuing:"
echo " nano .env"
echo " # or"
echo " code .env"
read -p "Press Enter to continue..."
else
echo "β
.env file exists."
fi
# ---- Step 2: Postgres init ----
echo "π Step 2: Initialize PostgreSQL database"
echo "Dropping and recreating database: reef_db"
dropdb --if-exists reef_db 2>/dev/null || true
createdb reef_db
echo "Running DDL..."
psql -d reef_db -f REEF/REEF_ddl_continuous.sql
echo "β
Database schema created."
# ---- Step 3: Seed data ----
echo "π Step 3: Generate seed data"
node REEF/seed_R1/run_all_seeds.js
echo "β
Seed data generated."
# ---- Step 4: Redis ----
echo "π Step 4: Redis check"
if redis-cli ping > /dev/null 2>&1; then
echo "β
Redis is already running (port 6379)."
else
echo "Redis is not running. Starting Redis..."
if command -v redis-stack-server > /dev/null 2>&1; then
echo "Using redis-stack-server..."
redis-stack-server --daemonize yes
elif command -v redis-server > /dev/null 2>&1; then
echo "Using redis-server..."
redis-server --daemonize yes
else
echo "β Redis server not found."
echo " Please install redis-stack-server or redis-server."
exit 1
fi
sleep 1
redis-cli ping > /dev/null 2>&1
echo "β
Redis started."
fi
# ---- Step 5: Connection tests ----
echo "π Step 5: Connection tests"
python - << 'PY'
import sys
sys.path.append(".")
from utils.settings import POSTGRES_CONFIG, REDIS_CONFIG
from utils.database import Database
import redis
print("π Testing PostgreSQL...")
db = Database(db_type="postgresql", config=POSTGRES_CONFIG)
res = db.run_query("SELECT COUNT(*) as user_count FROM users;")
print(f"β
PostgreSQL OK - users: {res[0][0]}")
print("π Testing Redis...")
r = redis.Redis(**REDIS_CONFIG)
r.ping()
print("β
Redis OK")
print("π All connection tests passed!")
PY
# ---- Metadata ----
echo "π Generating ORCA metadata..."
python -m utils.data_prep.runner
echo "β
Metadata generation completed."
echo ""
echo "π ORCA server bootstrap completed!"
echo ""
echo "Server info:"
echo "- PostgreSQL: localhost:5432/reef_db"
echo "- Redis: localhost:6379"
echo ""