Skip to content
suit Install
Login

Install

suit install makes suit run by itself. It sets up two timers, both owned by suit and named so they are recognisably suit's:

Timer Every Starts Does
run 60 seconds suit-run The no-change compare. It replaces itself with suit run when something differs.
tend 3600 seconds suit tend Every wardrobe: lint, check in, sync; then the usage scan (usage.md).

Two timers, not one, so the minute run stays inside its speed budget and each job can be seen and stopped by itself.

When the minute run finds the lock held (the hourly tend, or a command you started), it exits 20 without a word and changes nothing; the stamp is not moved, so the next minute applies the change. Every other command still says another suit holds the lock when it is busy.

The files

On macOS they are two launchd user agents in $HOME/Library/LaunchAgents:

Each holds Label, ProgramArguments (absolute paths), StartInterval, RunAtLoad (false), ProcessType Background, LowPriorityIO, StandardErrorPath ($SUIT_HOME/log/run.err or tend.err) and, only when SUIT_HOME is set to something other than $HOME/.suit, an EnvironmentVariables entry for SUIT_HOME.

On Linux they are systemd user units in $HOME/.config/systemd/user (or $XDG_CONFIG_HOME/systemd/user when that is set):

The services are Type=oneshot; the timers are WantedBy=timers.target. suit install --print shows the exact text of each file for this machine. Paths are XML-escaped in a property list and quoted for systemd; a path with a space works. A path with a newline or other control character, or one over 1024 bytes, is refused.

suit install

  1. Finds the absolute path of the running suit and of the suit-run beside it. Refuses, saying which, when suit-run is not there or either is not an existing executable file.
  2. Makes the folder if needed (and, on macOS, $SUIT_HOME/log, which launchd needs before it can open the error file), then writes each file whose text differs, atomically, mode 0644.
  3. Asks the loader to load the timers: on macOS launchctl bootstrap gui/UID PLIST (after bootout gui/UID/LABEL when an older file was there); on Linux systemctl --user daemon-reload, then systemctl --user enable --now NAME.timer. The loader is run directly with an absolute path, never through a shell, and waited for.

It says one line per timer: installed, updated or already installed. Run again with nothing changed it writes nothing, loads nothing and says already installed. A file that differs from what suit would write (an old version, a changed path) is rewritten and its timer loaded again.

When any file is written, both timers are loaded again, so an install that stopped half way is finished by the next one. If the loader exits non-zero the command exits 3, names the loader's exit status, leaves the files in place and says so; load them by hand (below). It also leaves one item in the attention file, timers load: written but not loaded (LOADER exit N), where LOADER is launchctl or systemctl and N its exit status, or could not run. So suit status --line says suit: 1 need you and suit status shows the item under needs you:.

Running install again, with the files unchanged and the item there, does not say already installed: it asks the loader to load again. If that works the item goes (and the attention file with it, when it is empty) and each timer says installed; if not, the item is updated and the command exits 3 again. A successful install by any path, and suit uninstall, remove the item.

If a write fails, nothing is loaded and the command exits 1; a file already written stays, and the next suit install finishes the job.

It never touches a file in those folders that is not one of its own names.

suit uninstall

Asks the loader to unload each timer, then removes exactly the files above and says removed PATH for each. Folders are left. When no file is there it says not installed and calls nothing. A loader that exits non-zero on unload is reported but the files are still removed: a timer that was not loaded is normal.

suit status --line

One short line for a status bar, exit 0, at most 60 characters:

Attention wins when both apply. It reads only the attention file and checks that the timer files exist; it opens no repository. If it cannot tell it exits 1 and says why on standard error.

Plain suit status ends its timers line the same way: timers: installed, timers: not installed or timers: differ from this suit (run suit install).

Checking by hand

macOS:

launchctl print gui/$(id -u)/app.zeitforge.suit.run
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/app.zeitforge.suit.run.plist
launchctl bootout gui/$(id -u)/app.zeitforge.suit.run

Linux:

systemctl --user list-timers 'suit-*'
systemctl --user status suit-run.service
systemctl --user enable --now suit-run.timer

Tests

The tests set HOME and SUIT_HOME to a scratch folder and point suit at a fake loader with SUIT_LOADER, and can choose which set of files is written with SUIT_PLATFORM=linux|macos. Both variables exist only in the test builds (the ones with fault injection); the release build has no code that reads them, which test/release_clean.sh checks. No test runs launchctl or systemctl.