Configure the agent for headless mode and auto-launch in Linux
Want to prepare your Linux server for using Multilogin in headless mode? Set both utilities as Systemd services. Systemd is a service manager for Linux, handling tasks like starting and stopping services during startup. This article will guide you in configuring the agent for this use case.
Keep in mind that the article is written for Ubuntu. The other distros are not officially supported.
Step 1: set up XVFB
Xvfb (X Virtual Framebuffer) is a display server that lets graphical applications run in environments without a physical display by creating a virtual screen in memory. It will be needed for the agent to work as intended.
- Open Terminal
- Create the XVFB service file and type the following command:
sudo nano /etc/systemd/system/xvfb.service - Add the content to the service file (and make sure to replace
YOUR_USERNAMEwith your username in Linux OS):[Unit] Description=MLX XVFB After=network.target [Service] Type=simple User=YOUR_USERNAME ExecStart=/usr/bin/Xvfb :99 -screen 0 1920x1080x24 Restart=always [Install] WantedBy=multi-user.targetIn ExecStart we configure the resolution, the number of displays, and the directory for XVFB.
- Press CTRL+X, then Y and Enter to close and save
Step 2: set up agent for auto-launch
- Open Terminal
- Create the XVFB service file and type the following command:
sudo nano /etc/systemd/system/mlx.service - Add the content to the service file (and make sure to replace
YOUR_USERNAMEwith your username in Linux OS):[Unit] Description=MLX Agent After=xvfb.service Requires=xvfb.service [Service] Type=simple User=YOUR_USERNAME Environment=HOME=/home/YOUR_USERNAME Environment=DISPLAY=:99 ExecStartPre=-/usr/bin/pkill -9 -f mlx ExecStartPre=-/bin/rm -f /home/YOUR_USERNAME/mlx/agent.lock /home/YOUR_USERNAME/mlx/profiles.lock /home/YOUR_USERNAME/mlx/launcher.lock ExecStart=/usr/bin/mlx Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.targetLet's understand what this service does:
In
[Unit], we wait for the XVFB service so we don't risk getting display errors.
In[Service], we set the user, home variable and display variable. The display variable is set in the agent service and not XVFB, otherwise the agent would not be able to use it.
Then, with ExecStartPre we kill any remaining agent processes and delete the.lockfiles, this is useful in case the service restarts.ExectStartis the path for the agent binary in Linux. - Press CTRL+X, then Y and Enter to close and save
Step 3: enable and load the services
- Reload daemon (a background service, which loads up the other services):
sudo systemctl daemon-reload - Enable both XFVB and Multilogin X agent as services:
sudo systemctl enable xvfb.service mlx.service - Use
systemctl(a utility tool used for managing system services) for starting the services:
Congratulations! Now the agent and XVFB will be launched during the OS startup.sudo systemctl start xvfb.service sudo systemctl start mlx.service
Use systemctl for managing services
Use systemctl utility for checking the service status. You can use them for getting logs and troubleshooting.
Check service status
Let’s get the service status with:
sudo systemctl status xvfb.serviceYou will see the actions of the XVFB service. You can also change xvfb.service to the name of your service if it’s different.
Get logs
Get the service logs with journalctl service:
journalctl -u mlx.serviceYou can also limit it by line amount. With this command you can limit the lines up to 100:
journalctl -u mlx.service -n 100You can also limit service logs for a time period. Here is the command for limiting the last 30 minutes of logs:
journalctl -u mlx.service --since "30 minutes ago"-f is used for displaying logs in real time:
journalctl -u mlx.service -f