init CTFd source
Some checks are pending
Linting / Linting (3.11) (push) Waiting to run
Mirror core-theme / mirror (push) Waiting to run

This commit is contained in:
gkr
2025-12-25 09:39:21 +08:00
commit 2e06f92c64
1047 changed files with 150349 additions and 0 deletions

35
ping.py Normal file
View File

@@ -0,0 +1,35 @@
"""
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 = url._replace(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 as e:
print(e)
print("Waiting 1s for database connection")
time.sleep(1)
print(f"{url.host} is ready")
time.sleep(1)