forked from CTFd/CTFd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping database with python instead of mysql client (CTFd#1862)
* Replaces `mysqladmin ping` with a custom script * Closes CTFd#725
- Loading branch information
1 parent
5976830
commit 345706d
Showing
3 changed files
with
36 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
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} to be ready") | ||
while True: | ||
try: | ||
engine.raw_connection() | ||
break | ||
except Exception: | ||
print(".", end="", flush=True) | ||
time.sleep(1) | ||
|
||
print(f"{url} is ready") | ||
time.sleep(1) |