@echo off set port=8089 netstat -ano | findstr ":%8089%" >nul if "%errorlevel%"=="0" ( goto restart ) else ( timeout /t 5 >nul goto start ) :restart for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%8089%"') do ( echo kill the process %%m who use the port taskkill /pid %%m -t -f goto start ) :start cd /d d:\asb\ set MYSQL_PORT=3306 :loop netstat -ano | findstr ":%MYSQL_PORT%" >nul if "%errorlevel%"=="0" ( goto check_es ) else ( timeout /t 5 >nul goto loop ) set ES_PORT=9200 :check_es netstat -ano | findstr ":%ES_PORT%" >nul if "%errorlevel%"=="0" ( goto check_redis ) else ( timeout /t 5 >nul goto check_es ) :check_redis set REDIS_PORT=9200 netstat -ano | findstr ":%REDIS_PORT%" >nul if "%errorlevel%"=="0" ( goto start_jar ) else ( timeout /t 5 >nul goto check_redis ) :start_jar start "app" javaw -javaagent:server.jar -jar server.jar --spring.profiles.active=prod