How to run WildFly as Service

The guide discusses how to configure WildFly or JBoss as a Service on a Linux machine or on a Windows box. We will cover the code settings and addresses common pitfalls and aligns with current best practices.

Linux (systemd Integration)

WildFly 36 includes native systemd support. Follow these steps:

Firstly, generate Systemd Files:

cd $WILDFLY_HOME/bin/systemd  
./generate_systemd_unit.sh standalone <user> <group>

Then, replace <user> and <group> with your service account. This creates wildfly-standalone.service.

Finally, anstall and activate the service:

sudo cp wildfly-standalone.service /etc/systemd/system/  
sudo systemctl daemon-reload  
sudo systemctl enable wildfly-standalone

Key commands:

sudo systemctl start wildfly-standalone    # Start  
sudo systemctl stop wildfly-standalone     # Graceful stop  
sudo systemctl restart wildfly-standalone  # Restart

Critical configurations (add to [Service] section):

TimeoutStopSec=90       # Prevents premature termination  
Restart=on-failure      # Auto-recover from crashes  
User=wildfly            # Dedicated service account

Pitfall Fixes:

  • Port conflicts: If ports remain occupied after shutdown, increase TimeoutStopSec to 90+ seconds.
  • Silent failures: Set Type=simple in unit files (default for WildFly 36).

Windows Service Management

Use the bundled service.bat. Start by installing the service:

cd %WILDFLY_HOME%\bin  
service.bat install

Then, here is how you can manage the service on Windows:

service.bat start     # Start  
service.bat stop      # Stop  
service.bat restart   # Restart
start jboss as service linux windows

Finally, in Domain mode:

service.bat install /controller=localhost:9990 /host=master

Troubleshooting:

  • Permission issues: Run installation as Administrator.
  • Startup failures: Verify JAVA_HOME is set in service.bat.

Key Improvements vs. Legacy Methods

Feature Legacy (AS7) WildFly 36
Linux Init Custom init.d scripts Native systemd generator
Windows Dependencies JBoss Web Native required Zero dependencies
Graceful Shutdown Manual CLI calls Built-in TimeoutStopSec
Permission Handling Manual chown/chmod User/Group directives

Best Practices

  1. Service account setup: bashuseradd -r -s /sbin/nologin wildfly chown -R wildfly:wildfly $WILDFLY_HOME
  2. Logging: Redirect output to journald (Linux) or standalone/log/ (Windows).
  3. Auto-recovery: Enable Restart=on-failure in systemd units.

⚠️ Critical Note: Always test restarts under load—WildFly’s embedded shutdown hooks now handle thread cleanup more reliably than older versions.