linxu restart command file

touch restart_xxx.sh

vi restart_xxx.sh

chmod 777 restart_xxx.sh

Copy the content into the file, modify the first 3 lines and you can use it

###################################################################################

 

#!/bin/bash

 

 

JAVA_HOME="/usr/local/java/jdk1.8" ###jdk 

APP_MAINCLASS="QuestionnaireApi" ###QuestionnaireApi.jar

APP_HOME="/home/java/QuestionnaireApi" ####/home/java/QuestionnaireApi/***

#java?..?Coax.?ㄥ.?

JAVA_OPTS="-ms512m -mx512m -Xmn256m -Djava.awt.headless=true -XX:MaxPermSize=128m  -Dfile.encoding=UTF-8  "

 

 

 

psid=0

 

##########################################checkpid()#################################

checkpid() {

   javaps=`$JAVA_HOME/bin/jps -l | grep $APP_MAINCLASS`

   if [ -n "$javaps" ]; then

      psid=`echo $javaps | awk '{print $1}'`

   else

      psid = 0 #### [$ psid -no 0]

   be

 

 

echo "checkpid:"+$psid

}

 

 

 

 

##########################################start ()#################################

start() {

   checkpid

   if [ $psid -ne 0 ]; then

      echo "================================"

      echo "warn: $APP_MAINCLASS already started! (pid=$psid)"

      echo "================================"

   else

      echo -n "Starting $APP_MAINCLASS ..."

 nohup $JAVA_HOME/bin/java $JAVA_OPTS -jar $APP_HOME/$APP_MAINCLASS.jar > /dev/null 2>&1 &

      checkpid

      if [ $psid -ne 0 ]; then

         echo "(pid=$psid) [start OK]"

      else

         echo "[start Failed]"

start

      be

   be

}

 

 

##########################################stoppid()#################################

 

stop() {

   checkpid

   if [ $psid -ne 0 ]; then

      echo -n "Stopping $APP_MAINCLASS ...(pid=$psid) "

      kill   $psid

      if [ $? -eq 0 ]; then

         echo "[stop OK]"

      else

         echo "[stop Failed]"

      be

 

      checkpid

      if [ $psid -ne 0 ]; then

         stop ###Nan...?..

      be

   else

      echo "================================"

      echo "warn: $APP_MAINCLASS is not running"

      echo "================================"

   be

}

 

 

##########################################status ()#################################

status() {

   checkpid

   if [ $psid -ne 0 ];  then

      echo "$APP_MAINCLASS is running! (pid=$psid) and run time is :"

      ps -p  $psid -o pid,etime,uid,gid

   else

      echo "$APP_MAINCLASS is not running"

   be

}

 

##########################################info)#################################

info() {

   echo "System Information:"

   echo "****************************"

   echo `head -n 1 /etc/issue`

   echo `uname -a`

   echo

   echo "JAVA_HOME=$JAVA_HOME"

   echo `$JAVA_HOME/bin/java -version`

   echo

   echo "APP_HOME=$APP_HOME"

   echo "APP_MAINCLASS=$APP_MAINCLASS"

   echo "****************************"

}

##########################################on ()##### ###########################

 

 

case "$1" in

   'start')

      start

      ;;

   'stop')

     stop

     ;;

   'restart')

     stop

     start

     ;;

   'status')

     status

     ;;

   'info')

     info

     ;;

  *)

     echo "Usage: $0 {start|stop|restart|status|info}"

     exit 1

esac

exit 0

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397041&siteId=291194637