zoukankan      html  css  js  c++  java
  • linux批量启动jar包

    先附上命令语句

    #!/bin/sh
    #当前目录全路径
    pp=$(pwd)
    export DEMO1=$pp/demo1-8080.jar
    export DEMO2=$pp/demo2-8082.jar
     
    export DEMO1_port=8080
    export DEMO2_port=8082
     
    case "$1" in
     
    start)
            ## 启动DEMO1
            echo "DEMO1开始启动----------------------"
            echo 'str:'$DEMO1''
            nohup java -Xms256m -Xmx256m -jar $DEMO1 1>>./out.log 2>&1 &
            DEMO1_pid=`lsof -i:$DEMO1_port|grep "LISTEN"|awk '{print $2}'`
            until [ -n "$DEMO1_pid" ]
                do
                  DEMO1_pid=`lsof -i:$DEMO1_port|grep "LISTEN"|awk '{print $2}'`  
                done
            echo "----------------------DEMO1启动成功pid:$DEMO1_pid"
            
            ## 启动DEMO2
            echo "DEMO2开始启动--------------------------"
            echo 'str:'$DEMO2''
            nohup java -Xms256m -Xmx256m -jar $DEMO2 1>>./out.log 2>&1 &
            DEMO2_pid=`lsof -i:$DEMO2_port|grep "LISTEN"|awk '{print $2}'` 
            until [ -n "$DEMO2_pid" ]
                do
                  DEMO2_pid=`lsof -i:$DEMO2_port|grep "LISTEN"|awk '{print $2}'`  
                done  
            echo "--------------------------DEMO2启动成功pid:$DEMO2_pid"
            echo "===startAll success==="
            ;;
     
     stop)
            P_ID=`ps -ef | grep -w $DEMO1 | grep -v "grep" | awk '{print $2}'`
            if [ "$P_ID" == "" ]; then
                echo "===DEMO1 process not exists or stop success"
            else
                kill -9 $P_ID
                echo "DEMO1 killed success"
            fi
            P_ID=`ps -ef | grep -w $DEMO2 | grep -v "grep" | awk '{print $2}'`
            if [ "$P_ID" == "" ]; then
                echo "===DEMO2 process not exists or stop success"
            else
                kill -9 $P_ID
                echo "DEMO2 killed success"
            fi
     
            echo "===stop success==="
            ;;   
     
    restart)
            $0 stop
            sleep 2
            $0 start
            echo "===restart success==="
            ;;   
    esac    
    exit 0
    View Code

    执行命令报错:

    后查找原因:

    发现是win系统文件上传到linux默认加字符,使用命令执行语句:

    sed -i 's/ $//' 【名字】.sh

    再次启动:

     成功。

  • 相关阅读:
    phpMyAdmin导入大的sql文件
    mysql错误代码解释
    Sphinx在windows下安装使用[支持中文全文检索]
    Linux查看磁盘分区等命令和相关工具介绍
    webuploader大小限制
    常用的C#正则表达式!
    C# csv.excel导入
    日志
    微信
    winform窗口控件随窗口变化
  • 原文地址:https://www.cnblogs.com/cjll/p/13724050.html
Copyright © 2011-2022 走看看