zoukankan      html  css  js  c++  java
  • 运行jar包shell脚本

    #!/bin/sh
    #该文件必须放在jar包的目录下,因为是以相对路径来运行的。不放jar包目录的话,可以直接在jar_name参数写绝对路径
    #start 设置三个参数 
    #环境
    profile=test
    #jar的路径和名称
    jar_name=zhong-auth.jar
    #远程断点端口
    remote_address=
    #end 设置三个参数
    echo "运行$jar_name"
    #查询进程,并杀掉当前jar/java进程
    pid=`ps -ef|grep $jar_name|grep -v grep|awk '{print $2}'`
    echo "进程为$pid"
    kill -9 $pid
    echo "$pid进程终止成功"
    sleep 2
    #判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
    if test -e $jar_name
    then
    echo "$jar_name存在,开始启动此程序..."
        # 判断是否有远程断点端口
        if test -z "$remote_address"
        then
          # 启动jar包
          nohup java -Xms64m -Xmx128m -jar $jar_name --spring.profiles.active=$profile >/dev/null 2>&1 &
          echo "远程断点端口为空"
        else  
          # 启动jar包
          nohup java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$remote_address -Xms64m -Xmx128m -jar $jar_name --spring.profiles.active=$profile >/dev/null 2>&1 &
          echo "远程断点端口为$remote_address"
        fi
    echo "$jar_name 启动成功..."
    pid=`ps -ef|grep $jar_name|grep -v grep|awk '{print $2}'`
    echo "新进程为$pid"
    else
    echo "$jar_name 文件不存在,请检查。"
    fi

    第一次运行的时候获取一下超级管理员权限
    chmod +x start.sh

    拷贝脚本的时候运行的时候如果报错,应该是文件格式转换的问题
    bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory
    yum -y install dos2unix
    dos2unix start.sh

    或者

    vi start.sh
    查看文件的格式
    :set ff
    设置文件的格式
    :set ff=unix
    保存
    :wq

  • 相关阅读:
    由DBCursor的“can't switch cursor access methods”异常引发的思考
    在Java中使用元组类型的利器
    Linux命令行如何返回上一次的目录
    Linux下通过crontab命令来实现定时任务
    Spark任务踩到的坑
    Hadoop HDFS命令学习笔记
    Spark RDD学习笔记
    HBase的基本操作
    一张图5分钟熟悉MarkDown的基本语法
    C#跨线程操作控件的最简单实现探究
  • 原文地址:https://www.cnblogs.com/suruozhong/p/11897592.html
Copyright © 2011-2022 走看看