I have a bash script (executed by Jenkins) which calls at one point
local STATUS=$($SERVER_DIR/bin/jboss-cli.sh --controller=$WILDFLY_CONTROLLER --connect --user=$ADMIN_USER --password=$ADMIN_PW command=:shutdown --timeout=$JBOSSTIMEOUT);
The sole purpose in this snippet is to shutdown a running wildfly process. Should the call itself be successfull, but for whatever reason wildfly was not terminated I also added another check that is executed several seconds later
SERVER_PID=`ps aux | grep $SERVER_DIR | grep 'wildfly.xml' | grep -v grep | tr -s ' ' | cut -d ' ' -f 2`;
if [[ ! -z $SERVER_PID ]] ; then
kill -9 $SERVER_PID;
fi
However, from time to time - I wasnt able to figure out under which circumstances - the snippet behaves not as expected.
Problem type 1)
Calling the jboss-cli.sh results in an exception
> 2019-02-27_22-05-17 [INFO] Trying to stop wildfly service with jboss-cli.sh /opt/wildfly/bin/jboss-cli.sh --controller=10.0.1.1:9990 --connect --user=XXXX --password=XXXX command=:shutdown --timeout=120 org.jboss.as.cli.CliInitializationException: Failed to connect to the controller at org.jboss.as.cli.impl.CliLauncher.initCommandContext(CliLauncher.java:278) at org.jboss.as.cli.impl.CliLauncher.main(CliLauncher.java:241) at org.jboss.as.cli.CommandLineMain.main(CommandLineMain.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jboss.modules.Module.run(Module.java:312) at org.jboss.modules.Main.main(Main.java:460) Caused by: org.jboss.as.cli.CommandLineException: The controller is not available at 10.0.1.27:9990 at org.jboss.as.cli.impl.CommandContextImpl.tryConnection(CommandContextImpl.java:1028) at org.jboss.as.cli.impl.CommandContextImpl.connectController(CommandContextImpl.java:840) at org.jboss.as.cli.impl.CommandContextImpl.connectController(CommandContextImpl.java:819) at org.jboss.as.cli.impl.CliLauncher.initCommandContext(CliLauncher.java:276) ... 8 more Caused by: java.io.IOException: java.net.ConnectException: JBAS012144: Could not connect to http-remoting://10.0.1.1:9990. The connection timed out at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeForResult(AbstractModelControllerClient.java:129) at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:71) at org.jboss.as.cli.impl.CommandContextImpl.tryConnection(CommandContextImpl.java:1005) ... 11 more Caused by: java.net.ConnectException: JBAS012144: Could not connect to http-remoting://10.0.1.1:9990. The connection timed out at org.jboss.as.protocol.ProtocolConnectionUtils.connectSync(ProtocolConnectionUtils.java:119) at org.jboss.as.protocol.ProtocolConnectionManager$EstablishingConnection.connect(ProtocolConnectionManager.java:256) at org.jboss.as.protocol.ProtocolConnectionManager.connect(ProtocolConnectionManager.java:70) at org.jboss.as.protocol.mgmt.FutureManagementChannel$Establishing.getChannel(FutureManagementChannel.java:204) at org.jboss.as.cli.impl.CLIModelControllerClient.getOrCreateChannel(CLIModelControllerClient.java:169) at org.jboss.as.cli.impl.CLIModelControllerClient$2.getChannel(CLIModelControllerClient.java:129) at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:117) at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:92) at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeRequest(AbstractModelControllerClient.java:236) at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:141) at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeForResult(AbstractModelControllerClient.java:127) ... 13 more packet_write_wait: Connection to XXX.XXX.XXX.XXX port 22: Broken pipe Build step 'Execute shell' marked build as failure
which in turn aborts the bash script and thus the Jenkins job. So, question 1: how can I catch Exceptions and make sure that the bash script is processed and wildfly is terminated using the kill-switch.
Problem type 2)
sometimes the call freezes and console shows me only
2019-02-27_22-05-17 [INFO] Trying to stop wildfly service with jboss-cli.sh /opt/wildfly/bin/jboss-cli.sh --controller=10.0.1.1:9990 --connect --user=XXXX --password=XXXX command=:shutdown --timeout=120
It seems that the timeout property of jboss is not working properly. So, question 2: how can I make sure that the call is terminated and not running/waiting indefinitely?
Thank you, Richard