-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_postgres.sh
More file actions
72 lines (61 loc) · 1.82 KB
/
start_postgres.sh
File metadata and controls
72 lines (61 loc) · 1.82 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
#!/bin/bash
# PostgreSQL Startup Script for Arrest Data Application
echo "=== PostgreSQL Startup Script ==="
echo ""
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker and try again."
exit 1
fi
echo "✅ Docker is running"
# Check if docker-compose is available
if ! command -v docker-compose &> /dev/null; then
echo "❌ docker-compose is not installed. Please install Docker Compose."
exit 1
fi
echo "✅ Docker Compose is available"
# Start PostgreSQL container
echo ""
echo "🚀 Starting PostgreSQL container..."
docker-compose up -d postgres
# Wait for PostgreSQL to be ready
echo "⏳ Waiting for PostgreSQL to be ready..."
sleep 10
# Check if PostgreSQL is running
if docker-compose ps postgres | grep -q "Up"; then
echo "✅ PostgreSQL container is running"
else
echo "❌ PostgreSQL container failed to start"
echo "Check logs with: docker-compose logs postgres"
exit 1
fi
# Check if we can connect to PostgreSQL
echo "🔍 Testing PostgreSQL connection..."
if python -c "
import psycopg2
try:
conn = psycopg2.connect(
host='localhost',
port=5432,
database='arrest_data',
user='arrest_user',
password='arrest_password'
)
conn.close()
print('✅ PostgreSQL connection successful')
except Exception as e:
print(f'❌ PostgreSQL connection failed: {e}')
exit(1)
"; then
echo "✅ PostgreSQL is ready for connections"
else
echo "❌ Cannot connect to PostgreSQL"
exit 1
fi
echo ""
echo "🎉 Setup complete! You can now start your application:"
echo " python run_server.py"
echo ""
echo "📊 To view PostgreSQL logs: docker-compose logs postgres"
echo "🛑 To stop PostgreSQL: docker-compose down"
echo "🔄 To restart PostgreSQL: docker-compose restart postgres"