Skip to content

Configuring communication between containers in the root partition

Configuring communication between containers in the root partition

Inter-process communication (IPC) allows processes, such as applications and services, to share data and synchronize resources through a common channel. Applications that communicate using IPC are either servers or clients. Servers actively listen to requests in the channel and respond to them. Clients connect to the channel to request data. Configuration stages related to applications in the root partition belong in the content pipeline of the manifest file, whereas configuration stages related to QM applications belong in the qm pipeline.

Signals, shared files, network sockets, and D-Bus subsystems are mechanisms in the kernel that enable IPC. In AutoSD, IPC occurs by using UNIX domain sockets. UNIX domain sockets are virtual sockets similar to network sockets, but UNIX domain sockets are constrained to the same host operating system.

UNIX domain sockets use the file system as their address name space. The sockets are seen as files for other processes and can open the same socket to communicate. UNIX sockets do not use the file system to exchange data. They use the kernel’s memory buffers instead.

In this context, to enable IPC between applications in the root partition, the applications' containers require access to the same UNIX domain socket in the file system. The volume, or storage area, that contains the UNIX domain socket must be mounted inside the containers. For more information about socket creation, see Systemd sockets.

Prerequisites

Procedure

  1. Create a radio.container quadlet file and an engine.container quadlet file located in the same directory as the manifest file by following the procedure in Running containers from systemd.

  2. To configure communication between the radio-service and engine-service containers, edit the two quadlet files and add lines to indicate where to mount the volumes that contain the UNIX domain sockets. In the following examples from the demo code, this location is /run/asil-ipc-demo, but you can name the directory according to your own conventions.

    1. Add this line to the [Container] section of the engine.container file to mount the volume where the root socket resides:

      console --8<-- "demos/ipc_asil_asil/engine.container:10:10"

    2. Add this line to the [Container] section of the radio.container file to mount the volume where the root socket resides:

      console --8<-- "demos/ipc_asil_asil/radio.container:13:13"

  3. Optional: Use systemd to create a UNIX socket file with the same name as the service with which the socket is associated, such as the radio service.

    1. Create a systemd socket file named radio.socket with the following code and save it to the same location locally as your engine.container and radio.container quadlet files:

      console --8<-- "demos/ipc_asil_asil/radio.socket"

    2. To ensure that the application starts after the socket is created, add these lines to the [Unit] section of the radio.container file to create a dependency with the systemd socket service:

      console --8<-- "demos/ipc_asil_asil/radio.container:5:6"

    3. To copy the radio.socket file to the /etc/systemd/system/ directory in the OS image, add the following lines in the add_files section of your manifest file:

      console --8<-- "demos/ipc_asil_asil/asil-asil.aib.yml:29:30"

    4. Enable the service to ensure that the socket is created when the OS image boots by adding the following line under systemd/enabled_services in your manifest file:

      console systemd: enabled_services: --8<-- "demos/ipc_asil_asil/asil-asil.aib.yml:40:40"

Sample code

The following are fully functioning demo code samples for configuring a systemd Unix socket for IPC communications between containers in the root partition.

```console title="Sample asil-asil.aib.yml file" --8<-- "demos/ipc_asil_asil/asil-asil.aib.yml"


```console title="Sample engine.container file"
--8<-- "demos/ipc_asil_asil/engine.container"

```console title="Sample radio.container file" --8<-- "demos/ipc_asil_asil/radio.container"


```console title="Sample radio.socket file"
--8<-- "demos/ipc_asil_asil/radio.socket"

Next steps

Additional resources