Skip to content

nvs config check and nvs config dump

nvs config check checks a configuration, and nvs config dump prints every setting that is in effect. Both commands run no program.

Without arguments, both read ./nvs.toml. If that file does not exist, they read nvs.toml in the data folder. config check reads all the files, with their includes, [[app]] blocks and secrets. It prints one line such as ok: 2 files, 4 directives set, 1 override, 0 warnings. The exit status is 1 for a syntax error, an unknown key or a missing include. It is also 1 for a [limits] value that is not valid, or that is above its [limits.hard] ceiling.

config check --as <account> also checks the owner of each file and folder for that account. The first file that a server with this account would not accept stops the check with E0607. On Windows, NT SERVICE\<service> works before the service exists. The check sees only the files on this machine.

config dump prints one key on each line, sorted by name. It also prints the default of every key that no file sets. --origin adds the file that set each key, or default. --toml prints only the keys that files set, as a TOML document.

Examples

The examples below run with this configuration file.

nvs.toml
# The settings every server of this application shares.
[limits]
memory = "256M"
wall_time = "30s"
[limits.hard]
memory = "512M"
# This server's own settings are in a second file, which is read after this one.
[[include]]
path = "production.toml"

Check a configuration split across two files

<?nvs
// Shows how to check a configuration before you deploy it, and how to see which file set each setting.
// This program runs under the `nvs.toml` in its folder. That file includes `production.toml`.
// `nvs config check nvs.toml` reads both files and runs nothing. It prints this line and exits with `0`:
// ok: 2 files, 4 directives set, 1 override, 0 warnings
// The override is `limits.memory`. Both files set it, and the file read last wins.
// `nvs config dump nvs.toml` prints every setting in force. These lines are the settings that the two files set:
// include.0.path = "production.toml"
// limits.hard.memory = "512M"
// limits.memory = "128M"
// limits.wall_time = "30s"
// Every other line is a default value, such as `log.target = "stderr"`. With `--origin`, the `limits.memory` line says it overrides `nvs.toml`.
// A running program gets the same values. This prints `128M`, the value from `production.toml`.
echo 'memory: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
// `nvs.toml` is the only file that sets these two. This prints `30s` and `512M`.
echo 'time limit: ', Core\Config::get('limits.wall_time') ?? '(unset)', "\n";
echo 'memory ceiling: ', Core\Config::get('limits.hard.memory') ?? '(unset)', "\n";
Output
memory: 128M
time limit: 30s
memory ceiling: 512M

Check a configuration for the service account

<?nvs
// Shows how to check that a service account can use this configuration before you install the service.
// This program runs under the `nvs.toml` in its folder. That file includes `production.toml`.
// A server starts only if its account or an administrator owns each configuration file and its folder.
// No group of ordinary accounts may have write access to them.
// `nvs config check --as www-data nvs.toml` runs this check for the account `www-data`.
// If both files pass, it prints this line and exits with `0`:
// ok: 2 files, 4 directives set, 1 override, 0 warnings
// If a file fails, it prints error `E0607` with the file name and exits with `1`.
// The help line of the error shows the command that repairs the file.
// On Windows, you can name the account of a service before the service exists:
// nvs config check --as "NT SERVICE\shop" nvs.toml
// A server that passes the check reads the same values as this program. This prints `128M` and `30s`.
echo 'memory: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
echo 'time limit: ', Core\Config::get('limits.wall_time') ?? '(unset)', "\n";
Output
memory: 128M
time limit: 30s

Changelog

VersionChange
0.0.6nvs config host-key <host> connects to an SFTP server and prints the fingerprint of each of its host keys. It also prints the host_key line for a [file_transfer.<name>] block. Compare each fingerprint with the one your provider publishes before you use it.