improved start sequence, fixed user update
This commit is contained in:
@@ -18,5 +18,7 @@ COPY . .
|
||||
# Expose RADIUS port (UDP)
|
||||
EXPOSE 1812/udp
|
||||
|
||||
COPY wait-for-db.py .
|
||||
|
||||
# Run the RADIUS service
|
||||
CMD ["python", "main.py"]
|
||||
CMD ["sh", "-c", "python wait-for-db.py && python main.py"]
|
||||
|
||||
36
radius/wait-for-db.py
Normal file
36
radius/wait-for-db.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import os
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
|
||||
host = os.getenv("DB_HOST", "db")
|
||||
port = int(os.getenv("DB_PORT", "3306"))
|
||||
user = os.getenv("DB_USER")
|
||||
password = os.getenv("DB_PASSWORD")
|
||||
database = os.getenv("DB_NAME")
|
||||
|
||||
timeout = 60 # seconds
|
||||
start_time = time.time()
|
||||
|
||||
print(f"⏳ Waiting for DB at {host}:{port} to be ready...")
|
||||
|
||||
while True:
|
||||
try:
|
||||
conn = mysql.connector.connect(
|
||||
host=host,
|
||||
port=port,
|
||||
user=user,
|
||||
password=password,
|
||||
database=database
|
||||
)
|
||||
if conn.is_connected():
|
||||
print("✅ Database is ready!")
|
||||
conn.close()
|
||||
break
|
||||
except Error as e:
|
||||
print(f"🛑 DB not ready yet: {e}")
|
||||
time.sleep(2)
|
||||
if time.time() - start_time > timeout:
|
||||
print("❌ Timeout waiting for the database.")
|
||||
exit(1)
|
||||
Reference in New Issue
Block a user