Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 880
Germinate Avatar asked Feb 09 '18 09:02

Germinate


People also ask

How do I check WildFly server status?

The simplest way to check the status of an application running on JBoss / WildFly is to use the CLI tool and the deployment-info command.

How do I know if my jboss server is running?

Starting the server and checking the status However, the jps command line is available upon JDK installation. Therefore, you can use the jps command to check the server status. When the server stops, the startup-marker file will be removed.

How do I run WildFly on command prompt?

To start up a WildFly 8 managed domain, execute the $JBOSS_HOME/bin/domain.sh script. To start up a standalone server, execute the $JBOSS_HOME/bin/standalone.sh. With no arguments, the default configuration is used.

How do I know if jboss is starting?

2.2. Let's open a terminal in OSX/Linux or a command prompt in Windows and navigate to the $JBOSS_HOME/bin directory. Furthermore, to check if the startup is successful, we can open up a browser and navigate to http://localhost:8080/. It'll show the default WildFly welcome page.


1 Answers

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
like image 121
Germinate Avatar answered Sep 28 '22 02:09

Germinate