Skip to content

The daemon

runy is a client and a server. The runy CLI and the console talk gRPC to a daemon on 127.0.0.1:4122; the daemon owns the workspaces, runs the resources, keeps the journals and serves the console and the proxy.

Any CLI call connects to the daemon and starts one in the background when none answers. It outlives the shell, and when it starts it brings back every workspace it ran before with its enabled namespaces (a workspace whose folder is gone is forgotten), so after a reboot the first runy command brings the stacks back.

Terminal window
runy daemon start # start it explicitly (it daemonizes)
runy daemon stop # stop it and everything it runs
runy daemon restart # a full stop and start

runy daemon start takes --addr for the API, --proxy-addr for the proxy, --stdout, --stderr and --pidfile for where a daemonized process writes, and --daemonize false to stay in the foreground (for a service manager). --no-daemon on any command runs it against a daemon in the same process, for debugging.

The CLI and the daemon carry a build version. A client whose build differs from the daemon’s upgrades it in place, the way systemctl daemon-reexec does, instead of restarting it:

  1. The client calls Upgrade with its own binary.
  2. The daemon stops following files, asks every resource for its handover state (a process: its pid and pipe descriptors, or how it exited; a port: its value; a worktree: its { ready, hooks_pending, workspace }; a vm: its { machine }) and writes the record next to its pidfile.
  3. It clears close-on-exec on exactly those descriptors and execs the new binary with --adopt <record> under the same pid. The processes stay its children with their pipes open.
  4. The new daemon adopts them before its first reconcile and republishes their statuses, so dependents do not restart. It then reconciles as usual: a resource that renders to the adopted spec keeps its pid and port; one whose render changed meanwhile gets the normal apply.

Calls made during the adoption wait for it; runy ps answers once it is done. A daemon too old to know Upgrade, or whose exec fails, is terminated and started fresh. runy daemon restart is always a full restart.

runy info folder prints the daemon’s two per-user folders. The state folder (~/.config/runy, or $XDG_CONFIG_HOME/runy) holds state.sqlite, with the workspace list, each workspace’s applied documents, enabled namespaces, runy start|stop overrides and loaded sources, and the records of its resources, beside secrets.key (this machine’s age key for secrets, mode 0600; back it up, since values encrypted to it cannot be read without it), secrets.revision (the key of the secrets’ placeholder revisions; it decrypts nothing), daemon.json (the host label) and the mesh identity and peers. The cache folder (~/.cache/runy, or $XDG_CACHE_HOME/runy) holds what can be regenerated: the journals, folder resources with cache: true, template builds, the worktrees, the guest runy binaries a vm downloads and the handover record. The daemon’s own logs, when daemonized, go to runy.out.log and runy.err.log there. Setting XDG_CACHE_HOME without XDG_CONFIG_HOME is refused.

The cache folder grows: a template’s packs take several GB each, a VM’s disk more, and smolvm keeps unpacked copies of the packs machines were created from. Workspaces that were deleted or moved leave their cache folders behind. runy prunes a template’s builds after each build and nothing else by itself.

Terminal window
runy gc # what is reclaimable, with sizes and reasons
runy gc --apply # remove it

runy gc lists the template builds no instance uses any more, machines with runy’s labels that no resource holds, the cache folders of workspaces the daemon does not know, guest binaries of other versions and smolvm’s cache of unpacked packs, and shows the size of the cache, the builds each template keeps and the machines resources hold. --apply removes what the report lists, checked again at that moment. It assumes this daemon is the only runy using smolvm’s machines. See runy gc.

Terminal window
runy signal <namespace>/<kind>/<name> restart|stop
runy signal workspace restart

The first is forwarded to the resource (a process takes restart and stop, a vm also setup, sync and pack, a template build, adopt, remove and prune; other kinds ignore signals they do not know). The second re-reads every resource file and re-snapshots the environment, which is how edits are picked up without watchman. Documents added with runy apply need neither watchman nor a restart, and they survive restart, daemon restarts and upgrades.