spring cloud 批处理文件单个启动模块,批量启动模块

普通单个bat启动:java -jar intelligent-audit-sys-discovery-eureka-1.0-SNAPSHOT.jar  -Xms32m -Xmx64m -Xss256k 

一.每个单独模块的写法  编写每一个项目的构建、启动、杀死脚本

@echo off
 
::默认PID,无需修改
set "PID=999999"
::记录当前目录,无需修改
set "CURRENT_PATH=%cd%"
 
::指定java_home路径,不能起名JAVA_HOME,会覆盖环境变量
set "JAVA_HOME_CUSTOM=D:\DevTool\jdk1.8.0_181"
::指定jre_home
set "JRE_HOME_CUSTOM=%JAVA_HOME_CUSTOM%\jre"
::指定maven_home,不能起名MAVEN_HOME,会覆盖环境变量
set "MAVEN_HOME_CUSTOM=D:\DevTool\apache-maven-3.5.4"
 
 
::指定程序工作路径
set "SERVICE_DIR=D:\xiaowei1\gitlabdep\chanpay-eureka\chanpay-eureka"
::指定程序包名
set "JARNAME=chanpay-eureka.jar"
::指定程序端口号
set "port=9080"
::指定程序启动日志名
set "LOG_FILE=chanpay-eureka.log"
 
 
 
::流程控制
if "%1"=="start" (
  call:START
) else (
  if "%1"=="stop" ( 
    call:STOP 
  ) else ( 
    if "%1"=="restart" (
      call:RESTART 
    ) else ( 
      call:DEFAULT 
    )
  )
)
 
goto:eof
 
 
::启动jar包
:START
echo function "start" starting...
cd /d %SERVICE_DIR%
call %MAVEN_HOME_CUSTOM%\bin\mvn clean install
echo "%JRE_HOME_CUSTOM%\bin\java"
start /b "%JRE_HOME_CUSTOM%\bin\" java.exe -Xms128m -Xmx512m -jar %SERVICE_DIR%\target\%JARNAME% > %SERVICE_DIR%\logs\%LOG_FILE%
cd /d %CURRENT_PATH%
echo == service start success
goto:eof
 
 
::停止java程序运行
:STOP
echo function "stop" starting...
call:findPid
call:shutdown
echo == service stop success
goto:eof

 
 
::重启jar包
:RESTART
echo function "restart" starting...
call:STOP
call:sleep2
call:START
echo == service restart success
goto:eof
 
 
::执行默认方法--重启jar包
:DEFAULT
echo Now choose default item : restart
call:STOP
call:sleep2
call:START
echo == service restart success
goto:eof
 
 
::找到端口对应程序的pid
:findPid
echo function "findPid" start.
for /f "tokens=5" %%i in ('netstat -aon ^| findstr %port%') do (
    set "PID=%%i"
)
if "%PID%"=="999999" ( echo pid not find, skip stop . ) else ( echo pid is %PID%. )
goto:eof
 
 
::杀死pid对应的程序
:shutdown
if not "%PID%"=="999999" ( taskkill /f /pid %PID% )
goto:eof
 
 
::延时5秒
:sleep5
ping 127.0.0.1 -n 5 >nul
goto:eof
 
 
::延时2秒
:sleep2
ping 127.0.0.1 -n 2 >nul
goto:eof

 

 

整体启动多个模块 

 

@echo off
 
::其他bat工作路径
set "OTHER_BAT_WORK_SPACE=D:\xiaowei1\startBat"
::记录当前目录,无需修改
set "CURRENT_ROOT_PATH=%cd%"
::启动命令(start|stop|restart|其他默认重启)
set "PARAM1="
 
 
 
::流程控制
if "%1"=="start" (
  set "PARAM1=%1"
) else (
  if "%1"=="stop" ( 
    set "PARAM1=%1"
  ) else ( 
    if "%1"=="restart" (
      set "PARAM1=%1"
    ) else ( 
      if "%1"=="" (
        set "PARAM1=restart" 
      ) else (
        set "PARAM1=restart"
      )
    )
  )
)
 
::项目主流程开始
 
echo facade.bat starting...
call %OTHER_BAT_WORK_SPACE%\facade.bat %PARAM1%
 
echo eureka.bat starting...
call %OTHER_BAT_WORK_SPACE%\eureka.bat %PARAM1%
 
 
echo service-base.bat starting...
call %OTHER_BAT_WORK_SPACE%\service-base.bat %PARAM1%
 
echo service-cache.bat starting...
call %OTHER_BAT_WORK_SPACE%\service-cache.bat %PARAM1%
 
echo service-monitor.bat starting...
call %OTHER_BAT_WORK_SPACE%\service-monitor.bat %PARAM1%
 
echo service-permission.bat starting...
call %OTHER_BAT_WORK_SPACE%\service-permission.bat %PARAM1%
 
echo hsm-keyou.bat starting...
call %OTHER_BAT_WORK_SPACE%\hsm-keyou.bat %PARAM1%
 
cd /d %CURRENT_ROOT_PATH%
 
echo ---all services have started successful---
 
goto:eof

自己修改过的直接是打包好的jar使用下面

@echo off
title intelligent-audit-sys-discovery-eureka
::默认PID,无需修改
set "PID=999999"
::记录当前目录,无需修改
set "CURRENT_PATH=%cd%"
::指定程序端口号
set "port=8761"

 
 
::流程控制
if "%1"=="start" (
  call:START
) else (
  if "%1"=="stop" ( 
    call:STOP 
  ) else ( 
    if "%1"=="restart" (
      call:RESTART 
    ) else ( 
      call:DEFAULT 
    )
  )
)
 
goto:eof
 
 
::启动jar包
:START
echo function "start" starting...
start /b java -jar intelligent-audit-sys-discovery-eureka-1.0-SNAPSHOT.jar  -Xms32m -Xmx64m -Xss256k 
echo == service start success
goto:eof
 
 
::停止java程序运行
:STOP
echo function "stop" starting...
call:findPid
call:shutdown
echo == service stop success
goto:eof
 
 
::重启jar包
:RESTART
echo function "restart" starting...
call:STOP
call:sleep2
call:START
echo == service restart success
goto:eof
 
 
::执行默认方法--重启jar包
:DEFAULT
echo Now choose default item : restart
call:STOP
call:sleep2
call:START
echo == service restart success
goto:eof
 
 
::找到端口对应程序的pid
:findPid
echo function "findPid" start.
for /f "tokens=5" %%i in ('netstat -aon ^| findstr %port%') do (
    set "PID=%%i"
)
if "%PID%"=="999999" ( echo pid not find, skip stop . ) else ( echo pid is %PID%. )
goto:eof
 
 
::杀死pid对应的程序
:shutdown
if not "%PID%"=="999999" ( taskkill /f /pid %PID% )
goto:eof
 
 
::延时5秒
:sleep5
ping 127.0.0.1 -n 5 >nul
goto:eof
 
 
::延时2秒
:sleep2
ping 127.0.0.1 -n 2 >nul
goto:eof

 

整体启动多个

@echo off
 

::记录当前目录,无需修改
set "CURRENT_ROOT_PATH=%cd%"
::启动命令(start|stop|restart|其他默认重启)
set "PARAM1="
title sysstart
 
 
 
::流程控制
if "%1"=="start" (
  set "PARAM1=%1"
) else (
  if "%1"=="stop" ( 
    set "PARAM1=%1"
  ) else ( 
    if "%1"=="restart" (
      set "PARAM1=%1"
    ) else ( 
      if "%1"=="" (
        set "PARAM1=restart" 
      ) else (
        set "PARAM1=restart"
      )
    )
  )
)
 
::项目主流程开始
 
echo intelligent-audit-sys-discovery-eureka.bat starting...
call intelligent-audit-sys-discovery-eureka.bat %PARAM1%
 
echo intelligent-audit-sys-config-server-1.0-SNAPSHOT.bat starting...
call intelligent-audit-sys-config-server-1.0-SNAPSHOT.bat %PARAM1%
 
 
echo intelligent-audit-sys-gateway-1.0-SNAPSHOT.bat starting...
call intelligent-audit-sys-gateway-1.0-SNAPSHOT.bat %PARAM1%
 
 
cd /d %CURRENT_ROOT_PATH%
 
echo ---all services have started successful---
 
goto:eof
 

 

 

你可能感兴趣的:(Spring,cloud)