zoukankan      html  css  js  c++  java
  • 快速启动jar包脚本【Linux】

    快速启动jar包脚本【Linux】

    备注:从Windows拷贝到Linux会出现编译器错误

    参考作者这篇博客:https://www.cnblogs.com/zhanqing/p/15305362.html

    #!/bin/bash
    version="1.0.1";
    
    appName=$2
    if [ -z $appName ];then
        appName=`ls -t |grep .jar$ |head -n1`
    fi
    
    function start()
    {
            count=`ps -ef |grep java|grep $appName|wc -l`
            if [ $count != 0 ];then
                    echo "Maybe $appName is running, please check it..."
            else
                    echo "The $appName is starting..."
                    nohup java -Xms512m -Xmx512m -Xmn256m -Xloggc:./gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -jar ./$appName > ./app-log.out 2>&1 &
            fi
    }
    
    function stop()
    {
            appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
            if [ -z $appId ];then
                echo "Maybe $appName not running, please check it..."
            else
            echo "The $appName is stopping..."
            kill -9 $appId
            fi
    }
    
    function restart()
    {
        # get release version
        releaseApp=`ls -t |grep .jar$ |head -n1`
    
        # get last version
        lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
    
        appName=$lastVersionApp
        stop
        for i in {5..1}
        do
            echo -n "$i "
            sleep 1
        done
        echo 0
    
        backup
    
        appName=$releaseApp
        start
    }
    
    function backup()
    {
        # get backup version
        backupApp=`ls |grep -wv $releaseApp$ |grep .jar$`
    
        # create backup dir
        if [ ! -d "backup" ];then
            mkdir backup
        fi
    
        # backup
        for i in ${backupApp[@]}
        do
            echo "backup" $i
            mv $i backup
        done
    }
    function status()
    {
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
            if [ -z $appId ]
            then
                echo -e "33[31m Not running 33[0m"
            else
                echo -e "33[32m Running [$appId] 33[0m"
            fi
    }
    
    
    function usage()
    {
        echo "Usage: $0 {start|stop|restart|status|stop -f}"
        echo "Example: $0 start"
        exit 1
    }
    
    case $1 in
            start)
            start;;
    
            stop)
            stop;;
    
            restart)
            restart;;
    
            status)
            status;;
    
            *)
            usage;;
    esac
  • 相关阅读:
    5th-个人总结(Alpha阶段)
    4th-结对编程2
    3rd-Bing Dict使用分析
    1st_homework_SE--四则运算题目生成器
    附加作业
    个人作业(3)----个人总结(Alpha阶段)
    结对作业(2)----单元测试
    个人作业(2)----英语学习APP案例分析
    结对作业(1)----基于GUI的四则运算
    (Alpha)个人总结
  • 原文地址:https://www.cnblogs.com/zhanqing/p/15306867.html
Copyright © 2011-2022 走看看