X4 Help Center
7.5 7.4 German English
Auto Light Dark
Auto Light Dark
7.5 7.4 German English

Instructions: Creating and Managing systemd Services for X4-Server

These instructions explain how to manually install, enable, start, stop, and uninstall systemd services for X4-Server.

Note:

These instructions replace the previous automatic service setup. Since X4 7.5.0, the Linux installation packages (ZIP, DEB, RPM) no longer register the X4-Server as a system service and no longer contain service files. You can create these files yourself with the commands on this page.

The instructions apply to one service unit:

  • X4-Server

The commands work on most modern Linux distributions that use systemd (e.g. RHEL 8/9, Debian 11+/12+, Ubuntu 20.04+). The instructions assume that X4 is installed in /opt/X4, which is the default for the DEB and RPM packages. Run all commands as:

  • root or with sudo

Prerequisites for ZIP installations

The DEB and RPM packages perform these steps during installation. If you installed X4 from the ZIP archive, run them once before you create the service. Replace <version> with your X4 version.

Bash
mkdir -p /opt/X4
unzip X4_Server_Linux-<version>.zip -d /opt/X4
getent passwd X4 >/dev/null || useradd -r -U -d /opt/X4 X4
grep -q '^X4_INSTALL_PATH=' /etc/environment || echo 'X4_INSTALL_PATH=/opt' >> /etc/environment
find /opt/X4 -name '*.sh' -exec chmod +x {} \;
chmod +x /opt/X4/jdk/bin/* /opt/X4/jdk/lib/jspawnhelper /opt/X4/apache-maven/bin/*
chown -R X4:X4 /opt/X4

Note: Without these steps, X4_INSTALL_PATH is not set in /etc/environment and the service cannot start.


Creating the service files

The service consists of two files:

  • /etc/default/X4-Server – environment file with the X4, Java and WildFly settings

  • /etc/systemd/system/X4-Server.service – systemd unit file

Create the environment file: /etc/default/X4-Server

Create the environment file and adjust the memory settings (-Xms, -Xmx) to your system as needed.

Environment file
Bash
cat > /etc/default/X4-Server <<'EOF'
#!/bin/bash

# Load pre-existing environment data from the system.
. /etc/environment

## Location of X4
X4_HOME="$X4_INSTALL_PATH/X4"

## Location of JDK
JAVA_HOME="$X4_HOME/jdk"

## Location of WildFly
JBOSS_HOME="$X4_HOME/wildfly"

## The username who should own the process.
JBOSS_USER=X4

## The mode WildFly should start, standalone or domain
# JBOSS_MODE=standalone

## Configuration for standalone mode
# JBOSS_CONFIG=standalone.xml

## Configuration for domain mode
# JBOSS_DOMAIN_CONFIG=domain.xml
# JBOSS_HOST_CONFIG=host-master.xml

## The amount of time to wait for startup
# STARTUP_WAIT=60

## The amount of time to wait for shutdown
# SHUTDOWN_WAIT=60

## Location to keep the console log
# JBOSS_CONSOLE_LOG="/var/log/wildfly/console.log"

## Additionals args to include in startup
JBOSS_OPTS="-b 0.0.0.0"

JBOSS_PIDFILE="/run/X4-Server/X4-Server.pid"

LAUNCH_JBOSS_IN_BACKGROUND=1

## Set heap memory parameters
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx2G -XX:SoftRefLRUPolicyMSPerMB=3600000"

JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"

## Configure path to the x4config.xml
JAVA_OPTS="$JAVA_OPTS -Dx4.config.file=$X4_HOME/X4config.xml"
JAVA_OPTS="$JAVA_OPTS -Dx4.directory=$X4_HOME"

## Enable custom URL handlers for wildfly
JAVA_OPTS="$JAVA_OPTS -Djboss.protocol.handler.modules=de.softproject.x4.client"

## Surpress some messages about not finding native implementations and falling back to a pure java implementation
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.media.jai.disableMediaLib=true"

## Enable remote debug
# JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

export X4_INSTALL_PATH
export X4_HOME
export JAVA_HOME
export JAVA_OPTS
export JBOSS_HOME
export JBOSS_USER
export JBOSS_OPTS
export JBOSS_PIDFILE
export LAUNCH_JBOSS_IN_BACKGROUND
EOF
chmod 0644 /etc/default/X4-Server

Create the unit file: /etc/systemd/system/X4-Server.service

Unit file
Bash
cat > /etc/systemd/system/X4-Server.service <<'EOF'
[Unit]
Description=X4 Application Server
After=network.target remote-fs.target
Wants=network.target

[Service]
Type=exec
User=root
Group=root
EnvironmentFile=/etc/environment
WorkingDirectory=/opt/X4
ExecStart=/bin/bash -ac '. /etc/default/X4-Server; /opt/X4/wildfly/bin/standalone.sh -c standalone.xml'
ExecStop=/bin/bash -ac '. /etc/default/X4-Server; /opt/X4/wildfly/bin/jboss-cli.sh --connect --command=:shutdown'
ExecReload=/bin/bash -ac '. /etc/default/X4-Server; /opt/X4/wildfly/bin/jboss-cli.sh --connect --command=:reload'
SuccessExitStatus=143
TimeoutStartSec=300
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
EOF
chmod 0644 /etc/systemd/system/X4-Server.service

Note: If X4 is not installed in /opt/X4 (e.g. DEB with INSTALL_PATH, RPM with --prefix), replace /opt/X4 in WorkingDirectory, ExecStart, ExecStop and ExecReload with your installation directory.


Activating and starting the service

  1. Reload systemd to recognize the new unit files.

  2. Then enable the services to run automatically when the system starts. Optionally, you can start it immediately.

Bash
# Make systemd aware of new/changed unit file
systemctl daemon-reload
 
# Start X4-Server automatically at boot
systemctl enable X4-Server
 
# Start X4 Server now (optional)
systemctl start X4-Server

Checking the installation

Check the current status and the last log entries of the services:

Bash
systemctl status X4-Server --no-pager
journalctl -u X4-Server -b --no-pager | tail -n 50

Note:

If the service does not start, check the log output and the following files:

  • /etc/default/X4-Server

  • /etc/environment (must contain X4_INSTALL_PATH)


Uninstalling the service

Complete the following steps to remove the services and all service files before you uninstall the X4 package.

Bash
# Stop and disable X4-Server
systemctl stop X4-Server || true
systemctl disable X4-Server || true
 
# Remove the unit file and the environment file
rm -f /etc/systemd/system/X4-Server.service
rm -f /etc/systemd/X4-Server
 
# Make systemd forget the removed unit
systemctl daemon-reload
systemctl reset-failed

Note: The file name /etc/default/X4-Server is case-sensitive.


Troubleshooting tips

Action

Command

Reload system after every change to the unit file

systemctl daemon-reload

Show the unit definition that systemd uses

systemctl cat X4-Server

Display recent log output

journalctl -u X4-Server -b --no-pager

Restart the service and check its status

systemctl restart X4-Server && systemctl status X4-Server --no-pager

  • File permissions: the unit file and /etc/default/X4-Server should be owned by root:root with mode 0644.

  • SELinux: if SELinux is active, adjust the labels if necessary (for example with restorecon) or move the files to default paths.

  • Network access: make sure the required ports are open (firewalld, ufw, iptables).

  • Message cannot create /run/X4-Server/X4-Server.pid: Directory nonexistent: harmless; starting, restarting and stopping the service work regardless.

  • Message /X4/jdk/bin/java: not found: X4_INSTALL_PATH is missing from /etc/environment; see prerequisites.


Differences from the previous automatic installation

Up to X4 7.4, the DEB and RPM packages installed the service files, set ownership and permissions, ran systemctl daemon-reload, enabled the service and, on a fresh installation, started it. Since X4 7.5.0 the packages no longer do this. The commands on this page perform the same steps explicitly, can be adjusted to your need and can also be used in scripted deployments.


Appendix: Fast installation block

After you have created the service files (and, for ZIP installations, completed the prerequisites), you can enable and start the service with one command:

Bash
systemctl daemon-reload && systemctl enable --now X4-Server

The service then starts automatically at every boot.