start.sh:
#!/bin/bashSERVER_NAME=‘stu‘# jar名称JAR_NAME=‘stu-0.0.1-SNAPSHOT.jar‘cd `dirname $0`BIN_DIR=`pwd`cd ..DEPLOY_DIR=`pwd`echo $DEPLOY_DIRCONF_DIR=$DEPLOY_DIR/conf SERVER_PORT=`sed ‘/server.port/!d;s/.*=//‘ conf/application.properties | tr -d ‘\r‘`# 获取应用的端口号echo $SERVER_PORT PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk ‘{print $2}‘`if [ "$1" = "status" ]; then if [ -n "$PIDS" ]; then echo "The $SERVER_NAME is running...!" echo "PID: $PIDS" exit 0 else echo "The $SERVER_NAME is stopped" exit 0 fifi if [ -n "$PIDS" ]; then echo "ERROR: The $SERVER_NAME already started!" echo "PID: $PIDS" exit 1fi if [ -n "$SERVER_PORT" ]; then SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l` if [ $SERVER_PORT_COUNT -gt 0 ]; then echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!" exit 1 fifi LOGS_DIR=$DEPLOY_DIR/logsif [ ! -d $LOGS_DIR ]; then mkdir $LOGS_DIRfiSTDOUT_FILE=$LOGS_DIR/stdout.log JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "JAVA_DEBUG_OPTS=""if [ "$1" = "debug" ]; then JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "fi JAVA_JMX_OPTS=""if [ "$1" = "jmx" ]; then JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "fi JAVA_MEM_OPTS=""BITS=`java -version 2>&1 | grep -i 64-bit`if [ -n "$BITS" ]; then JAVA_MEM_OPTS=" -server -Xmx512m -Xms512m -Xmn256m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "else JAVA_MEM_OPTS=" -server -Xms512m -Xmx512m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "fiecho $SERVER_PORT CONFIG_FILES=" -Dlogging.path=$LOGS_DIR -Dlogging.config=$CONF_DIR/log4j2.xml -Dspring.config.location=$CONF_DIR/application.properties "echo -e "Starting the $SERVER_NAME ..."echo $JAVA_OPTSecho $JAVA_MEM_OPTSecho $JAVA_DEBUG_OPTSecho $JAVA_JMX_OPTSecho $DEPLOY_DIR/lib/$JAR_NAMEecho $STDOUT_FILEecho ${CONF_DIR}LIB_DIR=$DEPLOY_DIR/libLIB_JARS=`ls $LIB_DIR|grep .jar|awk ‘{print "‘$LIB_DIR‘/"$0}‘|tr "\n" ":"`nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS cn.sw.stu.StuApplication --Dspring.config.location=$CONF_DIR > $STDOUT_FILE 2>&1 &COUNT=0while [ $COUNT -lt 1 ]; do echo -e ".\c" sleep 1 if [ -n "$SERVER_PORT" ]; thenecho $COUNT COUNT=`netstat -an | grep $SERVER_PORT | wc -l` COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk ‘{print $2}‘ | wc -l` fi if [ $COUNT -gt 0 ]; then break fidone echo "OK!"PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk ‘{print $2}‘`echo "PID: $PIDS"echo "STDOUT: $STDOUT_FILE"echo "success" stop.sh:
#!/bin/bashcd ..APP_NAME=`pwd`echo $APP_NAMEtpid=`ps -f | grep java | grep $APP_NAME | awk ‘{print $2}‘`echo "$tpid"if [ ${tpid} ] ;thenkill -9 $tpidecho "kill" ${APP_NAME} "success"elseecho ${APP_NAME} "stopped"fi
原文地址:https://www.cnblogs.com/sw-123/p/10970077.html
时间: 2024-11-10 01:12:04