zoukankan      html  css  js  c++  java
  • 我爱java系列---【linux启动项目脚本】

    linux启动项目脚本

    三个文件:更改第一个文件,其余两个直接复制粘贴

    1.project.sh文件

    JAVA_HOME=$JAVA_HOME
    
    JAVA_OPTS="-Xms5120m -Xmx5120m -XX:+UseParallelGC"
    
    MAIN_CLASS=db-proxy             //改成自己的jar包上级目录名
    JAR_PATH=db-proxy-0.0.1-SNAPSHOT.jar    //改成自己的jar包名
    
    psid=0
    execstop=0
    
    checkpid() {
       pidfile="process.pid"
    
       if [ -f $pidfile ]; then
          psid=$(cat $pidfile)
       else
          psid=0
       fi
    }
    
    start() {
     
       checkpid
       cd ../ 
       if [ $psid -ne 0 ]; then
          echo "warn: $MAIN_CLASS already started! (pid=$psid)"
       else
          echo -n "Starting $MAIN_CLASS ..."
          nohup $JAVA_HOME/bin/java $JAVA_OPTS -jar $JAR_PATH  > logs/out.log & echo $! > bin/process.pid
          checkpid
          if [ $psid -ne 0 ]; then
             echo "(pid=$psid) [OK]"
          else
             echo "[Failed]"
          fi
       fi
    }
    
    stop() {
       checkpid
       if [ $execstop -ne 1 ]; then
           if [ $psid -ne 0 ]; then
               echo -n "Stopping $MAIN_CLASS ...(pid=$psid) "
               kill -9 $psid
               rm -rf process.pid
               if [ $? -eq 0 ]; then
                   echo ""
                   execstop=1
                   stop
               else
                   execstop=0
                   echo "[Failed]"
               fi
            else
               echo "warn: $MAIN_CLASS is not running"
            fi
       else
           sleep 1
           echo -n "."
           if [ $psid -ne 0 ]; then
               stop
           else
               execstop=0
               echo ""
               echo "$MAIN_CLASS is stoped"
           fi
       fi
    }
    
    case "$1" in
       'start')
          start
          ;;
       'stop')
         stop
         ;;
      *)
         echo "Usage: $0 {start|stop}"
         exit 1
    esac
    exit 0

    2.start.sh文件

    G="$0"
    
    while [ -h "$PRG" ] ; do
      ls=`ls -ld "$PRG"`
      link=`expr "$ls" : '.*-> (.*)$'`
      if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
      else
        PRG=`dirname "$PRG"`/"$link"
      fi
    done
    
    PRGDIR=`dirname "$PRG"`
    
    exec "$PRGDIR"/project.sh start

    3.shutdown.sh文件

    G="$0"
    
    while [ -h "$PRG" ] ; do
      ls=`ls -ld "$PRG"`
      link=`expr "$ls" : '.*-> (.*)$'`
      if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
      else
        PRG=`dirname "$PRG"`/"$link"
      fi
    done
    
    PRGDIR=`dirname "$PRG"`
    
    exec "$PRGDIR"/project.sh stop

    4.在jar包所在的目录中创建bin目录,并进入bin目录,执行:chmod 775 * 命令(*号可以是文件名/目录名,这里*代表所有)。

    愿你走出半生,归来仍是少年!
  • 相关阅读:
    常用知识点集合
    LeetCode 66 Plus One
    LeetCode 88 Merge Sorted Array
    LeetCode 27 Remove Element
    LeetCode 26 Remove Duplicates from Sorted Array
    LeetCode 448 Find All Numbers Disappeared in an Array
    LeetCode 219 Contains Duplicate II
    LeetCode 118 Pascal's Triangle
    LeetCode 119 Pascal's Triangle II
    LeetCode 1 Two Sum
  • 原文地址:https://www.cnblogs.com/hujunwei/p/12305609.html
Copyright © 2011-2022 走看看