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 drawbard

drawbard is the optional daemon that runs one git fetch for every equivalent fetch in flight, so a swarm of agents fetching the same clone makes one network fetch where each would otherwise take its turn under the lease. Per-repo lease says which fetches it shares and when the shim fetches on its own instead. Every fetch works without it: when drawbard is not running, or cannot answer, each fetch takes the lease as it would with no daemon.

As a systemd user service

On Linux, drawbar install --drawbard writes drawbard.service to the systemd user unit directory, $XDG_CONFIG_HOME/systemd/user or ~/.config/systemd/user, enables it, and restarts it:

$ drawbar install --drawbard
drawbar: installed /home/acme/.local/opt/drawbar/drawbar
...
drawbar: wrote /home/acme/.config/systemd/user/drawbard.service
drawbar: enabled and started drawbard.service

deploy/install.sh --drawbard passes the flag on. The unit runs %h/.local/bin/drawbar daemon with XDG_RUNTIME_DIR=%t, ~/.local/bin first on PATH, and LimitNOFILE=1048576, starts with the user manager (WantedBy=default.target), and restarts two seconds after it fails. drawbard reads drawbard.coalesce_ttl_secs from the config file when it starts, so restart it after you change that setting:

$ systemctl --user restart drawbard.service

The service listens on $XDG_RUNTIME_DIR/drawbar/drawbard.sock. drawbard creates $XDG_RUNTIME_DIR/drawbar with mode 0700 when it starts, takes the drawbard.lock file there so a second daemon cannot take over the socket, and binds the socket with mode 0600. A shell or service whose XDG_RUNTIME_DIR is unset, or names another directory, does not find the socket, and its fetches take the lease. On a desktop session, XDG_RUNTIME_DIR is /run/user/<uid> both in your shells and in the user manager.

drawbar install without --drawbard leaves the unit file as it is. When drawbar wrote it, install runs systemctl --user try-restart drawbard.service, so a running drawbard switches to the copy just installed. An older drawbard speaks an older protocol and refuses every fetch, so until it restarts each fetch takes the lease, and drawbar doctor says to restart it.

Stopping

systemctl --user stop drawbard.service sends SIGTERM to the daemon alone (KillMode=mixed). drawbard removes its socket at once, so new fetches take the lease, and exits once the fetches it is running finish and their callers have their answers. No fetch fails because the service stopped. A fetch still running after TimeoutStopSec=10min is killed with the daemon, and each caller waiting on it runs its own fetch under the lease. systemd’s default, KillMode=control-group, would send SIGTERM to those fetches too, and every caller would fail with them.

Uninstalling

drawbar uninstall runs systemctl --user disable --now drawbard.service, which waits as a stop does, then removes the unit file. It then removes $XDG_RUNTIME_DIR/drawbar, with the lock file and any socket left in it, once it holds the lock itself, creating the lock file when it is missing, so a daemon that starts meanwhile cannot bind a socket there. It leaves the directory when a drawbard still holds the lock, when it holds other files, or when another user could reach it or put files in it, by the same checks the shim makes before it uses the socket. When systemctl fails, uninstall keeps the unit file, the ~/.local/bin links and the binary the service runs, reports the error, and removes them on the next uninstall, as it does for the timers.

Install refuses, and changes nothing, when a drawbard.service that drawbar did not write is already in the unit directory, the systemd user manager is not reachable, or systemd loads drawbard.service from another file, such as one in ~/.config/systemd/user.control, which systemd searches first. Uninstall leaves such a unit running. Customize the unit with systemctl --user edit drawbard.service drop-ins, which install and uninstall leave alone. See ADR 0017.

Without systemd

The unit is Linux-only, like the timers, and install.sh refuses --drawbard on macOS. Elsewhere, run drawbar daemon yourself, with the same XDG_RUNTIME_DIR your git callers have, from something that gives it no terminal, since a fetch it runs could prompt there. drawbard starts a session of its own when it can, and refuses to start when it cannot and a terminal is still attached. On Linux without a user manager:

$ setsid drawbar daemon < /dev/null > /dev/null 2>&1

macOS sets no XDG_RUNTIME_DIR. To use drawbard there, set it to a directory that belongs to you and that no other user can write to, in your shell profile and in a launchd agent that runs drawbar daemon. SIGTERM or SIGINT stops the daemon as systemctl stop does. Send the signal to the daemon’s own PID: a signal to its process group also reaches the fetches it runs, and they die with it.

Checking it

drawbar status reports the socket, whether drawbard answers and in which protocol, and whether the unit is installed. drawbar doctor reports the same as its drawbard.daemon check: it warns when the unit is installed but nothing listens, when a socket is there but nothing answers, when the shim will not use the socket because it is not private to you, and when the daemon speaks another protocol. Both ask the daemon only for its protocol, with a request every daemon refuses before it runs anything. See Status and doctor.