windows部分
启动服务脚本
start.xxx-xxx-1.1.21.RELEASE.bat
@echo off
set JAR=xxx-xxx-1.1.21.RELEASE.jar
@echo %JAVA_HOME%
start javaw -Dfile.encoding=UTF-8 -jar ..\lib\%JAR% --server.port=8105 --spring.profiles.active=aliyun
exit
启动服务脚本
start.xxx-xxx-*.RELEASE.bat
(当前文件夹下面必须只有一个如 xxx-xxx-1.1.0.RELEASE.jar的jar)
此启动是,不配置版本号,只启动指定的jar
@echo off
for %%i in ("..\lib\xxx-xxx-*.RELEASE.jar") do (
set JAR=%%~nxi
)
@echo %JAVA_HOME%
start javaw -Dfile.encoding=UTF-8 -jar ..\lib\%JAR% --server.port=8105 --spring.profiles.active=dev
exit
关闭服务脚本
stop.xxx-xxx-1.1.21.RELEASE.bat
@echo off
set port=8105
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port %port%
taskkill /f /pid %%m
)
线上debug启动服务脚本
start.xxx-xxx-1.1.21.RELEASE.bat
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8998
为远程访问,debug命令。此命令可以是本地环境debug线上环境,idea配置远程端口,启动连接线上
@echo off
set JAR=xxx-xxx-1.1.21.RELEASE.jar
@echo %JAVA_HOME%
start javaw -Dfile.encoding=UTF-8 -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8998 ..\lib\%JAR% --server.port=8105 --spring.profiles.active=aliyun
exit
linux部分
启动脚本
xxx-xxx-1.1.21.RELEASE.sh
#!/bin/sh
## java env
export JAVA_HOME=/usr/local/java/jdk1.8.0_172
export JRE_HOME=$JAVA_HOME/jre
## service name
APP_NAME=xxx-xxx-3.1.19.RELEASE
SERVICE_DIR=/usr/local/review/lib
SERVICE_NAME=$APP_NAME
JAR_NAME=$SERVICE_NAME\.jar
PID=$SERVICE_NAME\.pid
cd $SERVICE_DIR
case "$1" in
start)
nohup java -jar $SERVICE_DIR/$JAR_NAME --server.port=8102 --spring.profiles.active=aliyun >/dev/null 2>&1 &
echo $! > $SERVICE_DIR/$PID
echo "=== start $SERVICE_NAME"
;;
stop)
kill `cat $SERVICE_DIR/$PID`
rm -rf $SERVICE_DIR/$PID
echo "=== stop $SERVICE_NAME"
sleep 5
P_ID=`ps -ef | grep -w "$SERVICE_NAME" | grep -v "grep" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
echo "=== $SERVICE_NAME process not exists or stop success"
else
echo "=== $SERVICE_NAME process pid is:$P_ID"
echo "=== begin kill $SERVICE_NAME process, pid is:$P_ID"
kill -9 $P_ID
fi
;;
restart)
$0 stop
sleep 2
$0 start
echo "=== restart $SERVICE_NAME"
;;
*)
## restart
$0 stop
sleep 2
$0 start
;;
esac
exit 0