如何使用命令/脚本检查WildFly Server是否已成功启动?

Ger*_*ate 2 wildfly jboss-eap-7

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

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

但是当服务器启动时,由于控制器不可用,因此./jboss-cli.sh -c无法连接并返回错误。

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

Ger*_*ate 5

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

netstat -an | grep 9990 | grep LISTEN
Run Code Online (Sandbox Code Playgroud)

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

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

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

然后,使用jboss-cli命令部署我的应用程序。并且只需将日志打印到屏幕上,因此不需要使用其他外壳作为日志文件的尾部。

#!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
Run Code Online (Sandbox Code Playgroud)