
Stopping and starting your servers via the CLI
In this recipe, we will learn how to stop and start a single server that belongs to a server group using the CLI. Because servers that belong to a server group might be spread over a series of different machines, with different resources available, you might need to stop a single server, without stopping the entire server group to add more resources and start it up back again. Fortunately, WildFly provides such granularity with regards to stop servers.
Getting ready
For this recipe, both the domain controller and host controllers should be up and running. For their configuration, refer to the recipe Connecting the host controller to the domain controller in this chapter.
How to do it…
- Open your terminal and do as follows:
$ ./bin/jboss-cli.sh --connect [domain@localhost:9990 /]
- What we want to do is to "stop" the server named
REST-server-one
, which belongs to theHost Controller
namedslave-1
. This is done as follows:[domain@localhost:9990 /] /host=slave-1/server-config=REST-server-one:stop() { "outcome" => "success", "result" => "STOPPING" } [domain@localhost:9990 /]
As you can see, the server is in the
STOPPING
state; this means it may take a while depending on how many resources you have bound and/or deployed. - To check if it is done, try the following command:
[domain@localhost:9990 /] /host=slave-1/server-config=REST-server-one:read-resource(include-runtime=true) { "outcome" => "success", "result" => { "auto-start" => true, "cpu-affinity" => undefined, "group" => "server-group-REST-app", "name" => "REST-server-one", "priority" => undefined, "socket-binding-group" => undefined, "socket-binding-port-offset" => 0, "status" => "STOPPED", "interface" => undefined, "jvm" => {"default" => undefined}, "path" => undefined, "system-property" => undefined } } [domain@localhost:9990 /]
- Now let's start the server again by invoking the
start
method:[domain@localhost:9990 /] /host=slave-1/server-config=REST-server-one:start() { "outcome" => "success", "result" => "STARTING" } [domain@localhost:9990 /]
How it works…
The stop
command itself is pretty easy, and does not need much explanation. What is worth mentioning is that to be able to stop a server, you first need to know which host/slave it belongs to. What you can do is navigate through WildFly's structure, as follows:

Once you have located the server you want/need to stop, you can issue the stop
command.
There's more…
When dealing with the stop
and start
commands, on both server-group
and server
, you can add the blocking=true
option which basically hangs the commands until it's done. The command would be as follows:
[domain@localhost:9990 /] /host=slave-1/server-config=REST-server-one:start(blocking=true)
In this way we know when the server completes the operation. Imagine a case where you are executing multiple CLI commands in sequence, and a command needs the previous operations to be carried out. Without the blocking flag enabled, the command will not work.