New Database

This commit is contained in:
喆OvO
2026-08-11 22:07:55 +08:00
parent cbbb2e6d34
commit ceb4404c6a
28 changed files with 1825 additions and 768 deletions
+18 -24
View File
@@ -1,40 +1,34 @@
"""Production entry point for the Calendar Display application."""
"""Development entrypoint (Flask dev server, port 5001).
For production use Gunicorn via `start:app` (see start.py and Dockerfile).
"""
import os
import sys
os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from backend.app import create_app
from backend.scheduler import start_scheduler, stop_scheduler
from backend.models import _EMITTED_PASSWORDS, get_auth_config
from backend.scheduler import start_scheduler, stop_scheduler, try_acquire_scheduler_lock
# Use environment variable to toggle debug, default False for production
DEBUG = os.environ.get("FLASK_DEBUG", "").lower() in ("1", "true", "yes")
db_path = os.environ.get("FLASK_DB_PATH", os.path.join(os.path.dirname(__file__), "data.db"))
app = create_app(db_path=db_path)
db_url = os.environ.get("DATABASE_URL",
"postgresql://iot:iot@localhost:5432/iot_dboard")
app = create_app(db_path=db_url)
if __name__ == "__main__":
# In debug mode, scheduler runs only in the reloader child process
DEBUG = os.environ.get("FLASK_DEBUG", "").lower() in ("1", "true", "yes")
# In debug mode the reloader re-imports this module; only the child process
# should start the scheduler (advisory lock keeps it single anyway).
is_reloader_child = os.environ.get("WERKZEUG_RUN_MAIN") == "true"
if not DEBUG or is_reloader_child:
start_scheduler(app)
# Print temp password at startup
with app.app_context():
if not _EMITTED_PASSWORDS:
cfg = get_auth_config()
pw = cfg.get("temp_password", "")
if pw and cfg.get("must_configure_mfa"):
print(f"\n{'='*50}", file=sys.stderr)
print(f" 🔐 临时密码: {pw}", file=sys.stderr)
print(f" ⚠️ 请使用此密码登录并配置双因素认证", file=sys.stderr)
print(f"{'='*50}\n", file=sys.stderr)
if try_acquire_scheduler_lock(db_url):
start_scheduler(app)
try:
bind_host = os.environ.get("FLASK_BIND", "127.0.0.1")
app.run(host=bind_host, port=5001, debug=DEBUG, threaded=True)
app.run(host=bind_host, port=int(os.environ.get("FLASK_PORT", "5001")),
debug=DEBUG, threaded=True)
finally:
if not DEBUG or is_reloader_child:
stop_scheduler()
stop_scheduler()