For the complete documentation index, see llms.txt. A markdown version of this page is at /workstations/packages-tools-settings/scripts-files-services/index.md.

Scripts, files and services

Scripts run setup commands on a workstation, files put content at a path, and services keep a program running.

Scripts run setup commands on a workstation, files put content at a path, and services keep a program running. You declare them once, and Ringleader keeps the workstation matching them. Use them for what packages, devtools and tool configuration don’t cover.

Setup scripts

A setup script runs on the workstation during a configuration pass, after the packages, devtools, files and code are in place. Scripts run in the order you declare them. A script’s phase says who runs it. system, the default, runs it as root, and user runs it as the login user, in their home folder.

A script’s runPolicy says when it runs:

  • once, the default, runs each version of the script once, so editing the script runs it again.
  • onChange also runs it again when a path in watchPaths changes, such as a code source it builds. With no watchPaths, it works like once.
  • always runs it on every pass.
  • onRecycle never runs it in an ordinary pass. It runs once each time the workstation’s spec.recycleNonce changes, which is how a workstation pool cleans a member before its next lease.

A failed recycle deletes the member

A failing onRecycle script fails the recycle, whatever its fatal says, and the pool then deletes the member.

A script’s env can carry ${secret:NAME} references. A script with failOnError: true stops the rest of the pass when it fails, as Scripts that stop the pass explains. A script can also take its body from a ConfigMap instead of carrying it inline.

Declared files

A file entry puts content at a path on the workstation. The content is inline content, contentBase64, a url, or a ConfigMap key in contentFrom. Inline content and contentFrom can carry ${secret:NAME} references. A file under ~/ belongs to the login user, and any other file to root, unless you set owner. Ringleader creates the folders above the file when they are missing.

Ringleader writes a file when its entry, or a secret it uses, changes. It doesn’t check the file on the workstation between changes, so an edit made there stays until the entry changes. By default, a file also stays when you stop declaring it: when you delete its entry, or the layer that carried it stops applying.

Removal of undeclared files

With removeWhenUndeclared: true, Ringleader deletes the file on the next pass after its entry leaves the workstation’s configuration. You set it on each entry. A configuration can lose a layer without anyone editing anything, and deleting every undeclared file would remove healthy files then. Two things to know about it:

  • If you take removeWhenUndeclared off an entry, Ringleader stops tracking the file on the next pass, and the file stays.
  • If a contentFrom reference can’t be resolved, the configuration is incomplete, and Ringleader removes no file at all on that pass.

Edited files are deleted too

Ringleader doesn’t check the file’s content before it deletes it, so a file edited on the workstation is deleted too.

Managed services

A service keeps a program running on the workstation. You give either a full systemd unit or a command, which Ringleader turns into one. By default a service starts at once and starts again each time the workstation boots. Services start after the scripts.

Run a setup script

To build a code source each time it changes, give a script runPolicy: onChange and watch the source’s path:

spec:
  scripts:
    - name: build-app
      phase: user
      runPolicy: onChange
      watchPaths: ["/home/dev/app"]
      content: |
        cd ~/app && make build

To keep a long script in one place, take its body from a ConfigMap key with contentFrom instead of content, as Scripts shows.

Write a file

To put a file on the workstation, list it under spec.files:

spec:
  files:
    - path: ~/.config/app/settings.toml
      content: |
        theme = "dark"
      removeWhenUndeclared: true

Run a service

To keep a program running, list it under spec.services:

spec:
  services:
    - name: docs-preview
      command: /home/dev/app/bin/preview --port 4000
      runAs: dev

Next steps