当前位置: 首页 > article >正文

linux环境执行jar脚本

一、前言

平常工作中,我们的开发的项目部署到linux环境,以jar包的方式运行,涉及jar包的启动、停止、查看状态等,我们可以通过脚本的方式进行维护,减少自己敲打一长串的命令少敲一个字母或者多敲一个字母,方便维护。

二、脚本

vim  app.sh

#!/bin/bash

appName=xxxx.jar
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 "Maybe $appName is running, please check it..."
    else
        echo "The $appName is starting..."
        nohup java -jar $appName --spring.profiles.active=test >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 -n "The $appName is stopping..."
        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 "\033[31m Not running \033[0m"
    else
        echo -e "\033[32m Running [$appId] \033[0m"
    fi
}

function restart()
{
    stop
    for i in {3..1}
    do
        echo -n "$i "
        sleep 1
    done
    echo 0
    start
}

function help()
{
    echo "Usage: $0 {start|stop|restart|status|stop -f}"
    echo "Example: $0 start"
    exit 1
}

function taillog()
{
   tail -f -n 1000 log.out
}

case $1 in
    start)
    start;;

    stop)
    stop;;

    restart)
    restart;;

    status)
    status;;

    taillog)
    taillog;;

    *)
    help;;
esac

三、授权及命令

chmod   +x      app.sh

启动:app.sh  start    

停止:app.sh  stop -f

查看状态 app.sh  status


http://www.kler.cn/a/103856.html

相关文章:

  • “编辑微信小程序与后台数据交互与微信小程序wxs的使用“
  • 【Qt之QSetting】介绍及使用
  • 【从0到1设计一个网关】什么是网关?以及为什么需要自研网关?
  • 使用udevil自动挂载U盘或者USB移动硬盘
  • SpringBoot的日志系统(日志分组、文件输出、滚动归档)
  • Docker镜像仓库
  • 正点原子嵌入式linux驱动开发——Linux INPUT子系统
  • freeRTOS内部机制——栈的作用
  • HotReload For Unity的文档的导航的翻译,添加了一些自己的理解。很垃圾
  • 【德哥说库系列】-PostgreSQL跨版本升级
  • 优橙内推海南专场——5G网络优化(中高级)工程师
  • Unity 中使用波浪动画创建 UI 图像
  • Spring Cloud之声明式服务调用(Feign)
  • 【数据结构】【C语言】【环形链表约瑟夫问题】
  • 虚拟机kafka
  • 通俗介绍:什么是 Redis ?
  • Android 得到安装包的信息
  • 网络协议--IGMP:Internet组管理协议
  • Unity之ShaderGraph如何实现全息投影效果
  • ModbusTCP 转 Profinet 主站网关在博图配置案例