With systemd, you can run the mabl Link Agent as a system service on a Linux machine, so that it starts at boot and restarts if it stops.
Recommended: install with install.sh
The recommended way to run the Link Agent as a systemd service is the Linux and macOS installer. It creates the service for you, along with a service account and a configuration file, and offers to tune the host's socket-buffer limits. From the extracted tar.bz2 or zip archive, run:
sudo ./install.sh
The rest of this article explains how to write the systemd service yourself. Only follow these manual steps if you need a highly customized installation that the installer can't set up for you. Even then, start from the service definition the installer would write for your host, which ./install.sh --print-unit prints without installing anything.
Before you start
- A "Link Agent" API key and a tunnel name. See Link Agent setup.
- Java 11 or later. See Link Agent requirements.
Step 1: Install the Link Agent
-
Download the tar.bz2 or zip archive from Settings > Networking and copy it to the host.
-
Extract it to the directory you want to run it from, such as
/opt/mabl:sudo mkdir -p /opt/mabl sudo tar xjf link-agent.tbz2 -C /opt/mabl -
Create a Link Agent configuration file with your tunnel name and API key, such as
/opt/mabl/link-agent/config/config.yaml.
We recommend creating a separate account for the Link Agent, such as mabl, and making it the owner of the install directory. The service account needs to write to the install directory, because the Link Agent keeps its logs there and installs updates beside the running version.
sudo useradd --system --no-create-home mabl
sudo chown -R mabl: /opt/mabl/link-agent
sudo chmod 600 /opt/mabl/link-agent/config/config.yaml
Step 2: Create the service file
Save the following as /etc/systemd/system/mabl-link-agent.service, and update the paths, the User, and JAVA_HOME for your host:
[Unit]
Description=mabl Link Agent
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=mabl
WorkingDirectory=/opt/mabl/link-agent
Environment="LINK_AGENT_SERVICE_MANAGED=1"
Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk"
ExecStart=/opt/mabl/link-agent/bin/link-agent --config /opt/mabl/link-agent/config/config.yaml
Restart=on-failure
RestartSec=10
TimeoutStopSec=90
KillMode=mixed
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
A few of these settings matter for how the Link Agent behaves as a service:
-
LINK_AGENT_SERVICE_MANAGED=1andRestart=on-failurelet systemd restart the agent after it installs an update. The agent exits with an error code to ask for the restart. When the agent exits cleanly on purpose, such as when mabl reports that its API key is no longer valid, systemd leaves it stopped instead of retrying the same refusal. -
JAVA_HOMEtells the service which Java to use, because a service doesn't inherit the environment of the shell you installed it from. -
TimeoutStopSec=90andKillMode=mixedgive the agent time to let in-flight connections finish when the service stops, before systemd stops the agent's tunnel processes. -
LimitNOFILE=65535raises the open-file limit, because a busy tunnel uses one connection per test request.
Step 3: Start the Link Agent
Load the new service, then enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now mabl-link-agent
To check that the agent started, look at the service's status and output:
systemctl status mabl-link-agent
journalctl -u mabl-link-agent -r
The Link Agent's own log is logs/agent.log in the install directory.
Step 4: Confirm the Link Agent is connected
Go to Settings > Networking in the mabl app and confirm that the agent shows Connected. See Link Agent setup.
Next steps
When the Link Agent is installed and running, configure your tests to run over mabl Link.