Browse Source

增加shell检测服务器

xiewenjie 3 years ago
parent
commit
a1469b64c4
1 changed files with 23 additions and 5 deletions
  1. 23 5
      startJar.sh

+ 23 - 5
startJar.sh

@@ -1,24 +1,25 @@
 APP_NAME=
 APP_DEBUG=
 APP_DUMPlOG=/mnt/change/heapdump/heapdump.log
+date=`date`
 usage() {
-    echo "case: sh run.sh [start|stop|restart|status]"
-    echo "请类似这样执行 ./*.sh start   or  ./*sh restart"
+    echo "case: sh run.sh [start|stop|restart|status|checkServer]"
+    echo "请类似这样执行 ./*.sh start prod  or  ./*sh restart prod"
     exit 1
 }
 
 checkEnv(){
       if [ -z "${APP_NAME}" ] || [ -z "${APP_DEBUG}" ]; then #判断pid是否为空
            if [[ $1 = 'prod' ]];   then
-                        echo "prod start"
+                        echo "prod config"
                         APP_NAME=changeing-prod.jar
                         APP_DEBUG=5526
                       elif  [[ $1 = 'uat' ]] ; then
-                        echo "uat start"
+                        echo "uat config"
                         APP_NAME=changeing-uat.jar
                         APP_DEBUG=5520
                       elif  [[ $1 = 'devuat' ]] ; then
-                        echo "devuat start"
+                        echo "devuat config"
                         APP_NAME=changeing-devuat.jar
                         APP_DEBUG=5526
                       else
@@ -80,6 +81,20 @@ status(){
     fi
 }
 
+checkServer(){
+    echo "执行 status 方法"
+    checkEnv $1
+    is_exist
+    if [ $? -eq "0" ]; then
+        echo "${APP_NAME} running-正在运行. Pid is ${pid}"
+        echo `date +%Y-%m-%d` `date +%H:%M:%S` ${APP_NAME} "running-正在运行. Pid is ${pid}" >> check.log
+        exit 0
+    else
+        echo "${APP_NAME} 没有运行,即将重启"
+        echo `date +%Y-%m-%d` `date +%H:%M:%S` ${APP_NAME} "没有运行,即将重启" >> check.log
+        restart
+    fi
+}
 
 # 重启命令其实就是先执行关闭命令 再执行重启命令
 restart(){
@@ -117,6 +132,9 @@ case "$1" in
     "restart")
         restart $2
         ;;
+    "checkServer")
+        checkServer $2
+        ;;
     *)
     usage
     ;;