Skip to content

Instantly share code, notes, and snippets.

@onlyeat3
Created July 8, 2019 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlyeat3/0fa3ffc7a5671d35286fdce436e2004b to your computer and use it in GitHub Desktop.
Save onlyeat3/0fa3ffc7a5671d35286fdce436e2004b to your computer and use it in GitHub Desktop.
restart spring boot jar
#!/bin/bash
## Author LinkinStar,liuyuyu
## UPDATE 2019-01-05
version="1.0.1";
jarName=$2
appName=jarName
apolloMeta=http://172.20.5.103:8080
projectDir=/home/liuyuyu/data/web/$jarName
cd $projectDir
if [ -z $jarName ];then
jarName=`ls -t |grep .jar$ |head -n1`
jarName=${jarName%%.*}
fi
function start()
{
count=`ps -ef |grep java|grep $appName|wc -l`
if [ $count != 0 ];then
echo "Maybe $jarName is running, please check it..."
else
echo "The $jarName is starting..."
nohup java \
-Dapollo.meta=${apolloMeta} \
-server \
-Xms640M \
-Xmx640M \
-Xmn192M \
-XX:MaxMetaspaceSize=128M \
-XX:MetaspaceSize=128M \
-XX:+UseParallelGC \
-XX:+UseAdaptiveSizePolicy \
-XX:MaxGCPauseMillis=100 \
-verbose:class \
-XX:+PrintGCDateStamps \
-XX:+PrintCommandLineFlags \
-XX:+PrintTenuringDistribution \
-XX:+PrintGCApplicationStoppedTime \
-XX:+PrintGCApplicationConcurrentTime \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:HeapDumpPath=heapdump/$jarName.hprof \
-XX:+PrintGCDetails -Xloggc:${appName}_gc.log \
-jar $jarName.jar > /dev/null 2>&1 &
echo "The $jarName has started."
fi
}
function stop()
{
appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
if [ -z $appId ];then
echo "Maybe $jarName not running, please check it..."
else
echo "The $jarName is stopping..."
kill $appId
fi
}
function restart()
{
# get release version
releaseApp=`ls -t |grep .jar$ |head -n1`
# get last version
lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
jarName=$lastVersionApp
jarName=${jarName%%.*}
stop
for i in {5..1}
do
echo -n "$i "
sleep 1
done
echo 0
backup
jarName=$releaseApp
jarName=${jarName%%.*}
start
}
function backup()
{
# get backup version
backupApp=`ls |grep -wv $releaseApp$ |grep .jar$`
# create backup dir
if [ ! -d "backup" ];then
mkdir backup
fi
# backup
for i in ${backupApp[@]}
do
echo "backup" $i
mv $i backup
done
}
function status()
{
appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
if [ -z $appId ]
then
echo -e "\033[31m Not running \033[0m"
else
echo -e "\033[32m Running [$appId] \033[0m"
fi
}
function usage()
{
echo "Usage: $0 {start|stop|restart|status|stop -f}"
echo "Example: $0 start"
exit 1
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
usage;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment