linux中jar包部署
1.安装java环境
2.上传jar包到服务器/home/test/web.jar
3.上传start.sh到/home/test
#!/bin/sh RESOURCE_NAME=web.jar BUILD_ID=dontKillMe tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Stop Process...' kill -15 $tpid fi sleep 5 tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Kill Process!' kill -9 $tpid else echo 'Stop Success!' fi tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'App is running.' else echo 'App is NOT running.' fi rm -f tpid source /etc/profile nohup java -jar ./$RESOURCE_NAME > /dev/null 2>&1 & sleep 10s echo $! > tpid echo Start Success!
第二个
#!/bin/sh RESOURCE_NAME=web.jar BUILD_ID=dontKillMe tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Stop Process...' kill -15 $tpid fi sleep 5 tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'Kill Process!' kill -9 $tpid else echo 'Stop Success!' fi tpid=`ps -ef|grep $RESOURCE_NAME|grep "java"|grep -v kill|awk '{print $2}'` if [ ${tpid} ]; then echo 'App is running.' else echo 'App is NOT running.' fi rm -f tpid source /etc/profile nohup java -jar ./$RESOURCE_NAME -spring.profiles.active=prod > /dev/null 2>&1 & sleep 10s echo $! > tpid echo Start Success!
注意nohup java -jar ./$RESOURCE_NAME -spring.profiles.active=prod > /dev/null 的-spring.profiles.active=prod 指的环境可以根据application-dev.yaml修改
4.运行:sh start.sh