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

7
我想编写一个脚本来管理WildFly的启动和部署,但目前遇到了困难。为了检查服务器是否已经启动,我找到了以下命令: ./jboss-cli.sh -c command=':read-attribute(name=server-state)' | grep running 但当服务器正在启动时,由于控制器不可用,./jboss-cli.sh -c无法连接并返回错误。
有没有更好的方法来检查WildFly是否完全启动?
1个回答

8
我找到了更好的解决方案。命令是:
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

非常好的解决方案。我喜欢它。我会采用它。 - slawek
如果您的应用程序没有部署,那么端口仍然会保持开放。 - stdunbar
嗨,@stdunbar。服务器启动后,端口应始终保持开放状态,以便服务器可以接受管理命令。如果应用程序在服务器成功启动后未部署,则我可以查看屏幕上显示的日志,然后解决问题。 - Germinate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接