Device Commands
A device command runs an action on a device on demand, for example to restart a service or to collect diagnostics. Nexigon Agent loads command definitions from files, publishes them to Nexigon Hub, and runs a command’s handler when an authorized client invokes it. Create a Device Command walks through an example.
Custom commands are disabled by default. Enable them and, optionally, set the directory of the definition files:
[commands]
enabled = true
directory = "/etc/nexigon/agent/commands"Built-In Commands
The agent’s integrations provide commands of their own while they are
enabled, regardless of [commands]:
| Command | Integration | Purpose |
|---|---|---|
nexigon.ota.check | System updates | Requests an immediate system update check. |
nexigon.rugix-apps.check | Rugix Apps | Requests an immediate check of the apps. |
nexigon.rugix-apps.logs | Rugix Apps | Returns the most recent logs of an app. |
nexigon.rugix-apps.start, .stop, .rollback, .remove | Rugix Apps | Change an app that the configuration does not manage. |
A built-in command replaces a custom command with the same name. Built-in commands do not require a plan that includes custom device commands and do not consume remote access volume, as Device Commands describes.
Command Definitions
Each TOML file in the directory defines one command:
[command]
name = "restart-service"
description = "Restart a systemd service"
category = "services"
[input]
schema = '{"type": "object", "properties": {"unit": {"type": "string"}}, "required": ["unit"]}'
[exec]
handler = ["/usr/libexec/nexigon/commands/restart-service.sh"]
timeout = 30| Field | Purpose |
|---|---|
command.name | Name under which clients invoke the command. Required. |
command.description | Description shown to operators. |
command.category | Category that groups commands in the web interface. |
input.schema | JSON Schema of the input, as a string. |
output.schema | JSON Schema of the output, as a string. |
exec.handler | Executable followed by its arguments. Required. |
exec.timeout | Seconds after which the agent kills the handler and reports an error. Defaults to 30. |
The agent uses an absolute executable path directly, resolves a bare name such
as systemctl through its PATH, and resolves a relative path such as
./uptime.sh from the commands directory. The agent publishes the schemas
with the command, so that the web interface and API clients can validate
input.
Handlers run with the agent’s privileges, so an untrusted write to a definition or handler could change what a remote invocation runs. The agent therefore loads a definition only if the resolved definition file and handler are regular files owned by root or the agent’s user and not writable by group or others. Their resolved parent directories must be protected the same way. The agent skips definitions that fail these checks or cannot be parsed, logs an error, and loads the other commands. If the directory itself cannot be read, the agent starts without commands.
Handler Protocol
The handler communicates with the agent through its standard streams:
-
Stdin: The JSON input as a single line. Without input, stdin is closed immediately.
-
Stdout: NDJSON records, each a JSON object with a
typefield. AnOutputrecord carries the command’s result:{ "type": "Output", "data": { "uptime_secs": 86400 } }If the handler writes several
Outputrecords, the last one is the result. The agent ignores records of unknown types. -
Stderr: Diagnostics. The agent includes the last 8 KiB in the result.
Exit status zero reports success; any other status reports an error.
Commands in Operations
A DeviceCommand step of a
fleet operation runs a custom or built-in
command by its name. Fleet operations are a preview feature
of Nexigon Hub. The agent fetches such steps from Nexigon Hub only with
operation polling enabled:
[operations]
enabled = true
poll-interval-secs = 60The poll interval applies only while the device is idle. After a poll returns work, the agent carries it out and polls again right away, so a multi-step operation runs at the speed of its steps. Every device polls at this interval, so shorter intervals increase the load on Nexigon Hub with the size of the fleet.
The agent passes the step’s input to the handler and reports the status,
output, and error message. The step’s timeoutSecs, by default one hour,
replaces the definition’s timeout.