springboot 项目启动shell脚本
测试环境启动springboot项目脚本
适用应用结构
app
|-config/x.yml
|-logs/x.log
|-xx.jar
|-appserver
脚本支持start|stop|state|restart 其中stop默认用kill -15,restart 默认-15 等待30秒未正常关闭用-9强制关闭
#!/bin/sh export LANG="en_US.UTF-8" _JAVA=$JAVA_HOME/bin/java _APP=$(cd $(dirname $0); pwd) _JARS=.:$_APP/config #-Xdebug -Xrunjdwp:transport=dt_socket,address=6062,suspend=n,server=y _PARAMS="-Xverify:none -server -Xms128m -Xmx256m -Xmn128m -XX:PermSize=128m -XX:MaxPermSize=256m -Xss512K -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC -XX:ParallelGCThreads=1 -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=7 -XX:MaxGCPauseMillis=100 -XX:CMSInitiatingOccupancyFraction=80 -XX:-PrintGC -XX:-PrintGCDetails -Xloggc:$_APP/logs/gc.log -XX:ErrorFile=$_APP/logs/hs_error%p.log" _LOG="$_APP/logs/log_start.log" start() { [ -d $_APP ] || exit 5; echo "Server is starting..." cd $_APP nohup $_JAVA $_PARAMS -jar $_APP/hsd-*.jar > $_LOG 2>&1 & # crontab -e 0,30 * * * * current_date=`date -d "-1 day" "+%Y%m%d"`; split -b 65535000 -d -a 4 $_APP/$_LOG $_APP/$_LOG_${current_date}_; cat /dev/null > $_APP/$_LOG echo "Server is started..." } stop() { _kill=15 _timeout=30 if [[ "" -ne "$1" ]]; then _kill=$1 fi if [[ "" -ne "$2" ]]; then _timeout=$2 fi echo 'kill -'$_kill"..find Server process."; i=0 while test $i -lt $_timeout; do pid=$(ps -ef | grep $_APP | grep -v grep | grep -v appserver | awk '{print $2}') if [ ! -n "$pid" ]; then if [ $i -eq 0 ]; then echo "Server process is not find." fi if [ $i -gt 0 ]; then echo 'kill -'$_kill'..stop...success.' fi return 1; else if [ $i -eq 0 ]; then echo 'kill -'$_kill"..Waitting server stop." fi fi echo 'kill -'$_kill'..stop...'$i'..' if [ $i -eq 0 ]; then for id in $pid do kill -$_kill $id; done fi i=$(expr $i + 1) sleep 1 done; return 0; } restart() { if stop 15 30; then stop 9 30; fi start } state() { pid=$(ps -ef | grep $_APP | grep -v grep | grep -v appserver | awk '{print $2}') if [ ! -n "$pid" ]; then echo "Server process is not find." else for id in $pid do echo "Server is run pid="$id; done fi } case "$1" in start) $1 ;; stop) $1 ;; restart) $1 ;; state) $1 ;; *) echo $"Useage: $0 {start|stop|state|restart}" exit 2 esac
待改进其它项 后补