Install Wildfly 14 Server on Centos 7 as a Service

Deploy Wildfly as a service

Although many container solutions are available, in certain cases you need to install wildfly on a server. But not many resources explain the process in details. This article intends to fill that requirement. If you need you can completely automate the process by writing a shell script to do the exact same.

To install wildfly on a Centos 7 server you need to have following dependencies.

  • root level access
  • Java (JDK installed)
  • wget (wget utility installed)
  • Vim (Optional)

Downloading Wildfly

We will start by downloading latest version of Wildfly server. Go to downloads page of Wildfly web site and copy the URL to the latest tar.gz version of the server.

Copy URL to the latest Wildfly version.

Then open a terminal and enter following command

wget http://download.jboss.org/wildfly/14.0.1.Final/wildfly-14.0.1.Final.tar.gz
Download Wildfly using wget utility

Then extract the downloaded archive

tar zxvf wildfly-14.0.1.Final.tar.gz
Extract the archive

Configure the Server

  1. Add a user for the wildfly server
sudo adduser wildfly 

Check user (if required) with cat /etc/passwd

2. Copy server to /opt

sudo cp wildfly-14.0.1.Final/ /opt

3. Add a symlink for easier reference and change ownership

sudo ln -s wildfly-14.0.1.Final wildfly
sudo chown -R wildfly:wildfly wildfly-14.0.1.Final
sudo chown -R wildfly:wildfly wildfly
Change ownership to wildfly user

4. Copy the configuration file from wildfly sources to Centos default configurations

sudo cp /opt/wildfly/docs/contrib/scripts/init.d/wildfly.conf /etc/default/wildfly

5. Edit configuration to include new configuration. Use your favourite text editior. (Vim is user here)

sudo vim /etc/default/wildfly

Change following lines and save the file. (you have to uncomment the lines and change related parameters)

## Location of JDK
JAVA_HOME="/usr/java/jdk1.8.0_191-amd64/"
## Location of WildFly
JBOSS_HOME="/opt/wildfly"
## The username who should own the process.
JBOSS_USER=wildfly
## The mode WildFly should start, standalone or domain
JBOSS_MODE=standalone
## Configuration for standalone mode
JBOSS_CONFIG=standalone.xml
.
.
.
## Location to keep the console log
JBOSS_CONSOLE_LOG="/var/log/wildfly/console.log"

JAVA_HOME : java installation location, based on the installation method this may vary. If you cannot find it at /usr/java/, look in /usr/lib/jvm.

6. JBOSS_CONSOLE_LOG variable specifies the server console log location. We have to create it now and change ownership to wildfly user

sudo mkdir -p /var/log/wildfly
sudo chown -R wildfly:wildfly /var/log/wildfly

7. Copy init scripts

sudo cp /opt/wildfly/docs/contrib/scripts/init.d/wildfly.conf /etc/default/wildfly

8. Configure service with following commands

chkconfig --add wildfly 
chkconfig wildfly on

9. Our task is almost complete. All that is left is to spin up your brand new server. :)

sudo service wildfly start

If everything went well, you will see following.

Start your wildfly server as a service

server log will show tail -f -n 200 /var/log/wildfly/console.log

Successful deployment

10. You can check the server status with following.

sudo service wildfly status

Fin

You can deploy a java webapp in the wildfly server by copying the war into deployments folder.

sudo cp /opt/wildfly/standalone/deployments

Happy developing.