Restart Operation
thin-edge.io defines a restart operation to restart a device, being the main device or a child device.
- A restart is typically triggered by a mapper on behalf of a cloud operator.
- A restart can also be triggered from another operation (as a software update) or service (detecting for instance some anomalies requesting a reboot).
tedge-agentis the reference implementation of therestartoperation.- However, a custom
restartplugin implementation can be installed on a device with specific requirements.
MQTT API​
The restart operation API follows the generic thin-edge.io rules for operations:
- The
te/<device-topic-id>/cmd/restarttopic is used to tell the device<device-topic-id>can be restarted. - Each
restartrequest is given a<command-id>and a dedicated topicte/<device-topic-id>/cmd/restart/<command-id>, where all the subsequent states of the restart command are published during its execution. - The workflow is generic with
"init","executing","successful"and"failed"statuses.
restart registration​
The registration message of the restart operation on a device is an empty JSON object {}.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart' '{}'
mosquitto_pub -r -t 'te/device/child001///cmd/restart' -m '{}'
te/device/child001///cmd/restart
{}
init state​
To trigger a restart operation on a device, the requester has no information to provide.
It only has to create a new restart command instance topic.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' '{
"status": "init"
}'
mosquitto_pub -r -t 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' -m '{
"status": "init"
}'
te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00
{
"status": "init"
}
executing state​
When ready, but before actually restarting the device,
the agent or the restart plugin publishes the new state of the command.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' '{
"status": "executing"
}'
mosquitto_pub -r -t 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' -m '{
"status": "executing"
}'
te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00
{
"status": "executing"
}
successful state​
After a successful reboot,
the agent or the restart plugin publishes the new state of the command.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' '{
"status": "successful"
}'
mosquitto_pub -r -t 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' -m '{
"status": "successful"
}'
te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00
{
"status": "successful"
}
failed state​
In case the reboot failed for some reason,
the agent or the restart plugin publishes the new state of the command,
adding a reason text field with the error.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' '{
"status": "failed",
"reason": "The device has not restarted within 5 minutes"
}'
mosquitto_pub -r -t 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' -m '{
"status": "failed",
"reason": "The device has not restarted within 5 minutes"
}'
te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00
{
"status": "failed",
"reason": "The device has not restarted within 5 minutes"
}
Command cleanup​
As for all commands, the responsibility of closing a restart is on the requester.
This is done by publishing an empty retained message on the command topic.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' ''
mosquitto_pub -r -t 'te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00' -m ''
te/device/child001///cmd/restart/c8y-2023-09-08T18:13:00
<<empty>>
Implementation Contract​
The restart agent state must survive a device restart.
- The
executingstate must be published before a reboot is scheduled. - The
successfulstate is published after the reboot when the agent resumes an ongoing restart command. - The agent needs to differentiate between a simple process restart vs the actual device restart itself.
- A simple process restart is considered as a
failedrestart.