Files
CTFd/ping.py
Kevin Chung a64e7d51ef Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1
c9887cb1 Fix team template

git-subtree-dir: CTFd/themes/core-beta
git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
2023-06-11 15:56:28 -04:00

35 lines
828 B
Python

"""
Script for checking that a database server is available.
Essentially a cross-platform, database agnostic mysqladmin.
"""
import time
from sqlalchemy import create_engine
from sqlalchemy.engine.url import make_url
from CTFd.config import Config
url = make_url(Config.DATABASE_URL)
# Ignore sqlite databases
if url.drivername.startswith("sqlite"):
exit(0)
# Null out the database so raw_connection doesnt error if it doesnt exist
# CTFd will create the database if it doesnt exist
url.database = None
# Wait for the database server to be available
engine = create_engine(url)
print(f"Waiting for {url.host} to be ready")
while True:
try:
engine.raw_connection()
break
except Exception:
print(".", end="", flush=True)
time.sleep(1)
print(f"{url.host} is ready")
time.sleep(1)