-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
52 lines (46 loc) · 1.07 KB
/
start.sh
File metadata and controls
52 lines (46 loc) · 1.07 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
#!/bin/bash
# Wait for database to be ready
python << END
import sys
import time
import psycopg2
from urllib.parse import urlparse
import os
# Get Database URL from environment
db_url = os.environ.get('DATABASE_URL')
if not db_url:
sys.exit(0)
# Parse URL
result = urlparse(db_url)
dbname = result.path[1:]
user = result.username
password = result.password
host = result.hostname
port = result.port
# Wait for PostgreSQL
for _ in range(10):
try:
psycopg2.connect(
dbname=dbname,
user=user,
password=password,
host=host,
port=port
)
print("Database is ready!")
break
except psycopg2.OperationalError:
print("Waiting for PostgreSQL...")
time.sleep(3)
END
# Apply database migrations
python manage.py migrate --noinput
# Start Gunicorn with appropriate settings
exec gunicorn discuso.wsgi:application \
--bind 0.0.0.0:${PORT:-8000} \
--workers 2 \
--threads 2 \
--timeout 120 \
--max-requests 1200 \
--max-requests-jitter 50 \
--log-level info