zoukankan      html  css  js  c++  java
  • Shell脚本:jar包启停

    在日常工作中经常会启停服务,故整理成脚本,方便操作。

    shell脚本内容如下:(exe.sh)

    #!/bin/bash
    
    package_name=flink-0.0.1-SNAPSHOT.jar
    #current_path=/data
    
    #入参检查
    if [ $# -ne 1 ];
    then
        echo -e "-->Error! Please enter the param, such as 33[33m [start/status/stop/restart] or [1/2/3/4] 33[0m"
        echo -e "-->Example : ./exe.sh start"
        exit 1
    fi
    
    
    function Start(){
        nohup java -jar $package_name  > nohup.log 2>&1 &
        sleep 2
        echo "进程状态:"
        Status
    }
    
    function Status(){
        echo "进程状态:"
        ps -ef | grep $package_name | grep -v grep
    }
    
    function Stop(){
        pid=`ps -ef | grep $package_name | grep -v grep| awk {'print $2'}`
        kill -9 $pid
    }
    
    function Restart(){
        Stop
        Start
    }
    
    if [ $1 == "start" ] || [ $1 == "1" ];
    then    
        Start
        
    elif [ $1 == "status" ] || [ $1 == "2" ];
    then
        Status
    
    elif [ $1 == "stop" ] || [ $1 == "3" ];
    then
        Stop
    
    elif [ $1 == "restart" ] || [ $1 == "4" ];
    then
        Restart
    else
        echo -e "--> 33[33m The param you enter is wrong! Please retry! 33[0m" $1
        echo -e "--> 33[33m The param is [start/status/stop/restart] or [1/2/3/4] 33[0m"
    fi

    使用方法:

    ./exe.sh [start/status/stop/restart]

    或者

    ./exe.sh [1/2/3/4]

  • 相关阅读:
    团队项目-第一阶段冲刺-5
    用户场景分析
    第九周总结
    团队项目-第一阶段冲刺-3
    团队项目-第一阶段冲刺-2
    团队项目-第一阶段冲刺-1
    个人工作任务认领
    实验一:个人博客
    MFC onpaint() ondraw()
    MFC 虚函数与消息映射区别
  • 原文地址:https://www.cnblogs.com/gongxr/p/13182237.html
Copyright © 2011-2022 走看看