How to run WildFly as Service

[UPDATED!] This tutorial illustrates how to configure WildFly and JBoss AS as a Service (covering all server releases!) both in Windows environment and in Unix-Linux environment.

WildFly as a Service for Linux users

In order to start the application server as service using a Linux distribution you can use the scripts which are located under the JBOSS_HOME/docs/contrib/scripts/init.d folder. If you look into this folder, you will find the following files:

  • wildfly-­init­ : this file needs to be used for Red Hat Enterprise­-like Linux distributions (e.g. RHEL, Centos)
  • wildfly­-init­ this file needs to be used for Debian­like Linux distributions (e.g.Debian, Ubuntu)
  • wildfly.conf: this file contains the configuration used by the above init files

As first step, copy the shell script, which is required by your Linux distribution into the /etc/init.d folder. For example, if we were to install WildFly as a service on RHEL:

$ cp /etc/init.d/wildfly

Now we will copy as well the wildfly.conf configuration file in the location where the startup script expects it:

$ mkdir -p /etc/default
$ cp wildfly.conf /etc/default

Within the wildfly.conf file adjust the settings in order to fit your installation:

#Location of Java
# Location of WildFly
# The username who should own the process.
# The mode WildFly should start, standalone or domain
# Configuration for standalone mode

Next, we will use the  chkconfig command to install WildFly as a service: the first command will add the wildfly shell script to the chkconfig list:

$ chkconfig --add wildfly

The second one, sets the boot levels where the service will be started:

$ chkconfig --level 2345 wildfly on

In order to test that the service starts correctly issue from any root/sudoer user:

$ sudo service wildfly start

And here’s the corresponding service stopping:

$ sudo service wildfly stop

WildFly 10 as a Service for Windows users

Installing WildFly as a service on Windows is much simpler than the older AS7/EAP6 counterpart. As a matter of fact it’s not necessary to install any third party native library because WildFly already ships with all you need. So move to the JBOSS_HOME/docs/contrib/scripts/service folder. If you want to install WildFly as a service in standalone mode simple issue from the command prompt:

service install

Now you can use the Windows Services tab in order to manage the service start/stop. As an alternative you can use the service command to perform basic service management (start/stop/restart). Example:

service restart

Installing WildFly in domain mode requires that you specify some additional settings such as the Domain controller (default on port 9990) and the host name we are going to start (default “master”).

service install /controller localhost:9990 /host master


JBoss AS 7 as a Service for Windows Users

The latest release of the application server requires the following steps to be installed as a service:
Download the JBoss Web native connectors which contain the jbosssvc.exe and service.bat. These files are necessary to start JBoss AS 7 as service for Windows users.
You can download the latest stable release for your platform at:
install run jboss as service
Then unzip the file into your JBoss AS distribution directory.

Adapting service.bat

Now the little hack: as a matter of fact the service.bat file is based on the JBoss AS 5 platform. The most notable difference is that JBoss AS 7 uses standalone.bat instead of run.bat (although a run.bat file has been added for comtability reason).
So replace the service.bat with the following (just adapt your JBOSS_HOME variable to your environment):

@echo off
REM JBoss, the OpenSource webOS
REM Distributable under LGPL license.
REM See terms of license at
REM -------------------------------------------------------------------------
REM JBoss Service Script for Windows
REM -------------------------------------------------------------------------

@if not "%ECHO%" == "" echo %ECHO%
@if "%OS%" == "Windows_NT" setlocal

REM during the build with ant filter.
set SVCDISP=JBoss Application Server 7.1.1
set SVCDESC=JBoss Application Server 7.1.1 GA/Platform: Windows x86

REM Suppress killing service on logoff event
set JAVA_OPTS=-Xrs
SET JBOSS_HOME=C:\jboss-as-7.1.1.Final
REM Figure out the running mode

if /I "%1" == "install"   goto cmdInstall
if /I "%1" == "uninstall" goto cmdUninstall
if /I "%1" == "start"     goto cmdStart
if /I "%1" == "stop"      goto cmdStop
if /I "%1" == "restart"   goto cmdRestart
if /I "%1" == "signal"    goto cmdSignal
echo Usage: service install^|uninstall^|start^|stop^|restart^|signal
goto cmdEnd

REM jbosssvc retun values
REM ERR_RET_USAGE           1
REM ERR_RET_MODE            6

if errorlevel 1 echo Invalid command line parameters
if errorlevel 2 echo Failed installing %SVCDISP%
if errorlevel 4 echo Failed removing %SVCDISP%
if errorlevel 6 echo Unknown service mode for %SVCDISP%
goto cmdEnd

jbosssvc.exe -imwdc %SVCNAME% "%DIRNAME%" "%SVCDISP%" "%SVCDESC%" service.bat
if not errorlevel 0 goto errExplain
echo Service %SVCDISP% installed
goto cmdEnd

