You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.9 KiB
79 lines
1.9 KiB
@echo off
|
|
chcp 65001 >nul
|
|
echo ==========================================
|
|
echo 行情数据服务 - 环境初始化
|
|
echo ==========================================
|
|
echo.
|
|
|
|
REM 检查 Docker
|
|
where docker >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [错误] Docker 未安装!请先安装 Docker Desktop
|
|
echo 下载地址: https://www.docker.com/products/docker-desktop
|
|
exit /b 1
|
|
)
|
|
|
|
echo [1/4] 正在启动 PostgreSQL 容器...
|
|
docker ps | findstr market_data_postgres >nul
|
|
if %errorlevel% == 0 (
|
|
echo [提示] PostgreSQL 容器已在运行
|
|
) else (
|
|
docker start market_data_postgres >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo 正在创建新容器...
|
|
docker run -d --name market_data_postgres ^
|
|
-e POSTGRES_USER=postgres ^
|
|
-e POSTGRES_PASSWORD=postgres123 ^
|
|
-e POSTGRES_DB=marketdata ^
|
|
-p 5432:5432 ^
|
|
-v postgres_data:/var/lib/postgresql/data ^
|
|
--restart unless-stopped ^
|
|
postgres:15-alpine >nul
|
|
) else (
|
|
echo [提示] 已启动现有容器
|
|
)
|
|
)
|
|
|
|
echo.
|
|
echo [2/4] 等待数据库就绪...
|
|
set /a count=0
|
|
:wait_loop
|
|
timeout /t 1 /nobreak >nul
|
|
set /a count+=1
|
|
docker exec market_data_postgres pg_isready -U postgres >nul 2>&1
|
|
if errorlevel 1 (
|
|
if %count% lss 30 (
|
|
echo 等待中... (%count%/30)
|
|
goto wait_loop
|
|
) else (
|
|
echo [错误] 数据库启动超时!
|
|
exit /b 1
|
|
)
|
|
)
|
|
echo 数据库已就绪!
|
|
|
|
echo.
|
|
echo [3/4] 正在初始化数据库表...
|
|
python test_db.py
|
|
if errorlevel 1 (
|
|
echo [错误] 数据库初始化失败!
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
echo [4/4] 正在安装依赖...
|
|
pip install -q -r requirements.txt
|
|
|
|
echo.
|
|
echo ==========================================
|
|
echo 初始化完成!
|
|
echo ==========================================
|
|
echo.
|
|
echo 现在可以启动服务了:
|
|
echo python -m app.main
|
|
echo.
|
|
echo 访问地址:
|
|
echo http://localhost:8080
|
|
echo.
|
|
pause
|