springboot.sh

springboot.sh

Scroll Down
#!/bin/bash
#wajncn@gmail.com
#https://javanet123.com
#------  JAVA Env  ------#
#export JAVA_HOME="/opt/jdk1.8.0_20"
#export PATH=$JAVA_HOME/bin:$PATH
#.代表当前目录
LOG_FILE=.
APP=$1
ERROE_MSG="Usage: ./springBoot app.jar {start|stop|restart|status}"
if [ -z "$APP" ]; then
	echo ${ERROE_MSG}
	exit 0
fi
APP_NAME=${APP:0:${#APP}-4}
JAVA_OPTS="-Xms256m -Xmx512m"
# 远程监控
#JAVA_JMX="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=9909 -Dcom.sun.management.jmxremote.rmi.port=9909 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
# debug
#JAVA_JMX="-agentlib:jdwp=transport=dt_socket,address=8086,server=y,suspend=n"
#------  JMX RMI ------#
#JAVA_OPTS="$JAVA_OPTS $JAVA_JMX"
PID=""

function pid() {
	PID=$(ps -ef | grep -i $APP | grep 'java' | grep -v grep | awk '{ print $2 }')
}

function start() {
	pid
	if [ -n "$PID" ]; then
		echo "[$APP] is already running. PID $PID"
		exit 1
	fi

  # --spring.config.location=${APPLICATION_FILE}
	nohup java $JAVA_OPTS -jar $APP >>${LOG_FILE}/${APP_NAME}.log 2>&1 &

	sleep 1s
	pid
	if [ -n "$PID" ]; then
		echo "$APP Starting . PID $PID"
	else
		echo "$APP failure start"

	fi
	eval tail -f ${LOG_FILE}/${APP_NAME}.log
}

function status() {
	pid
	if [ -n "$PID" ]; then
		echo "[$APP] is already running. PID $PID"
	else
		echo "[$APP] is not running"

	fi
	sleep 3s
	eval tail -f ${LOG_FILE}/${APP_NAME}.log
}

function stop() {
	pid
	if [ -z "$PID" ]; then
		echo "[$APP] is already stopped"
	else
		echo kill -9 $PID
		kill -9 $PID
	fi
	sleep 3s
}

case $2 in
start)
	start
	exit 0
	;;
status)
	status
	exit 0
	;;
stop)
	stop
	exit 0
	;;
restart)
	stop
	start
	;;
*)
	echo ${ERROE_MSG}
	;;
esac

使用说明

./springBoot app.jar {start|stop|restart|status}

下载链接