Skip to content

Running HADAL as a systemd service

HADAL ships a systemd template unit at contrib/systemd/hadal@.service. The instance name is the access mode, so one file starts the server in any mode:

Terminal window
sudo systemctl enable --now hadal@lan

The modes are local, lan, cloudflare, tailscale, and tailscale-serve. Remote access explains who can connect in each one.

Enable one instance at a time. Every instance uses the same port and data folder, and a second launcher on that folder now refuses to start (it names the pid that holds it) rather than adopting the first one’s Tailscale Serve mount.

  • Node.js 22.19 or newer, installed for the whole system and found through PATH. A copy in a home folder, such as one from nvm or mise, is not visible to the service.
  • A checkout of HADAL with its packages installed (npm install).
  • A user for the service. Give it an account of its own: agents run commands as this user, and anyone who can steer a session can run them too.

The access mode also needs its own tools:

  • local: nothing. Listens on 127.0.0.1.
  • lan: the port open in the firewall (TCP 8787 by default). Plain http.
  • cloudflare: cloudflared on PATH, or in /var/lib/hadal/bin. The service has no terminal, so it cannot download it. Run HADAL once in a terminal as the service user, or install it yourself. The quick tunnel address changes each time the launcher starts.
  • tailscale: Tailscale connected (tailscale up). Listens on the Tailscale address only.
  • tailscale-serve: Tailscale 1.52 or newer, tailscaled running, HTTPS certificates enabled in the tailnet, and the service user as its operator (sudo tailscale set --operator=hadal, unless the service runs as root). The launcher adds the mapping and removes one it made. It also removes one that a crashed run made, which it knows by its receipt (serve-mount.json in the data folder). When it cannot, a start in another mode on that port stops and says how to free it, as the mapping would keep the app on the tailnet. A mapping with no receipt, such as one you made yourself, is left where it is: free it by hand with tailscale serve --https=443 --set-path=/ off if you need to.

The unit starts after tailscaled but does not start it, as the other modes do not need it: for tailscale and tailscale-serve, keep tailscaled enabled.

Provider sign-in does not need a terminal: sign in from the app’s Providers sheet after the first start.

From the checkout:

Terminal window
sudo useradd --system --user-group --create-home --home-dir /var/lib/hadal hadal
sudo mkdir -p /srv/hadal
sudo chown hadal: /srv/hadal
sudo cp contrib/systemd/hadal@.service /etc/systemd/system/

Edit the copy in /etc/systemd/system/ when your paths differ:

  • POCKET_HOME is the checkout, /opt/hadal in the unit. It must contain bin/hadal.js.
  • HOME and --data are /var/lib/hadal: HADAL’s config, sign-ins, database, uploads, and extensions live there.
  • WorkingDirectory and --cwd are /srv/hadal: new sessions start there, and it must be writable by the service user.

Then start an instance:

Terminal window
sudo systemctl daemon-reload
sudo systemctl enable --now hadal@lan

To run as an existing user instead, change User, Group, and HOME together, and point --data at a folder that user can write. Remove StateDirectory when the data folder is not /var/lib/hadal.

The owner’s sign-in link is in the log and is printed again on every start. It is the key to this server, so keep it private:

Terminal window
journalctl -u hadal@lan | grep '/login?token='

Open it once per browser. A cookie lasts a year.

Terminal window
systemctl status hadal@lan
journalctl -u hadal@lan -f
sudo systemctl restart hadal@lan
sudo systemctl stop hadal@lan

To change the access mode, disable the old instance first:

Terminal window
sudo systemctl disable --now hadal@local
sudo systemctl enable --now hadal@lan

The data folder stays the same, so sessions, people, and settings carry over.

Put provider keys and other secrets in /etc/hadal.env, one KEY=VALUE per line, and keep it readable by root only (0600). The unit reads it when the file exists. PATH must include the commands that the launcher and the agents use, such as node, git, gh, tailscale, and cloudflared.

The unit runs with NoNewPrivileges=yes and PrivateTmp=yes. Remove those lines if agents must use sudo or share the host’s /tmp.

Stop the service, back up the data folder, update the checkout, install its packages, and start the service again:

Terminal window
sudo systemctl stop hadal@lan
sudo cp -a /var/lib/hadal /var/lib/hadal.backup
git pull
npm install
sudo systemctl start hadal@lan

If the unit file changed, copy it again and run sudo systemctl daemon-reload before starting.

Menu → Update HADAL can also update the checkout from the app, when the service user owns it (sudo chown -R hadal: /opt/hadal). With the checkout owned by another user, as in the steps above, the sheet only says when a new version is out. A global npm install (npm install -g @t-crypt/hadal) updates from the sheet the same way, when the service user can write the folder that holds the package. An update from the app does not back up the data folder: for a release whose notes have a warning, back it up first, as above.

The launcher has no terminal under systemd, so it uses the mode from --access and never shows its menu. When that mode is not ready, it exits with a message:

Terminal window
journalctl -u hadal@lan -n 30 --no-pager

Check the prerequisites above: cloudflared for a tunnel, a connected Tailscale, or the operator for Tailscale Serve. A port already in use is another common cause. On NixOS, use the module instead of this unit: services.hadal.enable = true;.

These pages describe HADAL 0.29.0. Your copy has the pages of its own version in its docs/ folder.