Reference
This page documents the technical internals of Rugix Apps: app and generation state machines, storage layout, bundle format, stored files, systemd integration, crash recovery, and the CLI reference. For an introduction, start with Application Management.
App State Machine
An app is always in one of the following states:
stateDiagram-v2
[*] --> Inactive
Inactive --> Switching: switch
Active --> Switching: switch
Switching --> Active: activated
Switching --> Error: failed
Switching --> Inactive: deactivated
Error --> Switching: switch
Active --> Starting: start
Starting --> Active: started / failed
Active --> Stopping: stop
Stopping --> Active: stopped / failed
Activation, deactivation, generation switches, and configuration changes are all represented by the Switching state. Its from and to values are deployment pairs consisting of a generation and an optional device-specific configuration revision. The from deployment is deactivated first, then the to deployment is activated. If activation fails and a from deployment is available, rollback to that exact pair is attempted automatically. If rollback also fails, the app enters the Error state and requires manual intervention.
Starting and stopping are represented by the Starting and Stopping states. The app’s lifecycle state always returns to Active once the operation finishes; whether the workload itself is then running is reported separately by status. These states exist for crash recovery: if the system crashes while in one of them, the operation is replayed on the next boot.
If the system crashes while in the Switching, Starting, or Stopping state, crash recovery retries the operation on the next boot.
Generation State Machine
A generation is either incomplete or complete. When a bundle is installed, a new generation is created in the incomplete state. Once all files have been fully extracted, it transitions to complete. To remove a generation, it is first marked incomplete again and then its files are deleted.
stateDiagram-v2
direction LR
[*] --> Incomplete: install
Incomplete --> Complete: installed
Complete --> Incomplete: remove
Incomplete --> [*]: purged
Incomplete generations are always safe to purge, whether they result from an interrupted installation or an interrupted removal.
On the filesystem, each generation is a numbered subdirectory under <app>/generations/. The complete/incomplete state is determined by the presence of a .rugix/complete marker file inside the generation directory.
When a generation is successfully activated, the lastActivated timestamp in .rugix/generation.json is updated. Rollback only considers generations that have been activated at least once, ensuring it never targets a generation that was installed but never activated.
Storage Layout
App data is stored in the Rugix state directory at /run/rugix/state/apps/ (or /var/lib/rugix/apps/ if Rugix state management is not active). Using the state directory ensures that a factory reset also clears installed apps and their data. Each app has the following directory structure:
<apps-dir>/<app>/
├── .rugix/
│ ├── state.json # app lifecycle state
│ └── configuration-state.json # desired and highest allocated revisions
├── configurations/
│ ├── 1.json # device-specific JSON revision
│ └── 2.json
├── current -> generations/3 # activated generation
├── generations/
│ ├── 1/ # old generation
│ │ ├── app.toml
│ │ ├── ...
│ │ └── .rugix/
│ │ ├── generation.json # metadata (number, timestamps)
│ │ └── complete # marker: fully installed
│ ├── 2/ # another old generation
│ └── 3/ # current generation
│ ├── app.toml
│ ├── docker-compose.yml
│ ├── images/
│ │ └── rugix-images.json # image metadata (images are in the store)
│ └── .rugix/
│ ├── generation.json
│ ├── complete
│ └── systemd/
│ └── units/ # rendered systemd units (binary orchestrator)
│ └── ...
└── data/ # persistent app data (survives generations)
Key aspects:
- Current generation. The relative
currentsymlink points to the activated generation. It remains available while its workload is stopped or starting. During a deployment switch, it continues to point to the previous generation until activation succeeds, then Rugix replaces it atomically. It also remains available during deactivation until the app becomesInactive. It is absent in theInactiveandErrorstates and during an initial activation with no previous generation. Generations may contain compatibility metadata in.rugix/componentsand optional health definitions supplied by app payloads in.rugix/health/nodes. External readers can discover these files through<apps-dir>/*/current/.rugix/; they should skip missing directories. The symlink exposes the files but does not load health definitions by itself. - Persistent data directory. The
data/directory is shared across all generations. It is the right place for databases, caches, or any state that should survive app updates. - Complete marker. The
.rugix/completefile is written only after all payloads for a generation have been fully extracted. Its absence means the generation is incomplete. - Generation metadata. The
.rugix/generation.jsonfile stores the generation number, creation timestamp,lastActivatedtimestamp, the configuration revision used for the most recent successful activation, theoriginsupplied withapps install --origin, if any, and whether it was installed with--no-activate(staged). Rollback only considers generations wherelastActivatedis set. Garbage collection removes generations withoutlastActivated, unless they are complete, staged, and newer than every activated generation. - Configuration revisions. Device-specific JSON documents are immutable, numbered files under
configurations/. The directory is restricted to root..rugix/configuration-state.jsonrecords the desired revision and highest allocated revision independently from lifecycle state, ensuring a revision number is never reused for different content. - State file. The
.rugix/state.jsonfile tracks the app’s lifecycle state, including the configuration revisions in intermediate states used for crash recovery.
App Bundles
App bundles use the same Rugix Bundle format as system update bundles. The difference is in the payload type: instead of slot payloads that target partitions, app bundles contain app payloads that populate files within a generation directory.
There are currently two app payload types:
app-file: delivers a single file into the generation directory or the store.app: the app name.path: the relative path within the generation directory where the file should be placed.mode: optional Unix file mode, for example755for executables. Rugix Ctrl rejects a bundle that setsmodefor a stored file.store: optional, keeps the file in the store instead of the generation directory whentrue.
app-archive: delivers a tar archive that is extracted into the generation directory.app: the app name.
An app bundle installs exactly one app, because it becomes one generation of that app. It may carry any number of payloads for that app, applied in manifest order so that later payloads overlay earlier ones. For example, a bundle could ship a base archive followed by individual file payloads that override specific configuration files. Among app-file payloads, the last one for a path wins, whether it is stored or not. A stored file takes precedence over a file extracted from an app-archive payload at the same path, even if the archive comes later, because readers check the store first. Avoid shipping both. A manifest naming several apps is rejected when the bundle is packed, and again before it is installed. Pack one bundle per app.
app-file payloads are ideal for large artifacts (Docker image tarballs, binaries) because they leverage the bundle format’s support for compression, block-level deduplication, and delta encoding. With store = true, the device also keeps the file compressed and deduplicated across generations.
app-archive payloads are convenient for delivering many small files at once (configuration, scripts, templates) without the overhead of a separate payload per file.
Stored Files
An app-file payload with store = true is kept in the Rugix Ctrl store instead of the generation directory. The store keeps each distinct chunk of content once and compressed, so generations whose files share most of their content use little more space than one. In the store, the file PATH of generation N of app APP has the ref apps/APP/N/PATH, so rugix-ctrl store list apps/APP lists the stored files of an app.
A stored file does not exist in the generation directory. rugix-ctrl apps files lists the files that app-file payloads delivered to a generation and shows which of them are stored, and rugix-ctrl apps cat reads a file of a generation, wherever it is kept. Orchestrators use apps cat to read stored files, as shown for the generic orchestrator. The Docker Compose orchestrator loads stored images by itself.
Removing a generation deletes its directory. rugix-ctrl apps gc and rugix-ctrl apps remove then run the store’s garbage collection, which deletes the stored files of every generation whose directory no longer exists, including generations that an older Rugix Ctrl version removed. Stored files of an interrupted installation stay in the store until rugix-ctrl apps gc removes the incomplete generation.
Compatibility With Older Versions
Rugix Ctrl versions without the store ignore store = true and write the file into the generation directory. They cannot read files that a newer version stored and have no rugix-ctrl apps cat. After a system rollback to such a version, its Docker Compose orchestrator can only activate generations whose images Docker still has, and orchestrator scripts calling rugix-ctrl apps cat fail. As long as devices may roll back to such a version, pack Docker Compose apps with --image-location file and do not set store = true for other apps.
Systemd Integration
Orchestrators that use systemd (such as binary) persist rendered unit files under .rugix/systemd/units/ inside the generation directory. This ties the rendered units to the generation lifecycle: when a generation is garbage collected or removed, its rendered units are cleaned up automatically.
Runtime installation. When a generation is activated, the rendered systemd unit is written to two locations:
<gen_dir>/.rugix/systemd/units/inside the generation directory. This copy persists across reboots./run/systemd/system/, the systemd runtime directory, for immediate availability.
A daemon-reload is triggered so systemd picks up the new unit.
Boot-time restoration. Since /run/ is a tmpfs and its contents do not survive reboots, a oneshot service is needed to restore the units on boot:
[Unit]
Description=Restore Rugix app units into systemd
After=local-fs.target
DefaultDependencies=no
[Service]
Type=oneshot
ExecStart=rugix-ctrl apps service-manager systemd restore-units
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetThe rugix-ctrl apps service-manager systemd restore-units command copies persisted unit files from the active generation’s .rugix/systemd/units/ directory into /run/systemd/system/, triggers a daemon-reload, enables each unit with systemctl enable --runtime, and queues each unit for start with systemctl start --no-block.
The enable --runtime step registers the unit with systemd (so systemctl is-enabled reports the correct state) and creates runtime .wants/ symlinks based on the unit’s [Install] section. The start --no-block step queues a start job and returns immediately; systemd resolves the unit’s declared dependencies (After=, Requires=, etc.) asynchronously and starts the unit once its dependencies are met, without blocking the restore service or the rest of the boot process.
This service should be enabled on systems that use systemd as the service manager.
Crash Recovery
Activating and deactivating a generation involves multiple steps (running orchestrator hooks, updating state, cleaning up resources). If the system loses power or crashes mid-transition, these operations could be left in an inconsistent state.
To handle this, Rugix Apps tracks the app’s lifecycle state in <app_dir>/.rugix/state.json.
The state is updated before a transition begins and again after it completes.
If the system comes back up and the state is still intermediate, recovery replays the operation.
rugix-ctrl apps info reports this state as lifecycle, to keep it apart from the live workload status beside it.
The state file records one of:
inactive: no generation is active.switching: a deployment transition is in progress. Records optionalfromandtogenerations with their configuration revisions, plus arecoveryflag indicating whether this switch is a recovery attempt.active: a generation is active and ready to run.starting: the workload of an active generation is being started.stopping: the workload of an active generation is being stopped.error: a transition and automatic rollback both failed. Records thefromgeneration (previously active, if any), thetogeneration (that failed to activate), and an error message. Crash recovery attempts to re-activate thefromgeneration first, falling back to thetogeneration if that also fails.
If the system crashes while in the switching state, recovery retries the switch forward. If it crashes in the starting or stopping state, recovery replays the start or stop operation and then transitions back to active.
When a switch fails rather than being interrupted (the operation returns an error), the previous generation is automatically rolled back. If rollback also fails, the app transitions to the error state.
Automatic recovery should be run via a separate boot service that starts late enough for all required dependencies (Docker daemon, network, etc.) to be available:
[Unit]
Description=Recover interrupted Rugix app transitions
After=multi-user.target rugix-apps-restore-units.service docker.service
Wants=rugix-apps-restore-units.service
[Service]
Type=oneshot
ExecStart=rugix-ctrl apps recover
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetThe rugix-ctrl apps recover command can also be called manually at any time.
Recovery also reconciles each app’s current symlink with its persisted lifecycle state. This repairs a missing or stale link after a crash and creates links for apps activated by earlier Rugix versions. State and link updates are separate filesystem operations; readers should retry during transitions. Rugix replaces links atomically and syncs the app directory before an operation completes.
CLI Reference
| Command | Description |
|---|---|
rugix-ctrl apps install BUNDLE [--config FILE] | Install apps from a bundle (- for stdin). |
rugix-ctrl apps install BUNDLE --no-activate | Install a generation without activating it. |
rugix-ctrl apps install BUNDLE --origin JSON | Install apps and record the origin of the new generation. |
rugix-ctrl apps list | List all installed apps with status. |
rugix-ctrl apps info APP | Show details for an app. |
rugix-ctrl apps config get APP | Print the effective JSON configuration. |
rugix-ctrl apps config schema APP | Print the app’s JSON Schema. |
rugix-ctrl apps config set APP [SOURCE] | Validate, store, and apply JSON configuration. |
rugix-ctrl apps activate APP [GENERATION] [--config FILE] | Activate a generation (starts the app). |
rugix-ctrl apps deactivate APP | Deactivate the current generation (stops it). |
rugix-ctrl apps start APP | Start the workload of an active app. |
rugix-ctrl apps stop APP | Stop the workload without deactivating. |
rugix-ctrl apps rollback APP | Roll back to the previous generation. |
rugix-ctrl apps remove APP | Remove an app entirely. |
rugix-ctrl apps generations APP | List all generations. |
rugix-ctrl apps files APP [--generation N] | List the files that app-file payloads delivered to a generation and whether they are stored. |
rugix-ctrl apps cat APP PATH [--generation N] | Write a file of a generation to stdout, wherever it is kept. |
rugix-ctrl apps gc [APP] [--keep N] | Garbage collect old generations and unreferenced configuration revisions, and delete stored files of removed generations. |
rugix-ctrl apps recover | Recover interrupted transitions for all apps. |
rugix-ctrl apps service-manager systemd restore-units | Restore app units into systemd (for boot). |
Without --generation, apps files and apps cat use the active generation. Both read the state directory directly and therefore require root privileges. The store reference describes the rugix-ctrl store commands.