eclipse—在bash中监视tomcat,直到它完成war或应用程序的部署

6qfn3psc  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(472)

如何在bash脚本中监视tomcat,以检测它是否完成了war或应用程序的部署?
情节:
tomcat从 systemd tomcat从 catalina.sh 使用tomcat管理器
tomcat是从eclipse开始的
springboot上的嵌入式tomcat
我的答案如下。

5anewei6

5anewei61#

具有 systemd 如果您使用systemctl启动tomcat,或者catalina.sh使用systemctl,则可以执行类似的操作。改变 demo.war 根据您的战争名称,调整睡眠时间以显示尽可能多的睡眠时间 . (点)根据需要。如果部署需要30秒,它将显示30个点。

while ! systemctl status tomcat --no-pager | grep -q 'Deployment of.*demo.war.* has finished'; do \
echo -ne "."; sleep 1; \
done && echo "War deployed"

具有 catalina.sh 如果 catalina.sh run 使用来自apache的包(使用 catalina.sh start (不起作用)

while read -r line; do
    if echo "$line" | grep -q 'Deployment of.*[/]demo.war.* has finished' ; then
        echo "*****$line"
        # do some stuff with your app
        break
    else
        echo "---- $line"
    fi
done < <(./bin/catalina.sh run 2>&1 &) && echo "War deployed"

# start tomcat ----------^

# with console output but in background

./bin/catalina.sh stop

监控日志文件
可能需要对日志文件的权限。

log='/var/log/tomcat/catalina.2021-07-05.log'
msg='Deployment of.*[/]demo.war.* has finished'
while read -r line; do
    if echo "$line" | grep -q "$msg" ; then
        echo "*****$line"
        # do some stuff with your app
        break
    else
        echo "---- $line"
    fi
done < <(tail -n 1 -f "$log")
echo "War deployed"
sleep 5 # get a chance to see the previous message :-p

如果从eclipse启动tomcat

log='/home/lmc/workspace/.metadata/.plugins/org.eclipse.wst.server.core/logs/catalina.out'
msg='Deployment of deployment descriptor .*demo.xml. has finished'

# same code as above

和tomcat经理
配置tomcat管理器后:

until ! curl -u userblah:s3cr3t --silent "http://localhost:8080/manager/text/list" | grep '^[/]demo:running'; do
    echo "Deploying 'demo' app"
    sleep 1
done

带Spring Boot执行器
如果您的spring boot应用程序使用spring boot actuator并配置为

management.endpoints.web.exposure.include=health
management.endpoints.web.base-path=/actuator
management.server.port=8081
management.server.address=127.0.0.1

可通过以下方式对其进行监控:

until curl --silent "http://127.0.0.1:8081/actuator/health" | grep -q 'status":"UP'; do
    echo "Deploying 'demo' app"
    sleep 1
done
echo "is UP"

相关问题