WildFly Cookbook
上QQ阅读APP看书,第一时间看更新

Shutting down and restarting an instance via the CLI

In this recipe, we will learn how to stop a WildFly instance via the CLI, or alternatively, restart it via the CLI.The restart option is in contrast to the reload command of the previous recipe.

Getting ready

Start up your WildFly so that we can directly connect to it via the CLI, as follows:

$ cd ~/WFC/wildfly
$ ./bin/standalone.sh

How to do it...

The command itself is pretty easy:

$ ./bin/jboss-cli.sh --connect
[standalone@localhost:9990 /] shutdown
[disconnected /]

How it works...

The preceding command stops everything and drops you off from the CLI. Hence, in case you need to restart your WildFly instance, you need to execute the standalone.sh script again, along with any parameter previously defined.

There's more...

Alternatively, if what you really need is a full stop and start, you can rely on the --restart=true option for the shutdown command.

Before executing the shutdown command with the restart option, take note of the process ID (PID) of the WildFly instance, as follows:

$ ps -efa | grep java | grep -v grep
luigi     5031  5023  0 16:07 pts/2    00:00:03 /home/luigi/WFC/jdk8/bin/java -Djboss.modules.system.pkgs=com.sun.java.swing -Dlogging.configuration=file:/home/luigi/WFC/wildfly/bin/jboss-cli-logging.properties -jar /home/luigi/WFC/wildfly/jboss-modules.jar -mp /home/luigi/WFC/wildfly/modules org.jboss.as.cli --connect
luigi     5285  5249 99 16:29 pts/3    00:00:09 /home/luigi/WFC/jdk8/bin/java -D[Standalone] -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/home/luigi/WFC/wildfly/standalone/log/server.log -Dlogging.configuration=file:/home/luigi/WFC/wildfly/standalone/configuration/logging.properties -jar /home/luigi/WFC/wildfly/jboss-modules.jar -mp /home/luigi/WFC/wildfly/modules org.jboss.as.standalone -Djboss.home.dir=/home/luigi/WFC/wildfly -Djboss.server.base.dir=/home/luigi/WFC/wildfly/standalone

Okay, now go back into the CLI and do as follows:

[standalone@localhost:9990 /] shutdown --restart=true
[standalone@localhost:9990 /]

The first visible difference is that your CLI doesn't disconnect. Now let's go back to the terminal and list the available processes at the OS level, as done previously:

$ ps -efa | grep java | grep -v grep
luigi     5421  5413 10 16:29 pts/2    00:00:01 /home/luigi/WFC/jdk8/bin/java -Djboss.modules.system.pkgs=com.sun.java.swing -Dlogging.configuration=file:/home/luigi/WFC/wildfly/bin/jboss-cli-logging.properties -jar /home/luigi/WFC/wildfly/jboss-modules.jar -mp /home/luigi/WFC/wildfly/modules org.jboss.as.cli --connect
luigi     5482  5249 99 16:29 pts/3    00:00:10 /home/luigi/WFC/jdk8/bin/java -D[Standalone] -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/home/luigi/WFC/wildfly/standalone/log/server.log -Dlogging.configuration=file:/home/luigi/WFC/wildfly/standalone/configuration/logging.properties -jar /home/luigi/WFC/wildfly/jboss-modules.jar -mp /home/luigi/WFC/wildfly/modules org.jboss.as.standalone -Djboss.home.dir=/home/luigi/WFC/wildfly -Djboss.server.base.dir=/home/luigi/WFC/wildfly/standalone

This is probably the most important difference with the reload command. You get a completely new JVM, a different process ID at the OS level. The preceding command executed into the CLI completely shuts down the current instance and starts up a new one, as shown in the following log entries:

...
10:43:31,997 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0211: Suspending server
10:43:32,002 INFO  [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested.
10:43:32,016 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-10) WFLYUT0019: Host default-host stopping
10:43:32,017 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0010: Unbound data source [java:jboss/datasources/ExampleDS]
10:43:32,025 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-11) WFLYJCA0019: Stopped Driver service with driver-name = h2
10:43:32,058 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0008: Undertow HTTP listener default suspending
10:43:32,065 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0007: Undertow HTTP listener default stopped, was bound to /0.0.0.0:8080
10:43:32,066 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0004: Undertow 1.2.0.Beta10 stopping
10:43:32,152 INFO  [org.jboss.as] (MSC service thread 1-2) WFLYSRV0050: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) stopped in 130ms
Restarting JBoss...
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
10:43:32,639 INFO  [org.jboss.modules] (main) JBoss Modules version 1.4.2.Final
10:43:32,858 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.4.Final
10:43:32,936 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) starting
10:43:34,064 INFO  [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 22) WFLYCTL0028: Attribute enabled is deprecated, and it might be removed in future version!
10:43:34,088 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
10:43:34,120 INFO  [org.xnio] (MSC service thread 1-2) XNIO version 3.3.0.Final
10:43:34,130 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.3.0.Final
10:43:34,186 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
10:43:34,185 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
10:43:34,193 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 4.0.8.Final
10:43:34,220 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
10:43:34,230 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
10:43:34,228 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
10:43:34,242 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
10:43:34,242 INFO  [org.jboss.as.security] (MSC service thread 1-10) WFLYSEC0001: Current PicketBox version=4.9.0.Beta2
10:43:34,245 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
10:43:34,294 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
10:43:34,311 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0003: Undertow 1.2.0.Beta10 starting
10:43:34,328 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0003: Undertow 1.2.0.Beta10 starting
10:43:34,305 INFO  [org.jboss.as.connector] (MSC service thread 1-7) WFLYJCA0009: Starting JCA Subsystem (IronJacamar 1.2.3.Final)
10:43:34,350 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-9) WFLYJCA0018: Started Driver service with driver-name = h2
10:43:34,421 INFO  [org.jboss.as.naming] (MSC service thread 1-12) WFLYNAM0003: Starting Naming Service
10:43:34,421 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-14) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
10:43:34,616 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path /home/wildfly/WFC/wildfly/welcome-content
10:43:34,651 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-16) WFLYUT0012: Started server default-server.
10:43:34,670 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-16) WFLYUT0018: Host default-host starting
10:43:34,749 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-11) WFLYUT0006: Undertow HTTP listener default listening on /0.0.0.0:8080
10:43:34,882 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
10:43:34,948 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) WFLYDS0013: Started FileSystemDeploymentService for directory /home/wildfly/WFC/wildfly/standalone/deployments
10:43:35,080 INFO  [org.jboss.ws.common.management] (MSC service thread 1-2) JBWS022052: Starting JBoss Web Services - Stack CXF Server 5.0.0.Beta3
[standalone@localhost:9990 /] 10:43:35,314 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://0.0.0.0:9990/management
10:43:35,320 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://0.0.0.0:9990
10:43:35,321 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 9.0.0.Beta2 (WildFly Core 1.0.0.Beta2) started in 2990ms - Started 202 of 379 services (210 services are lazy, passive or on-demand)

Remember that the PID changes, so if you are monitoring your instance per PID, consider updating your monitoring tool/script as well!