如何使用command/script检查WildFly服务器是否启动成功?

How to check if a WildFly Server has started successfully using command/script?

我想写一个脚本来管理WildFly 的启动和部署,但我现在遇到了麻烦。为了检查服务器是否已经启动,我找到了命令

./jboss-cli.sh -c command=':read-attribute(name=server-state)' | grep running

但服务器启动时,由于控制器不可用,./jboss-cli.sh -c连接失败,returns出错

有没有更好的方法来检查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