几种启动脚本,可能是centos7的原因要加上source /etc/profile,使其在当前远程链接有效


#!/bin/bash
echo "开始执行运行脚本"

#BUILD_ID=dontKillMe
pid=`ps -ef | grep xxx.jar  | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
   echo "kill -9 的pid:" $pid
   kill -9 $pid
fi

source /etc/profile
cd /opt/apps/xxx
echo '进入到了xxx目录'
mv xxx-xxx-*.jar  xxx-xxx.jar
echo '修改了jar名字'
#以debug模式启动,可以用idea远程调试
nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8001,suspend=n   -jar xxx-xxx.jar  >/dev/null  2>&1 &
echo '执行完了构建'

以debug方式启动,
#!/bin/bash
ps -ef | grep xxx | grep -v grep | awk '{print $2}' | xargs  kill -9
cd /opt/apps/xxx
mv xxx-*.jar  xxx.jar
echo "start project"

export JAVA_HOME=/opt/jdk/jdk1.8.0_144
echo "use java at $JAVA_HOME"
# 加入启动参数。可以远程debug调试,调试端口是5005
source /etc/profile
#BUILD_ID=dontKillMe
nohup java  -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005  -jar xxx.jar  >/dev/null  2>&1 &

正式环境启动
#!/bin/bash
ps -ef | grep hs-app-server-web | grep -v grep | awk '{print $2}' | xargs  kill -9
cd /opt/apps/xxx
mv xxx-*.jar  xxx.jar
echo "start project"

export JAVA_HOME=/opt/jdk/jdk1.8.0_144
echo "use java at $JAVA_HOME"
source /etc/profile
#BUILD_ID=dontKillMe
nohup java -jar xxx.jar  >/dev/null  2>&1 &

测试成功的
#!/bin/bash
ps -ef | grep xxx | grep -v grep | awk '{print $2}' | xargs  kill -9
cd /opt/apps/xxx
mv xxx-*.jar  xxx.jar
#以debug模式启动,可以用idea远程调试
source /etc/profile
#BUILD_ID=dontKillMe
nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8001,suspend=n   -jar xxx.jar  >/dev/null  2>&1 &

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