7

I want to write a script to manage the WildFly start and deploy, but I'm having trouble now. To check if the server has started, I found the command

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

But when the server is starting, because the controller is not available, ./jboss-cli.sh -c fails to connect and returns an error.

Is there a better way to check whether WildFly started completely?

TT.
  • 15,774
  • 6
  • 47
  • 88
Germinate
  • 2,008
  • 2
  • 14
  • 23

1 Answers1

8

I found a better solution. The command is

netstat -an | grep 9990 | grep LISTEN

Check the management port (9990) state before the WildFly is ready to accept management commands.

After that, use ./jboss-cli.sh -c command=':read-attribute(name=server-state)' | grep running to check if the server has started. Change the port if the management port config is not the default 9990.

Here is my start & deploy script, the idea is continually check until the server started.

Then, use the jboss-cli command to deploy my application. And just print the log to the screen, so don't need to use another shell to tail the log file.

#!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
TT.
  • 15,774
  • 6
  • 47
  • 88
Germinate
  • 2,008
  • 2
  • 14
  • 23
  • Very nice solution. I like it. I will take it over. – slawek Feb 09 '18 at 19:55
  • What if you application didn't deploy? The port would still be open. – stdunbar Feb 10 '18 at 16:44
  • Hi, @stdunbar. After the server start, the port should always be open, so the server could accept management commands. If the application didn't deploy after the server start successfully, I can see the log shown on the screen, and then solve it. – Germinate Feb 11 '18 at 00:45