#!/bin/bashspring
#export PROJECT_HOME=/home/Project/boot-service
#ports=(8081 8082 8083)
#jvm="-server -Xmx1024m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime "
#pom="prod.pom.xml"springboot
maven=/home/maven/bin/mvn
umask 0002bash
export LANG=zh_CN.GBK
export LC_ALL=zh_CN.GBK
export LC_CTYPE=zh_CN.GBK
export LANGUAGE=zh_CN.GBKapp
ac=$1
port=""
margs=""
jargs=""curl
OPTIND=2
while getopts P:m:j: opt
do
case $opt in
P)
port=$OPTARG
;;
m)
margs=$OPTARG
;;
j)
jargs=$OPTARG
;;jvm
*)
echo "$opt not support"
exit 1
;;
esac
donemaven
cd $PROJECT_HOME
logdir=${PROJECT_HOME}/log
export SERVER_PORT=$port
export MAVEN_OPTS="${jvm} -Xloggc:${logdir}/gc${SERVER_PORT}.log"spring-boot
if [ -n "$jargs" ];then
export MAVEN_OPTS="$jargs"
echo "MAVEN_OPTS = ${MAVEN_OPTS}"
fiui
if [ ! -n "$SERVER_PORT" ];then
echo "require a port in ["${ports[*]}"]"
exit 1
fiurl
ac=$1
pidf=${logdir}/${SERVER_PORT}.pid
cdate=`date +%Y%m`
logf=${logdir}/${SERVER_PORT}-${cdate}.log
cd ${PROJECT_HOME}
if [[ "${ports[@]}" =~ ${SERVER_PORT} ]];then
echo "use port = ${SERVER_PORT}"
else
echo "require a port in ["${ports[*]}"]"
exit 0
fi
clog() {
if [ ! -f $logf ];then
:> $logf
echo "$logf is not exists creating..."
fi
}
co() {
read -r -p "$ac port ${SERVER_PORT} ? [Y/n] " input
case "$input" in
[yY][eE][sS]|[yY])
echo "ok."
;;
[nN][oO]|[nN])
echo "exit ."
exit 0
;;
*)
echo "Invalid input..."
exit 1
;;
esac
}
start() {
${maven} clean
nohup ${maven} -Pprod -Dserver.port=${SERVER_PORT} ${margs} -f ${PROJECT_HOME}/${pom} spring-boot:run >> $logf &
if [ $? -eq 0 ];then
echo $! > $pidf
fi
echo "${SERVER_PORT} start ing ..."
}
stop() {
result=`curl -X POST 127.0.0.1:${SERVER_PORT}/app/shutdown -s`
echo $result
if [[ $result =~ "down" ]];then
echo -e "\nwait ${SERVER_PORT} shutdown ing 10s ..."
sleep 6
else
echo -e "springboot app not active."
sleep 2
fi
if [ -f $pidf ];then
kill -9 `cat $pidf`
rm -rf $pidf
echo "Kill and Remove pid ${pidf}"
else
echo "Shutdown error pid not exists,Please kill it if process exists"
fi
echo "done."
}
case "$ac" in
start)
co
clog
start
;;
stop)
co
clog
stop
;;
restart)
clog
stop
sleep 5
start
;;
*)
echo "Usage: $0 [start|stop|restart] -P [port] -m [maven.properties] -j [jvm.args]"
exit 0
esac
tail -f $logf
exit 0