Service Wrappers
This page explains the purpose, structure, and integration of service wrappers in the Clea Cloud IoT architecture.
What Are Service Wrappers?
Service wrappers are Yocto recipes and supporting files that install, configure, and manage the main IoT applications (such as Edgehog Device Runtime and Astarte Message Hub) as systemd services on the target device. They ensure that these applications are started automatically at boot, monitored, and restarted if necessary.
Why Use Service Wrappers?
- Automated Startup:
Ensures critical services are started at boot without manual intervention. - Reliability:
Leverages systemd to monitor and restart services if they fail. - Separation of Concerns:
Keeps application packaging and service management logic distinct. - Configurability:
Allows for custom wrapper scripts or environment setup before launching the main binary.
Typical Structure
A service wrapper recipe directory (e.g., recipes-iot/service-edgehog-device-runtime/) usually contains:
- A
.bbBitBake recipe file (e.g.,service-edgehog-device-runtime.bb) - A systemd unit file (e.g.,
edgehog-device-runtime.service) - Optional wrapper scripts or configuration files
Example: Systemd Unit File
A typical systemd unit file for Edgehog Device Runtime:
[Unit]
Description=Edgehog Device Runtime
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/edgehog-device-runtime
Restart=on-failure
[Install]
WantedBy=multi-user.target
How Service Wrappers Work
- Installation:
The Yocto recipe installs the systemd unit file and any required scripts to the appropriate locations in the root filesystem. - Enablement:
The service is enabled so it starts automatically at boot (systemctl enable ...). - Management:
Systemd manages the lifecycle of the service, handling restarts and logging.
Example Recipes
-
service-edgehog-device-runtime.bb
Installs and enables the Edgehog Device Runtime as a systemd service. -
service-astarte-message-hub.bb
Installs and enables the Astarte Message Hub as a systemd service.
Customization
Service wrappers can be extended to:
- Add environment files or configuration
- Use wrapper scripts to set up prerequisites before launching the main binary
- Add dependencies on other services (e.g., networking)
Summary Table
| Service Wrapper Recipe | Main Service Managed | Role |
|---|---|---|
service-edgehog-device-runtime.bb | Edgehog Device Runtime | Device management and telemetry |
service-astarte-message-hub.bb | Astarte Message Hub | D-Bus to Astarte bridge |