Skip to main content
Rugix Bakery 0.9.6 is here: Build rules for custom image pipelines and verified boot for EFI and Raspberry Pi. Read the release post.
Documentation

Generic

Preview
You're viewing the Next docs — a rolling preview of in-development changes. The current release docs may differ.

The generic orchestrator delegates all lifecycle operations to a user-provided orchestrator script. This is the most flexible orchestrator and can manage any kind of workload.

Getting Started

1. Write the Orchestrator Script

Create an orchestrator script that handles activate, status, deactivate, start, and stop:

orchestrator
#!/bin/sh
set -eu

PID_FILE="$RUGIX_APP_DATA_DIR/daemon.pid"

start_daemon() {
    nohup "$RUGIX_APP_GENERATION_DIR/my-daemon" \
        --data-dir "$RUGIX_APP_DATA_DIR" \
        --pid-file "$PID_FILE" \
        > "$RUGIX_APP_DATA_DIR/daemon.log" 2>&1 &
}

stop_daemon() {
    if [ -f "$PID_FILE" ]; then
        kill "$(cat "$PID_FILE")" 2>/dev/null
        rm -f "$PID_FILE"
    fi
}

case "$1" in
  activate)
    start_daemon
    ;;
  deactivate)
    stop_daemon
    ;;
  start)
    start_daemon
    ;;
  stop)
    stop_daemon
    ;;
  status)
    if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
        echo '{"state": "running"}'
    else
        echo '{"state": "stopped"}'
    fi
    ;;
esac

2. Pack the Bundle

Use rugix-bundler to package the orchestrator script into an app bundle:

rugix-bundler apps pack generic \
    --app my-app \
    orchestrator \
    my-app-v1.rugixb

This command:

  1. Generates the app.toml manifest with orchestrator = "generic".
  2. Packages the orchestrator script and any included files as an app-archive payload.
  3. Produces a Rugix Bundle.

Options:

  • --include adds extra files or directories to the bundle (e.g., binaries, configuration, data files that the orchestrator script needs).
  • --config-schema and --config-default include the app’s optional JSON configuration contract.

3. Install on the Device

rugix-ctrl apps install --bundle-hash HASH my-app-v1.rugixb

Generation Directory

The generation directory must contain:

  • app.toml with orchestrator = "generic".
  • An executable orchestrator script.

Large Files in the Store

Large files, such as container images, can be kept in the store instead of the generation directory. The store keeps their content compressed and shares it between generations. Rugix Ctrl versions without the store cannot read such files; see Compatibility With Older Versions. rugix-bundler apps pack generic packages all files into one archive, so ship each large file as a separate app-file payload with store = true in a hand-written bundle manifest. For example, for a Podman image:

rugix-bundle.toml
update-type = "full"

[[payloads]]
filename = "app.tar"
delivery = { type = "app-archive", app = "my-app" }
block-encoding = { chunker = "casync-64", compression = { type = "xz" } }

[[payloads]]
filename = "image.tar"
delivery = { type = "app-file", app = "my-app", path = "images/image.tar", store = true }
block-encoding = { chunker = "casync-64", compression = { type = "xz" } }

app.tar is a tar archive with app.toml and the orchestrator script. image.tar is an uncompressed image archive, for example from podman save -o image.tar IMAGE. Compressing it would hide shared content from the store and from delta updates. Both belong in a payloads/ directory next to the manifest. rugix-bundler bundle DIRECTORY my-app.rugixb packs the bundle, where DIRECTORY contains rugix-bundle.toml and payloads/ (see Update Bundles).

A stored file does not exist in the generation directory. In the activate branch, the orchestrator script streams it with rugix-ctrl apps cat:

rugix-ctrl apps cat "$RUGIX_APP_NAME" images/image.tar \
    --generation "$RUGIX_APP_GENERATION" | podman load

Pass --generation because the generation being activated is not yet the active one.

Environment Variables

The following environment variables are set when the orchestrator script is invoked:

VariableDescription
RUGIX_APP_NAMEThe app name.
RUGIX_APP_DIRAbsolute path to the app directory.
RUGIX_APP_GENERATIONThe generation number.
RUGIX_APP_GENERATION_DIRAbsolute path to the generation directory.
RUGIX_APP_DATA_DIRAbsolute path to the app’s persistent data directory.
RUGIX_APP_CONFIG_PATHAbsolute path to the effective JSON configuration, when one exists.
RUGIX_APP_RECOVERY"true" if replaying an interrupted transition, "false" otherwise.

The working directory is set to the generation directory.

Operations

For activate, deactivate, start, and stop, a zero exit code means success and non-zero means failure (stderr is included in the error message).

The status operation must print a JSON object to stdout:

{"state": "running"}
{"state": "unhealthy", "message": "health check failing"}
{"state": "stopped"}
{"state": "failed", "message": "process crashed"}
{"state": "unknown"}

If the script exits with a non-zero status or produces invalid JSON, the status is reported as unknown.

Boot behavior after stop: Entirely determined by the script. If the script simply kills a process, the process will not restart on boot unless the activate operation is re-run. Since Rugix only re-runs activation during crash recovery, a stopped workload typically stays stopped across reboots.

The optional logs operation prints the logs of the workload, as described in the next section.

Logs

rugix-ctrl apps logs runs the logs operation of the script, which prints the logs of the workload to stdout, one record per line. Rugix Ctrl passes the selection of records in additional environment variables:

VariableDescription
RUGIX_LOGS_LINESMaximum number of records. The script should print the most recent ones.
RUGIX_LOGS_SINCEOnly records logged at or after this time are selected, in RFC 3339, when given.
RUGIX_LOGS_UNTILOnly records logged at or before this time are selected, in RFC 3339, when given.

Each line is either a log record as a JSON object, in the format that apps logs --json prints, or a plain line that becomes the message of a record. Plain lines are subject to the app’s log format. The script should print the records in chronological order, because Rugix Ctrl keeps their order. Rugix Ctrl applies the selection to the printed records again, so a script may print more records than selected, for example, if it cannot filter by time. A non-zero exit code fails rugix-ctrl apps logs with the script’s stderr in the error message.

For example, a workload that appends its output to a file in the data directory can implement the operation with tail:

logs)
    tail -n "$RUGIX_LOGS_LINES" "$RUGIX_APP_DATA_DIR/app.log"
    ;;

Idempotency and Recovery

Scripts should be written to be idempotent and handle being called again after a partial execution without side effects. When an operation is re-run during crash recovery, the RUGIX_APP_RECOVERY environment variable is set to "true". This allows scripts to take a different code path if needed (e.g., cleaning up partial state before retrying).