Skip to content
suit Artifact [75b852b23e]
Login

Artifact [75b852b23e]

Artifact 75b852b23ebf3db2ef0471483fb292940b7f9e7d17859a7c3aa630df9e511aa8:


# 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. |

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

## The files

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

- `app.zeitforge.suit.run.plist`
- `app.zeitforge.suit.tend.plist`

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):

- `suit-run.service` and `suit-run.timer` (OnBootSec and OnUnitActiveSec 60s,
  AccuracySec 1s)
- `suit-tend.service` and `suit-tend.timer` (3600s, Persistent true)

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). Running install again then finds the files
unchanged and loads nothing.

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:

- `suit: N need you` when the attention file has N items (an item is a line
  that is not indented);
- `suit: not installed` when any timer file is absent;
- `suit ok` otherwise.

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`.