This guide: sahinit guide · Unit reference · Commands, files & codes
Unit reference
A unit is one JSON file in the unit directory. This page is derived from
internal/unit (unit.go, execution.go, limits.go, sash.go),
internal/jsonobj and internal/graph. There are two kinds of unit:
- an exec unit, which names a program in
exec; - a sash unit, which names a sash service script in
sash(see sash units).
The unit directory
- The directory must not be a symlink (
symlink), must be a directory (failed), and must be owned by root or by the supervisor's effective uid and not writable by group or other (unit_perm). Any of these refuses the whole catalog. - Every entry must be a regular
NAME.jsonfile. A directory, a dot-file or a file without.jsonrefuses the catalog (stray_file); a symlink refuses it (symlink). An empty directory isempty. More than 256 entries istoo_many. - Each file must be at most 64 KiB (
file_size), and owned by root or the supervisor's uid and not group- or other-writable. A file failing the owner and mode rule is left out and reported asunit_perm FILE; the rest of the catalog loads. - Any other problem in a file (a parse or validation error below) refuses the
whole catalog with that token. Only
unit_perm, the file checks ofsash_file_permandsash_grant_perm(a relativesash.fileorsash.grantis a parse error and refuses the catalog), and the later per-unit checks (cgroup_controllerand the sash load checks) leave one unit out. - Two files whose
nameis the same isduplicate_field. If every file is left out, the result isempty.
Decoding rules
Every JSON object in a unit (the unit, execution, sandbox, sash) is
decoded strictly:
- one object, nothing after it (
failed); - an unknown key is
unknown_field; a repeated key isduplicate_field; nullfor a value, a wrong JSON type, or a number that does not fit the field isfailed. (exceptrestart,timeoutand the limits, which reportrestart_invalid,timeout_rangeandlimit_invalid).
Exec unit fields
| Field | Type | Required | Default | Rules (token on failure) |
|---|---|---|---|---|
name |
string | yes | ^[a-z][a-z0-9-]{0,62}$ (name_invalid), and equal to the file name without .json (name_mismatch). |
|
exec |
array of strings | yes | 1 to 32 entries, each at most 256 bytes, no NUL (failed). exec[0] is absolute and clean (exec_relative). See executables. |
|
type |
string | yes | simple or oneshot (type_invalid). |
|
ready |
string | yes | simple: exec or notify. oneshot: exit. Anything else is ready_invalid. |
|
restart |
string | no | no |
no, on-failure or always (restart_invalid). A oneshot must use no (restart_invalid). |
needs |
array of strings | no | none | At most 64, unique (duplicate_field), non-empty (edge_empty). Each must name a unit in the catalog (missing_needs). See dependencies. |
after |
array of strings | no | none | As needs (missing_after for an absent unit). |
wants |
array of strings | no | none | As needs, but an absent unit is ignored. |
timeout |
string | no | 5s |
A Go duration (500ms, 30s, 2m), more than 0 and at most 5m (timeout_range). |
boot |
bool | no | true for simple, false for oneshot |
Whether boot starts it. |
essential |
bool | no | the value of boot |
Only meaningful with supervise --boot-strict (PID 1): an essential unit's failure sends the host to recovery. true needs "boot": true (essential_requires_boot). Set false to let a boot unit fail alone. See strict boot. |
restart_delay |
string | no | 100ms |
A Go duration from 10ms to 5m (restart_delay_invalid): the first automatic restart's delay. |
restart_max_delay |
string | no | 30s |
From 10ms to 5m, not below restart_delay (restart_delay_invalid): the cap of the growing delay. |
watchdog |
string | no | none | From 100ms to 5m; needs "ready": "notify" (watchdog_invalid). See watchdog. |
execution |
object | no | supervisor identity, /, environment with only the default PATH |
See execution. |
sandbox |
object | no | no sandbox | See sandbox. Requires a non-root execution.uid (sandbox_root). |
memory_max |
string | no | no limit | See limits. |
cpu_max |
string | no | no limit | See limits. |
pids_max |
integer | no | no limit | See limits. |
There are no stop, environment_file, user (by name) or working_directory
fields: stop is always SIGTERM to the process group, then SIGKILL (see
lifecycle), and identity and directory live in execution.
Minimal and full examples
{ "name": "web", "exec": ["/usr/local/bin/web", "--port", "8080"], "type": "simple", "ready": "exec" }
{
"name": "worker",
"exec": ["/usr/local/bin/worker"],
"type": "simple",
"ready": "notify",
"restart": "on-failure",
"needs": ["db"],
"after": ["net"],
"wants": ["metrics"],
"timeout": "30s",
"execution": {
"uid": 1000, "gid": 1000, "groups": [27],
"directory": "/var/lib/worker",
"environment": ["APP_MODE=production"]
},
"sandbox": {
"no_new_privs": true,
"read_only_paths": ["/usr", "/etc/ssl/certs"],
"read_write_paths": ["/var/lib/worker"],
"caps": []
},
"memory_max": "256M",
"cpu_max": "50000 100000",
"pids_max": 64
}
{ "name": "migrate-db", "exec": ["/usr/local/bin/migrate"], "type": "oneshot", "ready": "exit", "boot": true }
Types, readiness and restart
type / ready |
Started when | Ends |
|---|---|---|
simple / exec |
at once: the process was started | when the main process exits |
simple / notify |
the process writes at least one byte to fd 3 (SAHINIT_READY_FD=3) within timeout |
when the main process exits |
oneshot / exit |
the process exits 0 within timeout; the state is then exited |
at exit |
- Not ready in time: the process group is killed, the start fails with
timeout, and it is not restarted. - A oneshot that exits non-zero is
failed. restartapplies to asimpleunit whose process exits after it was ready (or at any time withready: exec):alwaysrestarts after any exit,on-failureafter a non-zero exit or a signal. The n-th consecutive crash waitsrestart_delay× 2^(n−1), capped atrestart_max_delay, scaled by a random 80–100 % (so never above the cap); during the wait the state isstarting. Two limits end a crash loop withfailedandrestart_limit: more than 5 restarts in any 30 s, and more than 5 consecutive crashes, counting every exit until a run has stayed ready for the stable period (10 s, ortimeoutwhen longer), however long the delays. A run that stayed ready that long resets the crash count; a manual start resets both. A unit whoseneedsprovider is not ready when the delay ends becomesblocked. In strict boot, an essential unit that has crashed and is still waiting out its delay when the boot waves end counts as not ready, so the boot fails then rather than waiting.- A stop is never followed by a restart.
Watchdog
A "ready": "notify" unit with watchdog keeps its notify pipe (fd 3) open
after the readiness byte and must write another byte within every interval.
End of file on the pipe or a missed interval kills the process group; the
unit's last_error and event are watchdog, and its restart policy applies.
For a program that speaks sd_notify, run it through
sahinit host notify-adapter with the same interval.
This is a service watchdog, not a hardware (/dev/watchdog) one.
Lifecycle
States: stopped, starting, running, stopping, exited (a finished
oneshot), failed, blocked (desired, waiting for a needs provider). Stop sends SIGTERM to the process group, waits up to
timeout, then SIGKILLs. With cgroups, whenever the main process exits for any
reason everything left in the service's cgroup is killed, and the service has
ended only when the cgroup is empty; otherwise it fails with cgroup_stuck.
A stop can therefore take up to twice timeout.
A oneshot started at boot runs exec as written. After boot, a oneshot runs
only through the socket's oneshot operation with one argument appended to
exec ([A-Za-z0-9._-]{1,64} without .., else arg_rejected); ctl start
answers arg_required. Arguments are never logged.
Dependencies
needs: the unit starts only when each named unit is running and ready, or has exited successfully (a oneshot). A failed one makes the start fail withneeds_failed, one not yet ready withneeds_not_ready; either way the unit becomesblocked. The supervisor checks every 200 ms: a running unit whose provider is no longer ready is stopped andblocked(dependents first), and ablockedunit starts once its providers are ready (providers first). A unit an operator stopped is not desired and is left alone.after: ordering only; no requirement.wants: ordering when the named unit exists; ignored when it does not.- The whole catalog, including non-boot units, must be acyclic (
cycle). - A boot unit may not
needsa non-boot unit (boot_needs). - Boot runs waves in order; units in one wave start in parallel. A failed
unit does not stop later waves. In strict host boot an essential unit's
failure then enters recovery (see
essential). - Shutdown stops every unit, including ones started by hand, in reverse wave order; units in one wave stop in parallel.
Executables
exec[0] is resolved once at load, following symlinks one component at a time
(for example Debian's /bin/sh -> dash), and the resolved file is what runs;
argv[0] is passed as written.
- Every directory the walk passes through, from
/, must be owned by root or the supervisor's uid and not group- or other-writable, except a sticky directory such as/tmp(exec_perm). A link inside a directory someone else can write is refused. - The resolved file must be a regular file with an execute bit
(
exec_not_file), owned by root or the supervisor's uid and not group- or other-writable (exec_perm). A missing component or more than 40 links isexec_not_file. - If it does not resolve at load the unit still loads; the check is repeated at every launch, so a program installed later is still checked.
- On Linux the checked file is opened and executed through that file descriptor, so the file checked is the file run.
- A
#!script's interpreter must be an absolute path that passes the same checks and is not itself a script.#!/usr/bin/env ...,#!/bin/busybox env ..., a relative interpreter or a#!line longer than 256 bytes isexec_interp. The script is passed to its interpreter as/proc/self/fd/4.
Execution
"execution": { "uid": 1000, "gid": 1000, "groups": [], "directory": "/srv/app", "environment": ["KEY=value"] }
| Field | Type | Default | Rules |
|---|---|---|---|
uid |
integer | the supervisor's uid | 0 to 4294967294. Given together with gid or not at all. |
gid |
integer | the supervisor's gid | As uid. |
groups |
array of integers | [] with an identity |
Only with uid/gid; at most 64, unique, each below 4294967295. An explicit identity always replaces the supplementary groups. |
directory |
string | / |
Absolute, clean, at most 4096 bytes, no NUL. Must exist and be reachable by the identity at launch. |
environment |
array of strings | [] |
KEY=value literals; at most 128 entries and 16 KiB in total; KEY matches ^[A-Za-z_][A-Za-z0-9_]*$, is unique and does not start with SAHINIT_. |
Every rule violation is execution_invalid (a wrong JSON type or an out-of-range number is failed). IDs are numeric only: there is no
name-service lookup for exec units. Without uid/gid the service runs as
the supervisor (root under PID 1). An unprivileged supervisor that cannot set
the requested credentials fails the start. The environment rules are in
environment.
Sandbox
"sandbox": { "no_new_privs": true, "read_only_paths": ["/usr"], "read_write_paths": ["/var/lib/app"], "caps": [] }
Linux only (sandbox_unsupported elsewhere). The presence of the object turns
the sandbox on; every key is optional.
| Field | Type | Default | Rules |
|---|---|---|---|
no_new_privs |
bool | true |
Always applied; an explicit false is sandbox_privs. |
read_only_paths |
array of strings | [] |
Paths the service may read beneath. |
read_write_paths |
array of strings | [] |
Paths the service may read and write beneath. |
caps |
array of strings | [] |
Capability names from the closed set: chown, dac_override, fowner, kill, setgid, setuid, net_bind_service, net_admin, sys_admin (sandbox_cap). |
- The unit must set a non-root
execution.uid(sandbox_root); the helper also refuses to apply a sandbox while it runs as uid 0. - Paths: absolute, clean, at most 4096 bytes, no NUL (
sandbox_path); at most 64 in total and unique across both lists (sandbox_overlap). Each is resolved once at load through the trusted walk (so/libbecomes/usr/libon merged-/usr); a path that does not resolve is kept as written. At launch each path is opened without following any symlink: a link or a missing path issandbox_path. - Landlock: the ABI is detected (1 to 5 are known) and only the rights it
knows are handled. No Landlock is
landlock_unavailable; a right the ABI lacks islandlock_abi. Everything outside the listed paths is denied for file access. Network access is not confined. - Capabilities: ambient capabilities are cleared and
capsis the set the helper keeps. Because a sandboxed unit runs as a non-root uid, the helper has no capabilities to keep, so a non-emptycapscurrently fails the start withsandbox_cap. Leave it empty. Listingdac_override,fowner,chown,setuidorsys_adminalso makes the unit cgroup-trusted. - The status
sandboxfield reports what was applied, for exampleno_new_privs,landlock_v3,caps, and only while a process runs; an unsandboxed unit reportsnone. - The helper's set-up handshake has a deadline (
sandbox_timeout); a kernel withoutopenat2(before Linux 5.6) isopenat2_unavailable.
Limits
Written into the service's cgroup before the process starts. Needs cgroups.
| Field | Type | Accepted | Writes |
|---|---|---|---|
memory_max |
string | ^[1-9][0-9]{0,15}[KMG]?$: bytes, or binary K/M/G; at least 1M, at most 2^50 bytes |
memory.max, and memory.swap.max = 0 where it exists |
cpu_max |
string | "QUOTA PERIOD" in microseconds: period 1000 to 1000000, quota from 1000 to 1024 periods |
cpu.max |
pids_max |
integer | 1 to 4194304 | pids.max |
A malformed value is limit_invalid and refuses the catalog. A limit whose
controller the cgroup root does not offer, or any limit with --no-cgroups or
off Linux, leaves the unit out as cgroup_controller FILE (in strict boot:
boot_refused). I/O limits, slices and delegating a cgroup to a service are
not supported.
Sash units
A sash unit runs a sash service script through sash --session. Its ordering,
readiness, stop and restart come from sash --describe, and every privileged
action the script asks for is checked against its signed grant. See
operations for set-up and
the sash design for the protocol.
{
"name": "app",
"sash": { "file": "/etc/sahinit/services/app.sash", "grant": "/etc/sahinit/grants/app.grant" },
"execution": { "uid": 990, "gid": 990 },
"sandbox": { "read_only_paths": ["/usr", "/etc/sahinit/services"], "read_write_paths": ["/srv/app"] }
}
| Field | Type | Required | Default | Rules (token) |
|---|---|---|---|---|
name |
string | yes | As for exec units; must also equal the describe output's name (sash_name_mismatch). |
|
sash.file |
string | yes | Absolute, clean path to the service script (sash_file_perm). At load and before every start: resolved by the trusted walk, a regular file owned by root or the supervisor's uid, not group- or other-writable, no setuid, setgid or sticky bit (sash_file_perm). |
|
sash.grant |
string | yes | Absolute path to the signed sash/2 grant (sash_grant_perm). The same checks, and mode exactly 0600 (sash_grant_perm). |
|
execution.uid, execution.gid |
integers | yes | Non-zero (sash_root). They must equal what the describe output's user and group resolve to through the system user and group databases (sash_identity_mismatch). |
|
sandbox |
object | yes | Required (sash_sandbox); rules as above. The unit must not be cgroup-trusted (sash_cgroup_trusted). |
|
restart |
string | no | from describe | If set, must equal describe's policy (no equals sash's never) (sash_lifecycle_mismatch). |
needs, after, wants |
arrays | no | from describe | If set, must be the same set as describe's requires, after, wants (sash_order_mismatch). |
boot |
bool | no | true |
A sash boot unit is always essential in strict boot; it has no essential field. |
memory_max, cpu_max, pids_max |
no | none | As above. |
Refused on a sash unit (sash_unit_field): exec, type, ready,
timeout, essential, restart_delay, restart_max_delay, watchdog,
execution.groups, execution.directory,
execution.environment.
sash --describe limits: a ready or stop timeout or a restart delay above 5
minutes, a restart burst above 5, or a restart window (within) shorter
than the restart delay, is sash_lifecycle_limit. A sash unit's restarts
also stop at restart_limit after its burst of consecutive crashes without
a run that stayed ready for the stable period, as for exec units. Ordering names
must be valid unit names (sash_order_mismatch). A non-zero exit, malformed
output or no start/run entry is sash_describe. sahinit plan does not
run describe; it checks only the unit file and the file permissions.
Refusal tokens by field
| Token | Cause |
|---|---|
failed |
malformed JSON, null, a wrong type, a missing required field, too many or too long exec entries |
unknown_field, duplicate_field |
unknown or repeated key; repeated edge; two units with one name |
name_invalid, name_mismatch |
name grammar; file name differs |
exec_relative |
exec[0] not absolute and clean |
type_invalid, ready_invalid, restart_invalid, timeout_range |
the fields above |
essential_requires_boot, restart_delay_invalid, watchdog_invalid |
essential, the restart delays, watchdog |
edge_empty |
an empty dependency name |
execution_invalid |
any execution rule |
sandbox_root, sandbox_privs, sandbox_path, sandbox_overlap, sandbox_cap |
sandbox rules |
limit_invalid |
a limit value |
sash_* |
sash unit rules above |
cycle, missing_needs, missing_after, boot_needs |
the dependency graph |
All tokens are explained in codes.
Environment reference
sahinit reads no environment variable of its own: there is no
SAHINIT_* configuration variable, and every setting is a flag or a file.
This page lists what it sets for the processes it starts and the few
variables that still affect it through the Go runtime and libraries. It is
derived from internal/unit/execution.go, internal/sandbox,
internal/hostinit/init_linux.go, internal/supervise/sash*.go and
internal/bootpolicy/refresh.go.
Variables sahinit sets
| Variable | Set for | Value |
|---|---|---|
SAHINIT_READY_FD |
exec units with "ready": "notify"; every process a sash service spawns |
3. Write at least one byte to fd 3 to report readiness. The fd is the write end of a pipe; close it when done. |
PATH |
every service process, the sandbox helper, sash --describe, sash --session and sash-spawned processes |
/usr/bin:/bin:/usr/sbin:/sbin unless the unit's (or the spawn's) environment sets PATH, which then replaces it. |
NOTIFY_SOCKET, WATCHDOG_USEC |
the child of sahinit host notify-adapter only |
A private datagram socket path, and the --watchdog interval in microseconds when it is set. The adapter removes any inherited SAHINIT_*, NOTIFY_SOCKET and WATCHDOG_* first. |
PATH, HOME, TERM |
the supervisor and the recovery program started by PID 1 | exactly PATH=/usr/sbin:/usr/bin:/sbin:/bin, HOME=/root, TERM=linux, and nothing else. |
No other variable is added. In particular the supervisor does not set NOTIFY_SOCKET
(only notify-adapter does, for its own child),
LISTEN_FDS, INVOCATION_ID, HOME, USER, LOGNAME or SHELL for
services: set what a program needs in execution.environment.
Clean environment rules
-
Services never inherit the supervisor's environment. A service gets exactly its unit's
execution.environment, plus the defaultPATHwhen it sets none, plusSAHINIT_READY_FD=3for notify readiness. -
execution.environmententries are literalKEY=valuestrings, with no shell expansion. At most 128 entries and 16 KiB in total.KEYmust match^[A-Za-z_][A-Za-z0-9_]*$, must be unique and must not start withSAHINIT_(reserved). Any violation isexecution_invalidat load. -
There are no environment files and no per-unit inheritance switch.
-
The sandbox helper (
sahinit apply) runs with the service's environment and passes it on unchanged (adding onlySAHINIT_READY_FD). -
sash units may not set
execution.environment(sash_unit_field).sash --describeandsash --sessionget only the defaultPATH. -
Processes a sash service spawns get the names the spawn asked for, only if each is on the grant's
env_nameslist, matches^[A-Z][A-Z0-9_]{0,63}$and is not on the fixed denylist (env_refusedotherwise). At most 128 entries and 16 KiB. The denylist (copied from sash'sinternal/grant/policy.goand pinned by a test vector) is:- prefixes
LD_,DYLD_,MALLOC_,GIT_; GCONV_PATH,LOCPATH,NLSPATH,HOSTALIASES,RES_OPTIONS,GLIBC_TUNABLES,TZDIR,BASH_ENV,ENV,IFS,SHELLOPTS,PYTHONPATH,PYTHONHOME,PYTHONSTARTUP,PYTHONWARNINGS,PERLLIB,PERL5LIB,PERL5OPT,PERL5DB,RUBYLIB,RUBYOPT,NODE_OPTIONS,NODE_PATH,JAVA_TOOL_OPTIONS,_JAVA_OPTIONS,JDK_JAVA_OPTIONS,CLASSPATH,LUA_PATH,LUA_CPATH,OPENSSL_CONF,OPENSSL_ENGINES.
A secret value passed to a spawn is written only into the child's environment: never into logs, status, diagnostics or events. A spawned child never dumps core (
RLIMIT_COREis always 0), so a dump cannot carry it. - prefixes
Variables that affect sahinit itself
sahinit does not read these, but the Go runtime or standard library does, in
the supervisor's own process (and in sahinit policy, which runs in yours):
| Variable | Effect |
|---|---|
GODEBUG, GOMAXPROCS, GOGC, GOMEMLIMIT, GOTRACEBACK |
Go runtime behaviour. Under PID 1 the supervisor has none of them. |
SSL_CERT_FILE, SSL_CERT_DIR |
Where sahinit policy refresh finds the system root certificates (Go's crypto/x509 on Linux). A unit launch passes only the unit's own environment, so set them there if needed. |
HTTPS_PROXY, HTTP_PROXY, NO_PROXY |
Ignored: the renewal client uses no proxy. |
The supervisor's own environment under another init (for example systemd) is whatever that init gives it; it does not reach services.
File descriptors (for completeness)
Not environment variables, but part of the same contract:
| Process | fd 0, 1, 2 | Other fds |
|---|---|---|
| exec unit | /dev/null, captured stdout, captured stderr |
fd 3: readiness pipe (notify only). A #! script also keeps fd 4 for its interpreter. Every other fd from 3 up is closed at exec. |
sash --session |
/dev/null, captured stdout, captured stderr |
3: grant bytes, 4: fleet public key, 5: a fresh per-session public key with no private half kept (sash requires one), 6: the verb socket. |
| sash-spawned process | /dev/null, its stream (journal, null or a file: path) |
fd 3: readiness pipe. |
| PID 1 children | /dev/console |
none |
Built from the sash-init repository's reference documentation (docs/reference) at commit 9dce56e on branch feat/host-ops. That branch is the reviewed chain, licensed GPL-3.0-or-later; it is not yet merged into main.