• 服务器java启动停止脚本2


    #!/bin/bash
    
    RED='E[1;31m'      # 红
    GREEN='E[1;32m'    # 绿
    YELOW='E[1;33m'    # 黄
    BLUE='E[1;34m'     # 蓝
    PINK='E[1;35m'     # 粉红
    RES='E[0m'         # 清除颜色
    #当前线程日志所在位置
    logfile=/opt/kafka-consumer/logs/app.log 
    #执行需要的jdk环境位置 
    JavaPath=/usr/java/jdk/jre/lib/ext/
    #执行需要的项目JAR目录 
    mylibPath=/opt/kafka-consumer/
    #app名称
    appName=`ls|grep .jar$`
    cd $mylibPath
    if [ -z $appName ]
    then
        echo "Please check that this script and your jar-package is in the same directory!"
        exit 1
    fi
    
    killForceFlag=$2
    
    function start()
    {
        count=`ps -ef |grep java|grep $appName|wc -l`
        if [ $count != 0 ];then
            echo -e "${YELOW} Maybe $appName is running, please check it...${RES}"
        else
            echo -e "${GREEN} The $appName is starting...33[0m"
            nohup java -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512M -Xmx4G -jar $appName &
        fi
    }
    
    function stop()
    {
        appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        if [ -z $appId ]
        then
            echo -e "${YELOW} Maybe $appName not running, please check it...${RES}"
        else
            echo -e "${GREEN} The $appName is stopping...${RES}"
            if [ "$killForceFlag" == "-f" ]
            then 
                echo "by force"
                kill -9 $appId
            else
                echo
                kill $appId
            fi
        fi
    }
    
    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 restart()
    {
        stop
        for i in {3..1}
        do
            echo -n "$i "
            sleep 1
        done
        echo 0
        start
    }
    
    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
  • 相关阅读:
    回顾C#3.0新特性(3)
    第五周作业
    第六周基础作业
    第三周syh
    基础作业
    第七周作业
    2019年春季学期第四周作业
    第八周作业
    .Net 反射
    C#中SqlParameter
  • 原文地址:https://www.cnblogs.com/zk-blog/p/14274125.html
Copyright © 2020-2023  润新知