How to Start Wildfly Java Application Server using Wildfly User Account as a Background Process

Posted on

Introduction

This is another article which has similar content with several previous articles. Those articles are in several links. Those links are in the article with a title ‘How to Start Wildfly Java Application Server in the Foreground Process’ in this link. Another article with the title of ‘How to Start Wildfly Java Application Server in the Background Process’ in this link. Furthermore, there is also an article in this link with the title of ‘How to Start Wildfly Java Application Server using Wildfly User Account as a foreground process’. All of them have similar subject and content. In this article, the additional focus is running wildfly in the background process using ‘wildfly’ user account.

Running a specific process like Wildfly Java Application Server with a separate user account as ‘wildfly’ is a good practice in terms of security. If there is a compromise or even there is an illegal take over on the process, it will not harm the system heavily because user account running the process has limited privileges. The following are steps to achieve it :

1. First of all, switch to ‘root’ account. Execute the following command :

user@hostname:~$ sudo su - 
[sudo] password for user: 
root@hostname ~# 

2. After successfully switching to ‘root’ account, execute the following command pattern :

runuser user_account -l /opt/wildfly-xx.x.x.Final/bin/standalone.sh

The following is the real command execution as an example. It will start Wildfly Java Application Server using wildfly user account as a background process :

root@hostname ~# runuser wildfly -l /opt/wildfly-17.0.1.Final/bin/standalone.sh &
[1] 8717
root@hostname ~# =========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /opt/wildfly-17.0.1.Final

  JAVA: java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true 

=========================================================================

