QGIS的docker管理

This commit is contained in:
wzy-warehouse
2026-06-21 22:30:04 +08:00
parent 4e459fc203
commit 154f0a968e
11 changed files with 761 additions and 377 deletions
+15 -11
View File
@@ -22,17 +22,21 @@ async def lifespan(app: FastAPI):
get_earthquake_model()
logger.info("DBN模型预加载完成")
# 检测 QGIS 子进程环境(产图时按需启动子进程)
qgis_root = getattr(settings, "QGIS_ROOT", None)
if qgis_root:
try:
from app.services.qgis.qgis_env import is_qgis_available
if is_qgis_available(qgis_root):
logger.info("QGIS 环境检测通过")
else:
logger.warning("QGIS 环境不可用,专题图功能降级")
except Exception as e:
logger.error(f"QGIS 环境检测失败: {e}")
# 检测 Docker QGIS 容器是否可用
try:
import subprocess
from app.services.qgis.qgis_env import get_docker_container
container = get_docker_container()
result = subprocess.run(
["docker", "inspect", "--format={{.State.Running}}", container],
capture_output=True, text=True, timeout=5,
)
if result.stdout.strip() == "true":
logger.info(f"Docker QGIS 容器 '{container}' 运行中")
else:
logger.warning(f"Docker QGIS 容器 '{container}' 未运行,专题图功能降级")
except Exception as e:
logger.error(f"Docker QGIS 检测失败: {e}")
yield