Skip to content

Commit 1a5e569

Browse files
committed
Fix viam-server, move lifecycle to expander, etc
1 parent c10b99a commit 1a5e569

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

docs/operate/get-started/other-hardware/_index.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,25 @@ For C++ module examples, see the [C++ examples directory on GitHub](https://gith
5151
{{% /alert %}}
5252

5353
{{< expand "How and where do modules run?" >}}
54-
Modules run on your machine, alongside [`viam-server`](/operate/reference/viam-server/) as separate processes, communicating with `viam-server` over UNIX sockets.
55-
56-
When a module initializes, it registers its {{< glossary_tooltip term_id="model" text="model or models" >}} and associated [APIs](/dev/reference/apis/) with `viam-server`, making the new model available for use.
57-
`viam-server` manages the [dependencies](/operate/reference/viam-server/#dependency-management), [start-up](/operate/reference/viam-server/#start-up), [reconfiguration](/operate/reference/viam-server/#reconfiguration), [data management](/data-ai/capture-data/capture-sync/), and [shutdown](/operate/reference/viam-server/#shutdown) behavior of your modular resource.
54+
Modules run on your machine, alongside `viam-server` as separate processes, communicating with `viam-server` over UNIX sockets.
55+
56+
[`viam-server` manages](/operate/reference/viam-server/) the dependencies, start-up, reconfiguration, [data management](/data-ai/capture-data/capture-sync/), and shutdown behavior of your modular resource.
57+
58+
The lifecycle of a module and the resources it provides is as follows:
59+
60+
1. `viam-server` starts, and if it is connected to the internet, it checks for configuration updates.
61+
1. `viam-server` starts any configured modules.
62+
1. When a module initializes, it registers its model or models and associated [APIs](/dev/reference/apis/) with `viam-server`, making the models available for use.
63+
1. For each modular resource configured on the machine, `viam-server` uses the resource's `validate` function and the `depends_on` field in the resource configuration to determine the dependencies of the resource.
64+
1. If a dependency is not already running, `viam-server` starts it before starting the resource.
65+
If a dependency is not found or fails to start, `viam-server` will not start the resource that depends on it.
66+
1. `viam-server` builds the resource based on its resource configuration.
67+
1. If configuration fails due to a validation failure or an exception thrown by the reconfigure function, `viam-server` attempts to reconfigure the resource.
68+
1. The modular resource is ready to use.
69+
1. If at any point the user changes the configuration of the machine, `viam-server` reconfigures the affected resources within 15 seconds.
70+
1. If a resource crashes, `viam-server` attempts to rebuild it.
71+
1. When `viam-server` shuts down, it attempts to stop all running modules.
72+
If a module fails to shut down within 90 seconds, `viam-server` will forcefully kill it after 15 seconds.
5873

5974
For microcontrollers, you must flash a [firmware build that includes the Micro-RDK](/operate/get-started/other-hardware/micro-module/) and one or more modules onto your device.
6075
{{< /expand >}}
@@ -134,7 +149,7 @@ Authenticate your CLI session with Viam using one of the following options:
134149
| Language | The language for the module. |
135150
| Visibility | Choose `Private` to share only with your organization, or `Public` to share publicly with all organizations. If you are testing, choose `Private`. |
136151
| Namespace/Organization ID | In the [Viam app](https://app.viam.com), navigate to your organization settings through the menu in upper right corner of the page. Find the **Public namespace** (or create one if you haven't already) and copy that string. If you use the organization ID, you must still create a public namespace first. |
137-
| Resource to add to the module (API) | The [component API](/dev/reference/apis/#component-apis) your module will implement. |
152+
| Resource to add to the module (API) | The [component API](/dev/reference/apis/#component-apis) your module will implement. See [How to design your module](#how-to-design-your-module) for more information. |
138153
| Model name | Name your component model based on what it supports, for example, if it supports a model of ultrasonic sensor called "XYZ Sensor 1234" you could call your model `xyz_1234` or similar. Must be all-lowercase and use only alphanumeric characters (`a-z` and `0-9`), hyphens (`-`), and underscores (`_`). |
139154
| Enable cloud build | If you select `Yes` (recommended) and push the generated files (including the <file>.github</file> folder) and create a release of the format `vX.X.X`, the module will build and upload to the Viam registry and be available for all Viam-supported architectures without you needing to build for each architecture. `Yes` also makes it easier to [upload](#upload-your-module) using PyInstaller by creating a build entrypoint script. You can select `No` if you will always build the module yourself before uploading it. |
140155
| Register module | Select `Yes` unless you are creating a local-only module for testing purposes and do not intend to upload it. Registering a module makes its name and metadata appear in the Viam app registry page; uploading the actual code that powers the module is a separate step. If you decline to register the module at this point, you can run [`viam module create`](/dev/tools/cli/#module) to register it later. |

docs/operate/get-started/other-hardware/dependencies.md

+11-25
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,12 @@ type: "docs"
77
description: "Handle dependencies in your custom modular resource."
88
---
99

10-
If you are authoring a module, this page will help you understand how to handle dependencies in your modular resources.
11-
12-
## The lifecycle of a module
13-
14-
An instance of a module runs as a separate process from `viam-server`.
15-
`viam-server` manages the lifecycle of the module, communicating with it over UNIX sockets.
16-
The lifecycle of a module and the resources it provides is as follows:
17-
18-
1. `viam-server` starts, and if it is connected to the internet, it checks for configuration updates.
19-
1. `viam-server` starts any configured modules.
20-
1. For each modular resource configured on the machine, `viam-server` uses the resource's `validate` function and the `depends_on` field in the resource configuration to determine the dependencies of the resource.
21-
1. If a dependency is not already running, `viam-server` starts it before starting the resource.
22-
1. `viam-server` builds the resource based on its configuration.
23-
1. If the configuration fails, `viam-server` attempts to reconfigure the resource.
24-
1. The modular resource is ready to use.
25-
1. If at any point the user changes the configuration of the machine, `viam-server` reconfigures the affected resources.
26-
1. If a resource crashes, `viam-server` attempts to rebuild it.
27-
1. When `viam-server` shuts down, it attempts to stop all running modules.
28-
29-
## What are dependencies?
30-
3110
Dependencies are other {{< glossary_tooltip term_id="resource" text="resources" >}} that your modular resource needs to access in order to function.
3211
For example, a vision service might depend on a camera component, meaning that the camera is a dependency of that vision service.
3312

34-
When `viam-server` builds all the resources on a machine, it builds the dependencies first.
13+
When [`viam-server` builds all the resources on a machine](/operate/get-started/other-hardware/#how-and-where-do-modules-run), it builds the dependencies first.
3514

36-
### Implicit versus explicit dependencies
15+
## Implicit versus explicit dependencies
3716

3817
- **Implicit dependencies** require users to configure a named attribute (for example `"left-motor": "motor1"`).
3918

@@ -68,7 +47,8 @@ For example, you cannot call `Camera.from_robot()` to get a camera resource.
6847

6948
Instead, you must access dependencies by writing your module code as follows:
7049

71-
### Use implicit dependencies
50+
{{< tabs >}}
51+
{{% tab name="Use implicit dependencies" %}}
7252

7353
{{< tabs >}}
7454
{{% tab name="Python" %}}
@@ -205,7 +185,8 @@ If you need to maintain the state of your resource, see [(Optional) Create and e
205185
{{% /tab %}}
206186
{{< /tabs >}}
207187

208-
### Use explicit dependencies
188+
{{% /tab %}}
189+
{{% tab name="Use explicit dependencies" %}}
209190

210191
{{< tabs >}}
211192
{{% tab name="Python" %}}
@@ -244,8 +225,13 @@ func (cfg *Config) Validate(path string) ([]string, error) {
244225
{{% /tab %}}
245226
{{< /tabs >}}
246227

228+
{{% /tab %}}
229+
{{< /tabs >}}
230+
247231
{{% hiddencontent %}}
248232
There is not currently an SDK method to access configuration attributes of dependencies in Python or Go, but in Python it is possible to use `get_robot_part` to return information including the whole configuration of a machine part, and then access the configuration attributes of the dependency from there.
249233
{{% /hiddencontent %}}
250234

251235
## Configure your module's dependencies more easily with a discovery service
236+
237+
If your module requires dependencies, you can make it easier for users to configure them by writing a [discovery service](/operate/reference/services/discovery/) as one model within your module.

docs/operate/reference/viam-server/_index.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Overall, `viam-server` manages:
3737

3838
## Dependency management
3939

40-
`viam-server` handles dependency management between resources.
40+
`viam-server` handles [dependency](/operate/get-started/other-hardware/dependencies/) management between resources.
4141

4242
## Start-up
4343

@@ -50,7 +50,7 @@ After start-up, `viam-server` manages:
5050
- the running services, and
5151
- the {{< glossary_tooltip term_id="module" text="modules" >}} that provide the {{< glossary_tooltip term_id="modular-resource" text="modular resources" >}}.
5252

53-
### Reconfiguration
53+
## Reconfiguration
5454

5555
When you or your collaborators change the configuration of a machine in the Viam app, `viam-server` automatically synchronizes the configuration to your machine and updates the running resources within 15 seconds.
5656
This means you can add, modify, and remove a modular resource instance from a running machine.
@@ -67,7 +67,7 @@ If you want to force a reconfiguration of a resource, you can click the **Disabl
6767
Alternatively, if you are having issues with a module, try the **Restart module** button in the module menu.
6868
{{% /hiddencontent %}}
6969

70-
### Maintenance window
70+
## Maintenance window
7171

7272
There are a few updates that may make your machine temporarily unavailable:
7373

@@ -108,7 +108,7 @@ maintenance : {
108108
| `sensor_name` | string | **Required** | The full name of the sensor that provides the information if it is safe to update a machine's configuration. For example `rdk:component:sensor/sensor1`. |
109109
| `maintenance_allowed_key` | string | **Required** | The key of the key value pair for the reading returned by the sensor. |
110110

111-
### Logging
111+
## Logging
112112

113113
Log messages appear under the [**LOGS** tab](/manage/troubleshoot/troubleshoot/#check-logs) for a machine.
114114

@@ -191,7 +191,7 @@ If log configurations are applied at a resource level using the `log_configurati
191191

192192
{{% /expand%}}
193193

194-
#### Disable log deduplication
194+
### Disable log deduplication
195195

196196
By default, `viam-server` deduplicates log messages that are deemed noisy.
197197
A log is deemed noisy if it has been output 3 times in the past 10 seconds.
@@ -220,7 +220,7 @@ To disable log deduplication, set `disable_log_deduplication` in your machine's
220220

221221
{{% /expand%}}
222222

223-
#### Delete machine logs
223+
### Delete machine logs
224224

225225
You cannot delete machine logs.
226226
If your machine has generated a large amount of logs and you are concerned about the cost, you can:
@@ -230,7 +230,7 @@ If your machine has generated a large amount of logs and you are concerned about
230230

231231
If you delete a machine you will not be charged for the remainder of the 30 days until logs from that machine are deleted.
232232

233-
#### Debugging
233+
### Debugging
234234

235235
You can enable debug level logs in two ways:
236236

@@ -246,7 +246,7 @@ You can enable debug level logs in two ways:
246246

247247
Enabling debug level logs will take precedence over all logging configuration set using the `log` field on a machine or the `log_configuration` field on a resource.
248248

249-
### Shutdown
249+
## Shutdown
250250

251251
During machine shutdown, `viam-server` handles modular resource instances similarly to built-in resource instances - it signals them for shutdown in topological (dependency) order.
252252

0 commit comments

Comments
 (0)