cmd
Executes an arbitrary shell command via /bin/sh, gated by an idempotency guard (creates, onlyif, or unless). The mandatory guard keeps the declaration idempotent: once the command’s work is done the guard flips to skip and re-applying reports no change.
Category: System & core
States
| State | Meaning |
|---|---|
run | Run command through /bin/sh unless its guard (creates/onlyif/unless) says the work is already done. |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
command | string | yes | The shell command to execute via /bin/sh -c. |
creates | string | Absolute path; skip the command if this path already exists. Acts as the idempotency guard. | |
onlyif | string | Guard command; run command only if this exits zero. | |
unless | string | Guard command; run command only if this exits non-zero. | |
cwd | string | Working directory the command runs in. | |
env | map | Environment variables (string keys to string values) added to the command’s environment. | |
timeout_seconds | int | Kill the command after this many seconds. Range [0, 3600]. Default: 60. | |
shell | string | Shell interpreter. Only /bin/sh is supported in v1.0; alternate shells are v1.x. Default: /bin/sh. |
Examples
Run once, guarded by a marker file
creates makes the declaration idempotent: the command is skipped once the path exists.
cmd:
bootstrap-db:
state: run
command: /opt/myapp/bin/init-db && touch /var/lib/myapp/.initialized
creates: /var/lib/myapp/.initializedGuard with onlyif and a working directory
cmd:
rebuild-cache:
state: run
command: make cache
cwd: /opt/myapp
onlyif: test -f /opt/myapp/cache.dirty
timeout_seconds: 300Run after a package install, with env
The require requisite orders this command after the package is present.
cmd:
migrate:
state: run
command: myapp migrate
unless: myapp migrate --check
env:
MYAPP_ENV: production
require:
- package: myappNotes
- Linux and macOS only; the module is
/bin/sh-based, so Windows / cmd.exe is v1.x. state: runrequires at least one guard (creates/onlyif/unless) for idempotency; useonlyif: /bin/trueto opt into always-run.createsmust be an absolute path.- A successful Apply always counts as a change; the engine only invokes Apply when Check reports the guards say “run”.
- Out of scope for v0.1:
runas(run as another user), non-POSIX shells, sandboxing (seccomp / namespaces), and command-policy integration.