Files
cattleData/backend/start.bat

101 lines
2.4 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM 牛只数据管理后端启动脚本 (Windows版本)
REM 使用方法: start.bat [start|stop|restart|status]
setlocal enabledelayedexpansion
set APP_NAME=cattletends
set JAR_NAME=cattletends-1.0.0.jar
set APP_PORT=8080
set JAVA_OPTS=-Xms512m -Xmx1024m
set SPRING_PROFILE=prod
set LOG_FILE=log.out
set PID_FILE=pid.%APP_NAME%.txt
REM 获取脚本所在目录
set SCRIPT_DIR=%~dp0
set JAR_PATH=%SCRIPT_DIR%target\%JAR_NAME%
REM 检查jar文件是否存在
if not exist "%JAR_PATH%" (
echo 错误: 找不到jar文件: %JAR_PATH%
echo 请先执行 mvn clean package 打包项目
exit /b 1
)
if "%1"=="start" goto start
if "%1"=="stop" goto stop
if "%1"=="restart" goto restart
if "%1"=="status" goto status
goto usage
:start
echo 正在启动应用: %APP_NAME%
REM 检查是否已经运行
for /f "tokens=2" %%a in ('jps -l ^| findstr "%JAR_NAME%"') do (
echo 应用已经在运行中PID: %%a
exit /b 1
)
REM 启动应用
start /b java %JAVA_OPTS% -Dspring.profiles.active=%SPRING_PROFILE% -Dserver.port=%APP_PORT% -jar "%JAR_PATH%" > "%LOG_FILE%" 2>&1
timeout /t 3 /nobreak >nul
REM 查找进程
for /f "tokens=2" %%a in ('jps -l ^| findstr "%JAR_NAME%"') do (
echo 应用启动成功PID: %%a
echo %%a > %PID_FILE%
echo 日志文件: %LOG_FILE%
echo 查看日志: type %LOG_FILE%
exit /b 0
)
echo 应用启动失败,请查看日志: %LOG_FILE%
exit /b 1
:stop
echo 正在停止应用: %APP_NAME%
REM 查找进程并停止
for /f "tokens=2" %%a in ('jps -l ^| findstr "%JAR_NAME%"') do (
echo 找到进程 PID: %%a
taskkill /F /PID %%a >nul 2>&1
echo 应用已停止
if exist %PID_FILE% del %PID_FILE%
exit /b 0
)
echo 应用未运行
if exist %PID_FILE% del %PID_FILE%
exit /b 0
:restart
echo ========== 重启应用: %APP_NAME% ==========
call :stop
timeout /t 2 /nobreak >nul
call :start
exit /b %errorlevel%
:status
for /f "tokens=2" %%a in ('jps -l ^| findstr "%JAR_NAME%"') do (
echo 应用运行中PID: %%a
echo 端口: %APP_PORT%
echo 日志: %LOG_FILE%
exit /b 0
)
echo 应用未运行
exit /b 0
:usage
echo 使用方法: %0 {start^|stop^|restart^|status}
echo.
echo 参数说明:
echo start - 启动应用
echo stop - 停止应用
echo restart - 重启应用
echo status - 查看应用状态
exit /b 1