Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Running as a Service

Linux (systemd)

Save this as ~/.config/systemd/user/rex-iroh.service, with the path to your rex-iroh binary in ExecStart:

[Unit]
Description=Rex over iroh

[Service]
ExecStart=%h/.cargo/bin/rex-iroh serve
Restart=always
RestartSec=10

[Install]
WantedBy=default.target

Then enable and start it:

systemctl --user enable --now rex-iroh

systemctl --user status rex-iroh shows whether it’s running, and journalctl --user -u rex-iroh shows its output, including its ticket. systemctl --user disable --now rex-iroh stops it and keeps it from starting again.

By default, systemd only runs your user services while you’re logged in. On a headless server, or any machine you want to reach without logging in to it first, turn on lingering for your user so they start at boot and keep running:

sudo loginctl enable-linger $USER

Some systems let you run loginctl enable-linger without sudo, but minimal installs without polkit refuse it with Access denied.

macOS (launchd)

Save this as ~/Library/LaunchAgents/rex-iroh.plist, replacing the program path with the output of which rex-iroh and you with your username:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>rex-iroh</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/you/.cargo/bin/rex-iroh</string>
    <string>serve</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <true/>
  <key>ThrottleInterval</key>
  <integer>10</integer>
  <key>StandardOutPath</key>
  <string>/Users/you/Library/Logs/rex-iroh.log</string>
  <key>StandardErrorPath</key>
  <string>/Users/you/Library/Logs/rex-iroh.log</string>
</dict>
</plist>

Then load it:

launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/rex-iroh.plist

A launch agent runs while you’re logged in to the Mac, and starts again each time you log in.

launchctl print gui/$(id -u)/rex-iroh shows whether it’s running, and ~/Library/Logs/rex-iroh.log has its output, including its ticket. To stop it and keep it from starting at login:

launchctl bootout gui/$(id -u)/rex-iroh

Pointing serve at Rex

If serve picks the wrong Rex server, or can’t find one, set REX_SERVER in the service’s environment.

With systemd, add this under [Service]:

Environment=REX_SERVER=unix:///path/to/server.sock

With launchd, add this to the <dict>:

<key>EnvironmentVariables</key>
<dict>
  <key>REX_SERVER</key>
  <string>unix:///path/to/server.sock</string>
</dict>

If Rex isn’t running yet when the service starts, serve exits and the service manager retries until it is.

Running connect as a service

To keep a socket open for every issuer you’ve joined, use the same setup under another name, such as rex-iroh-connect, with connect in place of serve:

ExecStart=%h/.cargo/bin/rex-iroh connect

With launchd, name the plist and its Label rex-iroh-connect, and put connect in ProgramArguments in place of serve.

One service covers every issuer. It picks up issuers you join or forget while it runs, so there’s nothing to change or restart when you do.

If an issuer revokes this device, connect keeps running and serving the other issuers. Its log shows revoked by peer or denied by peer for that issuer; see Troubleshooting.

A device that only joins doesn’t need the serve service at all.