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