目录
JAR包的启动脚本
多个JAR包同时启动
@echo off echo. echo WebVR START... echo. :: 进入目录文件夹 d: cd D:\JT\java\workspace\webvr-end\deploy :: 执行多个javaw命令,但是无法输出日志 echo webvr-auth START... start javaw -jar -Dfile.encoding=utf-8 -Xms800m -Xmx1024m webvr-auth-1.0.5.jar echo webvr-gateway START... start javaw -jar -Dfile.encoding=utf-8 -Xms800m -Xmx1024m webvr-gateway-1.0.5.jar echo webvr-system START... start javaw -jar -Dfile.encoding=utf-8 -Xms800m -Xmx1024m webvr-system-1.0.5.jar echo webvr-vr START... start javaw -jar -Dfile.encoding=utf-8 -Xms800m -Xmx1024m webvr-vr-1.0.5.jar pause
启动效果
存在问题:
无法输出日志
单个JAR包启动,并输出日志
依赖cronolog组件
cronolog组件下载
链接:https://pan.baidu.com/s/1vYprB1gfXed9gqQ0o8QSSQ
提取码:1111
@echo off echo. echo WebVR START...[1/4] echo. :: 应用存放路径 set deploy_path = D:\JT\java\workspace\webvr-end\deploy :: 进入目录文件夹 d: echo cd deploy_path %deploy_path% cd %deploy_path% :: 执行命令 echo webvr-auth START... javaw -D'file.encoding=utf-8' -jar webvr-auth-1.0.5.jar 2>&1>webvr-auth.log pause
存在问题:
日志文件越来越大,问题定位不方便
单个JAR包启动,并输出按天分割的日志
@echo off echo. echo WebVR START...[4/4] echo. :: 应用存放路径 set deploy_path = D:\JT\java\workspace\webvr-end\deploy :: 进入目录文件夹 d: echo cd deploy_path %deploy_path% cd %deploy_path% :: 执行命令 echo webvr-vr START... :: javaw -D'file.encoding=utf-8' -jar webvr-vr-1.0.5.jar 2>&1>webvr-vr.log javaw -D'file.encoding=utf-8' -jar webvr-vr-1.0.5.jar | D:\JT\java\workspace\webvr-end\deploy\cronolog\cronolog.exe D:\JT\java\workspace\webvr-end\deploy\log\webvr-vr-%%Y%%m%%d.log pause
启动效果
还待解决的问题:
过去多少天(如3个月)的日志,并没有多大意义,需要清理
JAR包的停止脚本
原理:
1. 查找一下XXX端口的进程: netstat -a -n -o | findstr :9200
2. 结束进程: taskkill /pid 2044 -t -f
停止一个端口
@echo off set port=20812 for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do ( echo kill the process %%m who use the port %port% taskkill /pid %%m )
停止多个端口
port设置成变量,并用空白字符分割
@echo off set port=7910 9200 9201 9203 for /f "tokens=1-5" %%a in ('netstat -ano^|findstr ":%port%"') do ( echo PID:%%e is running,kill the process [%%e] who use the port [%%b] taskkill /F /pid %%e ) pause
执行效果
其中报错信息"错误,没有找到进程XXX",并不影响,因为对应的进程已经再上面被杀掉
停止多个连续端口
for /l %%n in (20801,1,2085),表示操作20801,20802,20803,20804,20805的端口
@echo off for /l %%n in (20801,1,2085) do ( @echo find the process which use port [%%n] for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%%n"') do ( tasklist /FI "PID eq %%m"|find /i "PID" && ( echo PID:%%m 运行中,kill the process [%%m] who use the port [%%n] taskkill /F /pid %%m ) || echo PID:%%m 未运行 ) )
bat批处理脚本静默运行
1.打开文本编辑器
DIM objShell
set objShell=createobject("wscript.shell")
result=objShell.Run("bat路径",0,true)
2.将文件的后缀名改为.vbs 双击即可运行
DIM objShell set objShell=createobject("wscript.shell") result=objShell.Run("D:\JT\java\workspace\webvr-end\deploy\StartWebVR.bat",0,true)