多條告白如次劇本只需引入一次
一個通用的java運用步調(diào)啟用shell劇本:
#!/bin/bashcd`dirname$0`CUR_SHELL_DIR=`pwd`CUR_SHELL_NAME=`basename${BASH_SOURCE}`#竄改這邊jar包名即可JAR_NAME="console.jar"JAR_PATH=$CUR_SHELL_DIR/$JAR_NAME#JAVA_MEM_OPTS="-server-Xms1024m-Xmx1024m-XX:PermSize=128m"JAVA_MEM_OPTS=""#SPRING_PROFILES_ACTIV="-Dspring.profiles.active=prod"SPRING_PROFILES_ACTIV=""JAR_LIB="-Dloader.path=libs/"echo_help(){echo-e"syntax:sh$CUR_SHELL_NAMEstart|stop"}if[-z$1];thenecho_helpexit1fiif["$1"=="start"];then#checkserverPIDS=`ps--no-heading-Cjava-f--width1000|grep$JAR_NAME|awk'{print$2}'`if[-n"$PIDS"];thenecho-e"ERROR:The$JAR_NAMEalreadystartedandthePIDis${PIDS}."exit1fiecho"Startingthe$JAR_NAME..."#startnohupjava$JAR_LIB$JAVA_MEM_OPTS-jar$SPRING_PROFILES_ACTIV$JAR_PATH>>/dev/null2>&1&COUNT=0while[$COUNT-lt1];dosleep1COUNT=`ps--no-heading-Cjava-f--width1000|grep"$JAR_NAME"|awk'{print$2}'|wc-l`if[$COUNT-gt0];thenbreakfidonePIDS=`ps--no-heading-Cjava-f--width1000|grep"$JAR_NAME"|awk'{print$2}'`echo"${JAR_NAME}StartedandthePIDis${PIDS}."elif["$1"=="stop"];thenPIDS=`ps--no-heading-Cjava-f--width1000|grep$JAR_NAME|awk'{print$2}'`if[-z"$PIDS"];thenecho"ERROR:The$JAR_NAMEdoesnotstarted!"exit1fiecho-e"Stoppingthe$JAR_NAME..."forPIDin$PIDS;dokill$PID>/dev/null2>&1doneCOUNT=0while[$COUNT-lt1];dosleep1COUNT=1forPIDin$PIDS;doPID_EXIST=`ps--no-heading-p$PID`if[-n"$PID_EXIST"];thenCOUNT=0breakfidonedoneecho-e"${JAR_NAME}StoppedandthePIDis${PIDS}."elseecho_helpexit1即使您愛好正文,就請動動您的發(fā)達手為正文點贊指摘轉(zhuǎn)發(fā),讓咱們一道進修更多運維關(guān)系常識,結(jié)果請牢記關(guān)心我。