Lifecycle of a module
Modules run on your machine, alongside viam-server as separate processes, communicating with viam-server over UNIX sockets.
viam-server manages the dependencies, start-up, reconfiguration, data management, and shutdown behavior of your modular resources.
The lifecycle of a module and the resources it provides are as follows:
viam-serverstarts, and if it is connected to the internet, it checks for configuration updates.viam-serverstarts any configured modules.When a module initializes, it registers its model or models and associated APIs with
viam-server, making the models available for use.For each modular resource configured on the machine,
viam-serveruses the return values of the resource’svalidate_configfunction to determine the required and optional dependencies of the resource.If a required dependency is not already running,
viam-serverstarts it before starting the resource. If a required dependency is not found or fails to start,viam-serverdoes not start the resource that depends on it.viam-servercalls the resource’s constructor to build the resource based on its configuration. Typically, the constructor calls thereconfigurefunction.Modular resources can fail to start for various reasons:
- a validation error or exception thrown in constructor
- a validation error or exception thrown during reconfiguration
- exceeding the configured timeout limits (default 5 minutes to start up and 1 minute to reconfigure)
Check the
viam-serverlogs for these errors on the machine’s LOGS tab.Once the modular resource has started up and finished configuring, it is available for use.
If at any point the user changes the configuration of the machine,
viam-serverreconfigures the affected resources within 15 seconds.If
viam-serverattempts to shut down an individual module (for example due to a user disabling a module) and the module does not shut down within 30 seconds,viam-serverkills the module process.When
viam-servershuts down, it first attempts to shut down each module process sequentially in no particular order. If a module process does not shut down within 30 seconds, it is killed with aSIGKILLsignal. If any modules are still running after 90 seconds,viam-serverkills them as well. This means that if four modules are running and the first three each fail to shut down within 30 seconds each, the fourth is killed immediately at the 90 second mark.
Microcontroller modules function differently and are embedded in the firmware you flash onto your device. For more information see Modules for ESP32.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!