jbosssvc.exe -u %SVCNAME%
if not errorlevel 0 goto errExplain
echo Service %SVCDISP% removed
goto cmdEnd


REM Executed on service start

del .r.lock 2>&1 | findstr /C:"being used" > nul

if not errorlevel 1 (

  echo Could not continue. Locking file already in use.
  goto cmdEnd


echo Y > .r.lock

jbosssvc.exe -p 1 "Starting %SVCDISP%" > %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log
del .r.lock

goto cmdEnd


REM Executed on service stop

echo Y > .s.lock

jbosssvc.exe -p 1 "Shutting down %SVCDISP%" > %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\shutdown.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\shutdown.log
del .s.lock

goto cmdEnd


REM Executed manually from command line
REM Note: We can only stop and start

echo Y > .s.lock

jbosssvc.exe -p 1 "Shutting down %SVCDISP%" >> %JBOSS_HOME%\standalone\log\shutdown.log
call jboss-cli.bat --connect command=:shutdown >> %JBOSS_HOME%\standalone\log\shutdown.log 2>&1
del .s.lock


REM Delete lock file

del .r.lock > nul 2>&1

REM Wait one second if lock file exist

jbosssvc.exe -s 1

if exist ".r.lock" goto waitRun

echo Y > .r.lock

jbosssvc.exe -p 1 "Restarting %SVCDISP%" >> %JBOSS_HOME%\standalone\log\standalone.log
call standalone.bat --server-config=standalone.xml < .r.lock >> %JBOSS_HOME%\standalone\log\standalone.log 2>&1
jbosssvc.exe -p 1 "Shutdown %SVCDISP% service" >> %JBOSS_HOME%\standalone\log\standalone.log

del .r.lock

goto cmdEnd


REM Send signal to the service.
REM Requires jbosssch.dll to be loaded in JVM

@if not ""%2"" == """" goto execSignal

echo Missing signal parameter.
echo Usage: service signal [0...9]

goto cmdEnd


jbosssvc.exe -k%2 %SVCNAME%

goto cmdEnd

Now from the DOS prompt run:
C:\jboss-as-7.1.1.Final\bin>service.bat install
Installed JBAS711SVC
Service JBoss Application Server 7.1.1 installed
This will install JBoss AS 7 in the list of Services.
run jboss as service

JBoss AS 7 as a Service for Linux users

Linux applications use System V Init scripts to run an application when the machine boots.
Basically, the scripts which start a service are placed in:
/etc/rc.d/init.d/   (other distributions: /etc/init.d/)

The same scripts need to be linked as:
/etc/rc.(x)/  (Prefixed with S for start and K for stop)

We suggest you reading a good tutorial about Linux Init scripts if you are new to this:

In order to install JBoss AS 7 on your Linux distribution pickup the file located in JBOSS_HOME/bin/init.d. This file needs to be placed in init.d to launch jboss as a service.

cp /etc/rc.d/init.d/jboss					

Remember to edit the file to adapt it to your environment:

# Load JBoss AS init.d configuration.
if [ -z "$JBOSS_CONF" ]; then

[ -r "$JBOSS_CONF" ] && . "${JBOSS_CONF}"

# Set defaults.

if [ -z "$JBOSS_HOME" ]; then
Now you should create a link for each System level so that Linux/Unix knows at which level the application server needs to be started:
ln -s /etc/rc.d/init.d/jboss /etc/rc3.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc5.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc4.d/S84jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc6.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc0.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc1.d/K15jboss
ln -s /etc/rc.d/init.d/jboss /etc/rc2.d/K15jboss					
We don’t go deep into the details of Linux startup system but the links targeted as “S” are launched to start the service at a certain system level. The scripts marked with “K” are launched when the server is shuitting down.JBoss AS distribution includes a few shell commands which are located in the JBOSS_HOME/bin folder.

JBoss AS 4-5-6 as a Service for Windows Users

Earlier releases of JBoss ship out of the box with the service.bat shell command which is located into the JBOSS_HOME/bin folder. The service.bat commands needs at least one parameter to run:
Usage: service install|uninstall|start|stop|restart|signal

In order to install JBoss AS as Windows service launch:

C:\jboss-5.0.0.GA\bin>service install
Now JBoss AS should me enlisted in the Windows Service List, which can be found in the control panel.

run jboss as service

Now you can use both the Windows service applet or the service.bat command to start the service. Example:

Starting JBoss AS service:

C:\jboss-5.0.0.GA\bin>service start

JBOSS AS 4-5-6 as a Service for Linux Users

The main difference with the AS 7 distribution is that you have a set of different shell command for each operating system:

Copy the appropriate file for your distribution into the /etc/rc.d/init.d folder

cp /etc/rc.d/init.d/jboss	

The rest of the procedure stays the same as for AS 7.

Reference: WildFly 10 Administration guide