-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-entrypoint-postgres.sh
More file actions
48 lines (36 loc) · 1.38 KB
/
docker-entrypoint-postgres.sh
File metadata and controls
48 lines (36 loc) · 1.38 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
#!/bin/bash
set -e
# Save original stdout and redirect setup output to stderr
exec 3>&1
exec 1>&2
# Switch to postgres user for database operations
sudo() {
su postgres -c "$*"
}
# Initialize PostgreSQL if data directory is empty
if [ ! -s "$PGDATA/PG_VERSION" ]; then
echo "Initializing PostgreSQL database..."
sudo "/usr/lib/postgresql/15/bin/initdb -D $PGDATA"
# Start PostgreSQL temporarily for setup
sudo "/usr/lib/postgresql/15/bin/pg_ctl -D $PGDATA -o '-c listen_addresses=localhost' -w start"
# Create database and extensions
sudo "/usr/lib/postgresql/15/bin/psql -c \"CREATE EXTENSION IF NOT EXISTS vector;\""
# Run setup SQL if it exists
if [ -f sql/setup_database.sql ]; then
sudo "/usr/lib/postgresql/15/bin/psql -f sql/setup_database.sql"
fi
# Stop temporary PostgreSQL
sudo "/usr/lib/postgresql/15/bin/pg_ctl -D $PGDATA -m fast -w stop"
fi
# Start PostgreSQL in background
sudo "/usr/lib/postgresql/15/bin/pg_ctl -D $PGDATA -o '-c listen_addresses=localhost' -w start"
# Wait for PostgreSQL to be ready
until sudo "/usr/lib/postgresql/15/bin/pg_isready -h localhost -p 5432"; do
echo "Waiting for PostgreSQL to be ready..."
sleep 1
done
echo "PostgreSQL is ready. Starting MCP server..."
# Restore original stdout for the MCP server
exec 1>&3
# Start the MCP server
exec python3 src/postgres_memory_server.py