[[app]]
An [[app]] block contains the settings for one application: its limits, its capabilities, its mode and its origin.
A block names the programs that it covers in one of two ways. root is a directory, and the block covers every entry file inside it. entry is one file. A block has exactly one of the two. A block with both or with neither gives the error E0609.
When nvs run <file> starts, every block that covers the file applies. The global blocks apply first, then the root blocks from the widest directory to the narrowest, then the entry block. A later value replaces an earlier one. So an [[app]] block can lower a limit, lower a ceiling, or remove a capability that the global configuration grants.
Good to know: a root or entry that does not exist stops the run with an error. [app.limits] and [app.limits.hard] take the same keys as [limits] and [limits.hard].
Examples
The examples below run with this configuration file.
# Every program on this server gets these limits.[limits]memory = "256M"
[limits.hard]memory = "512M"
# This block covers every program in this directory.[[app]]root = "."
[app.limits]memory = "192M"
# This block covers one file only. It is the most specific block, so its values win.[[app]]entry = "01-a-smaller-limit-for-a-nightly-job.nvs"
[app.limits]memory = "128M"
[app.limits.hard]memory = "256M"A smaller limit for a nightly job
<?nvs// Shows a nightly job that gets its own memory limit from an `[[app]]` block in `nvs.toml`.// Three places in that file set `memory`. The block that names this file wins.
// This prints `memory: 128M`.echo 'memory: ', Core\Config::get('memory') ?? '(unset)', "\n";
// The same block lowers the ceiling to `256M`. The job cannot go above it.// This prints `300M: no`.echo '300M: ', Core\Config::set('memory', '300M') ? 'yes' : 'no', "\n";
// A value under the ceiling is allowed. This prints `200M: yes`.echo '200M: ', Core\Config::set('memory', '200M') ? 'yes' : 'no', "\n";memory: 128M300M: no200M: yesapp
Configures one application: which settings, limits and permissions apply to a program, chosen by where that program's file lives.
One server can run several applications side by side. An [[app]] block names either a directory or a single entry file, and everything written inside it applies only to programs under that name. Where more than one block covers a program, the more specific block wins, and a block that says nothing about a setting leaves whatever the wider one said in place. A block can take permissions away as well as grant them, and narrow limits as well as widen them, but it can never reach past the ceilings set for the server as a whole.
Good to know: these blocks belong to whoever deploys the server. A running program can read the settings it ended up with, and can tighten its own limits for the rest of its run, but it can never change the block that configured it — one that could would be choosing its own permissions, or another application's.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The examples below run with this configuration file.
# Every request starts with 256M of memory.[limits]memory = "256M"
# This block covers every file in this directory.[[app]]root = "."
[app.capabilities.script]spawn = true
# This block covers one file. It sets a smaller memory limit for that file.[[app]]entry = "01-settings-for-one-application.nvs"
[app.limits]memory = "64M"Settings for one application
<?nvs// A program uses the settings of every `[[app]]` block in `nvs.toml` that covers its file.// The `nvs.toml` beside this file has two blocks. One covers the whole directory.// The other covers this file only. When both set the same value, the block for this file wins.
// Only the block for this file sets `limits.memory`, so this prints `64M`.// Other files in the directory use the value from `[limits]`.echo 'memory: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
// Only the block for the whole directory sets `spawn`.// This file uses that value too, so this prints `true`.echo 'spawn: ', Core\Config::get('capabilities.script.spawn') ?? '(unset)', "\n";
// A program may lower its own memory limit for the rest of the run.echo 'narrow: ', Core\Config::set('limits.memory', '32M') ? 'yes' : 'no', "\n";echo 'memory: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
// A program cannot change the `[[app]]` blocks. Only the person who deploys the// application may do that, so `Core\Config::set` returns `false` and this prints `no`.string $root = 'app.0.root';echo 'reroot: ', Core\Config::set($root, '/') ? 'yes' : 'no', "\n";memory: 64Mspawn: truenarrow: yesmemory: 32Mreroot: noChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
