gpt4 book ai didi

wildfly - 如何使用命令/脚本检查 WildFly 服务器是否已成功启动?

转载 作者:行者123 更新时间:2023-12-03 16:05:03 27 4
gpt4 key购买 nike

我想编写一个脚本来管理 WildFly 启动和部署,但我现在遇到了麻烦。要检查服务器是否已启动,我找到了命令
./jboss-cli.sh -c command=':read-attribute(name=server-state)' | grep running
但是服务器启动的时候,因为 Controller 不可用,./jboss-cli.sh -c连接失败并返回错误。

有没有更好的方法来检查 WildFly 是否完全启动?

最佳答案

我找到了更好的解决方案。命令是

netstat -an | grep 9990 | grep LISTEN

在 WildFly 准备好接受管理命令之前检查管理端口 (9990) 状态。

之后,使用 ./jboss-cli.sh -c command=':read-attribute(name=server-state)' | grep running检查服务器是否已启动。更改端口
如果管理端口配置不是默认的 9990。

这是我的 启动和部署 脚本,这个想法是不断检查,直到服务器启动。

然后,使用 jboss-cli命令来部署我的应用程序。并且只需将日志打印到屏幕上,因此不需要使用另一个 shell 来拖尾日志文件。
#!bin/sh
totalRow=0
printLog(){ #output the new log in the server.log to screen
local newTotal=$(awk 'END{print NR}' ./standalone/log/server.log) #quicker than wc -l
local diff=$(($newTotal-$totalRow))
tail -n $diff ./standalone/log/server.log
totalRow=$newTotal
}

nohup bin/standalone.sh>/dev/null 2>&1 &
echo '======================================== Jboss-eap-7.1 is starting now ========================================'
while true #check if the port is ready
do
sleep 1
if netstat -an | grep 9990 | grep LISTEN
then
printLog
break
fi
printLog
done
while true #check if the server start success
do
if bin/jboss-cli.sh --connect command=':read-attribute(name=server-state)' | grep running
then
printLog
break
fi
printLog
sleep 1
done
echo '======================================== Jboss-eap-7.1 has started!!!!!! ========================================'
bin/jboss-cli.sh --connect command='deploy /bcms/jboss-eap-7.1/war/myApp.war' &
tail -f -n0 ./standalone/log/server.log

关于wildfly - 如何使用命令/脚本检查 WildFly 服务器是否已成功启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48702307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com