jar包项目常用脚本

jar包项目常用脚本

将脚本放在jar包同级目录下,每次更新时将老的jar包文件备份,最新包放在脚本同级目录

#!/bin/bash
source /etc/profile
#
path=$(cd `dirname $0`;pwd)
JAVA_OPTS="-Dlog4j2.formatMsgNoLookups=true"
port=8082
cd $path
jar_pkg=`ls |grep 'xxl-job-admin' |awk 'END {print}'`

start(){
    pid=`lsof -i:$port | grep -v grep | awk '{print $2}' | grep -v PID`
    sleep 2
    if [ "$pid" = "" ];then
        echo
        echo "Service start running!"
        echo ' ' >nohup.out
        echo
        sleep 2
        nohup java "$JAVA_OPTS"  -jar  ${jar_pkg} &
        sleep 2
        new_pid=`ps -ef |grep $jar_pkg  | grep -v grep | awk '{print $2}'`
        sleep 2
        echo 
        echo "Service process started,new PID is $new_pid!"
        echo
    else
        echo
        echo "Service is running, no need to start again,PID is $pid!"
        echo
    fi
}

stop(){
    pid=`lsof -i:$port | grep -v grep | awk '{print $2}' | grep -v PID`
    if [ -z "${pid}" ];then
        echo
        echo "Service is not running!"
        echo
    else
        echo
        echo "Service be stoping!"
        kill -9 $pid
        sleep 2
        echo
        echo "Service process stopped!"
        echo
    fi
}

status(){
    pid=`lsof -i:$port | grep -v grep | awk '{print $2}' | grep -v PID`
    if [ -z $pid ];then
        echo "Service is not running"
    else
        echo "Service is running, PID is $pid!"
    fi
}

case "$1" in
start) 
start  
;;  
stop)  
stop  
;; 
status)
status
;;   
restart) 
stop  
start  
;;  
*)  
echo 'Only param {start|stop|status|restart} is supported!'
exit 1  
;;  
esac

检测web服务是否正常

#!/bin/bash
# Need set CURL_CA_BUNDLE enviroment cacert.pem
#PATH=/home/test/xxl_job/xxl-admin
path=$(cd `dirname $0`;pwd)
url="https://192.168.0.21:8088/xxl-job-admin/jobinfo"
port=9080
#
cd $path
#http_status=` curl -k -i -s -m 10  $url |grep HTTP  |awk '{print $2}'`
http_status=` curl -k -o  /dev/null -s -m 10 --connect-timeout 10 -w %{http_code}  $url`
#
code=`echo $http_status`
    if [ "$code" == "200" ]; then

        echo `date` "The request is successful, and the response code is$code " >> /dev/null
    else 
        echo
        echo `date` "The request failed, the response code is$code,restarting the xxl job admin service!" >> $path/monitor.log
        $path/xxl-job-admin.sh restart
	sleep 10
        newpid=`lsof -i:$port | grep -v grep | awk '{print $2}' | grep -v PID`
        echo
        echo `date` "xxl-job-admin service was restarted successfully. The new PID is$newpid!" >> $path/monitor.log
    fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值