linux系统应用程序启动脚本

1.run.sh

bash 复制代码
#!/bin/bash
version="1.0.0";

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 -Dloader.path=./lib  -jar ./$appName  -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms1G -Xmx4G > /dev/null 2>&1 &
        fi
}

function stop()
{
#       appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
        appId=$(cat ./logs/abk.pid)

        if [ -z $appId ];then
            echo "Maybe $appName not running, please check it..."
        else
        echo "The $appName is stopping..."
        kill $appId
        rm -rf ./logs/abk.pid

        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 "\033[31m Not running \033[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

2.start.sh

bash 复制代码
#!/bin/bash
## Author ly
version="1.0.0";
./run.sh start

3.其他

其他的stop.shrestart.sh写法同start.sh

相关推荐
不想学习!!15 分钟前
linux之进程控制
java·linux·服务器
良许Linux16 分钟前
学电子信息工程时你遇到什么相见恨晚的网站和学习方法?
linux
良许Linux19 分钟前
一个人离职前有什么征兆?
linux
神经毒素23 分钟前
WEB安全--文件上传漏洞--36C3 CTF includer bypass
linux·安全·web安全
良许Linux29 分钟前
单片机、嵌入式的大神都平时浏览什么网站?
linux
kfepiza33 分钟前
`accept_ra` 和 `autoconf` 和 `forwarding` 的关系 笔记250404
linux·网络·笔记·tcp/ip·智能路由器·ip·tcp
DADIAN_GONG42 分钟前
incomplete command on Huawei switch
linux·运维·华为
Once_day1 小时前
Linux错误(6)X64向量指令访问地址未对齐引起SIGSEGV
linux·c++·sse·x64·sigsegv·xmm0
Tee xm1 小时前
清晰易懂的 Flutter 卸载和清理教程
linux·windows·flutter·macos
小镇青年达师傅1 小时前
System V信号量 vs. POSIX信号量:核心区别与选型指南
linux·嵌入式·多线程·系统编程