停服务
@echo off
echo "*********Steps 1 停止服务*********"
set port=8888
echo port:%port%
set portpid=none
echo portpid:%portpid%
FOR /F "tokens=1-5" %%i IN ('netstat -ano^|findstr ":%port%"') DO @set portpid=%%m
if not %portpid% ==none ( taskkill /pid %portpid% /f ) else ( echo here is no pid for port %port% )
echo "*********Steps 1 停止服务成功! *********"
启动服务-备份服务
@echo off
echo "*********Steps 2 启动服务 *********"
set jarName="springboot-plusdome-1.0.0.jar"
set servicePath="D:\Program Files\Jenkins\Data\Jenkins\.jenkins\workspace\springboot2\"
set backupPath=%servicePath%"backup\"%jarName%"_"
set dataPath=%servicePath%"data"
set targetPath=%servicePath%"springboot_plusdome\target"
set backupDatePath="%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.jar"
set backupDatePath=%backupDatePath: =0%
cd %dataPath%
echo "*********Steps 2-1 正常启动 *********"
if exist %jarName% (
echo 文件%jarName%存在
copy %jarName% %backupPath%%backupDatePath%
echo "*********Steps 2-2 正常启动备份Jar包 end *********"
cd %targetPath%
move %jarName% %dataPath%
echo "*********Steps 2-3 启动服务! *********"
cd %dataPath%
set BUILD_ID=dontKillMe
start javaw -jar %jarName%
) else (
echo 启动目录-文件%jarName%不存在!
echo "*********Steps 2-1 正常启动失败!! *********"
cd %targetPath%
echo "*********Steps 2-1 进入首次启动 *********"
if exist %jarName% (
echo target目录-文件%jarName%存在
copy %jarName% %backupPath%%backupDatePath%
echo "*********Steps 2-2 首次启动备份Jar包 end *********"
move %jarName% %dataPath%
echo "*********Steps 2-3 首次启动服务!*********"
cd %dataPath%
set BUILD_ID=dontKillMe
start javaw -jar %jarName%
echo "*********Steps 2-3 首次启动服务成功*********"
) else (
echo target目录-文件%jarName%不存在!启动失败!!!!!
echo "*********Steps 2-1 首次启动服务失败!!!请联系管理员 *********"
)
echo "*********Steps 2 启动服务成功! *********"
)