Java web 应用自启动 shell脚本自动重启

之前公司的内部管理系统jenkins自动构建代码有时候会失效,导致服务停掉。

于是乎就搞了一个自动启动脚本。

oa.jar就是监测的服务

startup.sh 的内容是运行jar包的命令

java -jar oa.jar --spring.profiles.active=xxx &

#!/bin/bash

while :

do

  echo "Current DIR is " $PWD

  stillRunning=$(ps -ef |grep "$PWD/oa.jar" |grep -v "grep")

  if [ "$stillRunning" ] ; then

    echo "TWS service was already started by another way"

    echo "Kill it and then startup by this shell, other wise this shell will loop out this message annoyingly"

    kill -9 $pidof $PWD/oa.jar

  else

    echo "TWS service was not started"

    echo "Starting service ..."

    $PWD/startup.sh

    echo "TWS service was exited!"

  fi

  sleep 30

done

猜你喜欢

转载自www.cnblogs.com/wendao1996/p/11134217.html