Skip to main content
Documentation

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:

/etc/nexigon/agent.toml
[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]:

CommandIntegrationPurpose
nexigon.ota.checkSystem updatesRequests an immediate system update check.
nexigon.rugix-apps.checkRugix AppsRequests an immediate check of the apps.
nexigon.rugix-apps.logsRugix AppsReturns the most recent logs of an app.
nexigon.rugix-apps.start, .stop, .rollback, .removeRugix AppsChange 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:

/etc/nexigon/agent/commands/restart-service.toml
[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
FieldPurpose
command.nameName under which clients invoke the command. Required.
command.descriptionDescription shown to operators.
command.categoryCategory that groups commands in the web interface.
input.schemaJSON Schema of the input, as a string.
output.schemaJSON Schema of the output, as a string.
exec.handlerExecutable followed by its arguments. Required.
exec.timeoutSeconds 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 type field. An Output record carries the command’s result:

    { "type": "Output", "data": { "uptime_secs": 86400 } }

    If the handler writes several Output records, 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:

/etc/nexigon/agent.toml
[operations]
enabled = true
poll-interval-secs = 60

The 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.