The test environment starts the springboot project script
Applicable application structure
app
| -config / x.yml
|-logs/x.log
|-xx.jar
|-appserver
The script supports start|stop|state|restart, where stop defaults to kill -15, restart defaults to -15, waits for 30 seconds and does not shut down normally, and uses -9 to force shutdown
#!/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 be if [[ "" -ne "$2" ]]; then _timeout=$2 be 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." be if [ $i -gt 0 ]; then echo 'kill -'$_kill'..stop...success.' be return 1; else if [ $i -eq 0 ]; then echo 'kill -'$_kill"..Waitting server stop." be be echo 'kill -'$_kill'..stop...'$i'..' if [ $i -eq 0 ]; then for id in $pid do kill -$_kill $id; done be i=$(expr $i + 1) sleep 1 done; return 0; } restart() { if stop 15 30; then stop 9 30; be 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 be } case "$1" in start) $1 ;; stop) $1 ;; restart) $1 ;; state) $1 ;; *) echo $"Useage: $0 {start|stop|state|restart}" exit 2 esac
Other items to be improved