脚本 启动/停止 jar包服务
windows (.bat):
@set port=8692 @echo %port%for /f "tokens=5" %%i in ('netstat -aon ^| findstr %port%') do (
set n=%%i
goto js
)
:js
taskkill /f /pid %n%
java -jar XXXXXXXX.jar --server.port=%port%
linux (.sh)
#!/bin/bash jar_pid=`ps -ef|grep -v grep | grep 'java -jar XXXXXX.jar '|awk '{ print $2 }'` echo $jar_pid if [ ! -n "$jar_pid" ]; then echo 'will redploy.' #cd portal-webserver/ rm -rf nohup.out nohup java -jar XXXXXX.jar & echo 'redploy success0.' else kill -9 $jar_pid echo 'kill' $jar_pid #cd dir/ rm -rf nohup.out nohup java -jar XXXXX.jar & echo 'redploy success1.' fi
原文地址:https://www.cnblogs.com/pangkang/p/9579494.html