06:24:29,931 INFO  [org.jboss.modules] (main) JBoss Modules version 1.9.1.Final
06:24:30,238 INFO  [org.jboss.msc] (main) JBoss MSC version 1.4.8.Final
06:24:30,246 INFO  [org.jboss.threads] (main) JBoss Threads version 2.3.3.Final
06:24:30,342 INFO  [org.jboss.as] (MSC service thread 1-1) WFLYSRV0049: WildFly Full 17.0.1.Final (WildFly Core 9.0.2.Final) starting
06:24:31,198 INFO  [org.wildfly.security] (ServerService Thread Pool -- 8) ELY00001: WildFly Elytron version 1.9.1.Final
06:24:31,576 INFO  [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
06:24:31,638 INFO  [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 36) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.
06:24:31,666 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
06:24:31,683 INFO  [org.xnio] (MSC service thread 1-2) XNIO version 3.7.2.Final
06:24:31,690 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.7.2.Final
06:24:31,731 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 43) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
06:24:31,784 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 51) WFLYCLINF0001: Activating Infinispan subsystem.
06:24:31,791 INFO  [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 5.0.12.Final
06:24:31,792 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 52) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
06:24:31,822 INFO  [org.jboss.as.jaxrs] (ServerService Thread Pool -- 53) WFLYRS0016: RESTEasy version 3.7.0.Final
06:24:31,831 INFO  [org.jboss.as.connector] (MSC service thread 1-1) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.16.Final)
06:24:31,843 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
06:24:31,849 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 58) WFLYJSF0007: Activated the following JSF Implementations: [main]
06:24:31,850 INFO  [org.wildfly.extension.microprofile.config.smallrye._private] (ServerService Thread Pool -- 60) WFLYCONF0001: Activating WildFly MicroProfile Config Subsystem
06:24:31,858 INFO  [org.wildfly.extension.microprofile.opentracing] (ServerService Thread Pool -- 63) WFLYTRACEXT0001: Activating MicroProfile OpenTracing Subsystem
06:24:31,869 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 64) WFLYNAM0001: Activating Naming Subsystem
06:24:31,873 INFO  [org.wildfly.extension.microprofile.health.smallrye] (ServerService Thread Pool -- 61) WFLYHEALTH0001: Activating Eclipse MicroProfile Health Subsystem
06:24:31,873 INFO  [org.wildfly.extension.microprofile.metrics.smallrye] (ServerService Thread Pool -- 62) WFLYMETRICS0001: Activating Eclipse MicroProfile Metrics Subsystem
06:24:31,893 INFO  [org.jboss.as.naming] (MSC service thread 1-3) WFLYNAM0003: Starting Naming Service
06:24:31,894 INFO  [org.jboss.as.ejb3] (MSC service thread 1-1) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 128 (per class), which is derived from thread worker pool sizing.
06:24:31,901 INFO  [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 32 (per class), which is derived from the number of CPUs on this host.
06:24:31,894 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-7) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
06:24:31,908 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 70) WFLYSEC0002: Activating Security Subsystem
06:24:31,908 INFO  [io.smallrye.metrics] (MSC service thread 1-4) Converted [2] config entries and added [4] replacements
06:24:31,910 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 72) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.
06:24:31,913 INFO  [org.jboss.as.security] (MSC service thread 1-2) WFLYSEC0001: Current PicketBox version=5.0.3.Final
06:24:31,915 INFO  [io.smallrye.metrics] (MSC service thread 1-4) Converted [3] config entries and added [14] replacements
06:24:31,923 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 74) WFLYWS0002: Activating WebServices Extension
06:24:31,944 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0003: Undertow 2.0.21.Final starting
06:24:32,168 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 73) WFLYUT0014: Creating file handler for path '/opt/wildfly-17.0.1.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
06:24:32,174 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0012: Started server default-server.
06:24:32,175 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0018: Host default-host starting
06:24:32,263 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
06:24:32,343 INFO  [org.jboss.as.ejb3] (MSC service thread 1-8) WFLYEJB0493: EJB subsystem suspension complete
06:24:32,397 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
06:24:32,421 INFO  [org.jboss.as.patching] (MSC service thread 1-2) WFLYPAT0050: WildFly Full cumulative patch ID is: base, one-off patches include: none
06:24:32,440 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) WFLYDS0013: Started FileSystemDeploymentService for directory /opt/wildfly-17.0.1.Final/standalone/deployments
06:24:32,539 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
06:24:33,127 INFO  [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBossWS 5.3.0.Final (Apache CXF 3.3.2) 
06:24:33,299 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
06:24:33,301 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
06:24:33,301 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
06:24:33,301 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 17.0.1.Final (WildFly Core 9.0.2.Final) started in 3728ms - Started 314 of 576 services (369 services are lazy, passive or on-demand)

root@hostname ~# 

Further Description for Checking the Process

Since the above process is running in the background process by adding ‘&’ character in the end of the command, the log output process can stop. Just hit the ‘enter’ command, the process will redirect back to the command line interface process. It is indicating that the running wildfly is currently run in the background process.

Furthermore, check the owner status of the process by executing the following command pattern :

ps -aux | grep wildfly

The execution command of the above pattern to prove that wildfly user account owns the running process will in the following output :

root@hostname ~# ps -aux | grep wildfly
root      8717  0.0  0.0  70632  3912 pts/9    S    06:24   0:00 runuser wildfly -l /opt/wildfly-17.0.1.Final/bin/standalone.sh
wildfly   8718  0.0  0.0  18504  3024 pts/9    S    06:24   0:00 -bash /opt/wildfly-17.0.1.Final/bin/standalone.sh
wildfly   8765  3.6  2.3 2258512 387588 pts/9  Sl   06:24   0:13 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=/opt/wildfly-17.0.1.Final/standalone/log/server.log -Dlogging.configuration=file:/opt/wildfly-17.0.1.Final/standalone/configuration/logging.properties -jar /opt/wildfly-17.0.1.Final/jboss-modules.jar -mp /opt/wildfly-17.0.1.Final/modules org.jboss.as.standalone -Djboss.home.dir=/opt/wildfly-17.0.1.Final -Djboss.server.base.dir=/opt/wildfly-17.0.1.Final/standalone
root      9203  0.0  0.0  23960  1048 pts/9    S+   06:30   0:00 grep wildfly
root@hostname ~# 

3. Finally, check the status of the process or the running service. Read the article with the title of ‘How to Check Wildfly Java Application Server running service or process’ in this link.

Leave a Reply