How to manage Servers in a WildFly Domain

This article will teach you how to manage the Servers and Server Groups running in a WildFly Domain. For the purpose of this article we will use the Command Line Interface to perform the management operations.

Pre-requisites: You should be able to set up WildFly in Domain mode. The following article will teach you how to configure it: How to configure WildFly in Domain mode

How to start and stop Domain Servers

You can configure the start up state of the Servers in the host.xml file, which contains the list of servers. The parameter is auto-start. If you don’t include the parameter, by default all Servers will start:

<servers directory-grouping="by-server">
    <server name="server-one" group="main-server-group">
        <socket-bindings port-offset="100"/>
    </server>
    <server name="server-two" group="other-server-group">
        <socket-bindings port-offset="200"/>
    </server>
</servers>

In order to stop a Server, you need to operate on the server path of the Host Controller:

/host=host1/server=server-one:stop()
"outcome" => "success",
"result" => "STOPPING"
}

TIP: You force stopping a Server by using the kill() command which sends a kill -9 signal to interrupt abruptly the Server.

In order to start a Server you can use the equivalent start() command:

/host=host1/server=server-one:start()
{
"outcome" => "success",
"result" => "STOPPING"
}

TIP: You can perform a stop and start in a single operation using the restart command.

Then, you can also execute the suspend operation. When you suspend a server, it will immediately stop accepting new requests, but wait for existing request to complete. For example, here is how to suspend the server-one:

/host=host1/server=server-one:suspend

TIP: It is a good idea to use suspend before shutting down a Server to enable the server to gracefully finish processing all active requests and then shut down.

On the other hand, you can resume a suspended Server as follows:

/host=host1/server-config=server-one:resume
IMPORTANT: Please note that older WildFly versions used the server-config path to manage servers start and stop. This is now deprecated and will be removed in future server versions. Use the server path to manage your servers instead.

Adding or removing WildFly Servers to a Domain

In order to add a new Server, we need to point the Host Controller which will contain the new Server and define at least the Server Group it belongs. To avoid conflicts, it is recommended to define in the same context, the socket-binding-port-offset:

/host=host1/server-config=server-five:add(group=main-server-group,socket-binding-port-offset=300)

You can check the list of servers by stepping into the Host Controller’s path and executing an “ls” of the server element as follows:

cd /host=host1
ls server
server-five   server-one    server-two 

Conversely, you can remove a Server by using the remove command. The server needs however to be stopped before it can be removed:

 /host=host1/server-config=server-five:stop
{
    "outcome" => "success",
    "result" => "STOPPING"
}
/host=host1/server-config=server-five:remove

How to manage WildFly Server Groups

As we have discussed for the single Servers, it is possible to perform the same operations (start/stop/suspend/resume/kill) also on the Server Groups. The advantage is that the operations will be performed on all Servers belonging to a Server Group.

For example, in order to start all Servers belonging to the man-server-group, you can execute the following command on our Domain:

/server-group=main-server-group:start-servers

The opposite operation (stop) can be executed as follows:

/server-group=main-server-group:stop-servers

In order to add a new Server group, you can execute the add operation against the /server-group top element as follows. The mandatory attributes are the Server Group’s profile and its Socket Binding Group:

/server-group=new-server-group:add(profile=full, socket-binding-group=full-sockets)
{
    "outcome" => "success",
    "result" => undefined,
    "server-groups" => undefined
}

Remove the Server Group as follows:

 /server-group=new-server-group:remove

Performing Domain-wide start/stop

An useful shortcut to start, stop or resume all Servers in a Domain is to start with a colon (“:”) which will trigger the following commands:

:start-servers
:stop-servers
:suspend-servers
:resume-servers

: You can also set a timeout on each operation, by including the timeout=x parameter between parenthesis

Found the article helpful? if so please follow us on Socials