Skip to content

Configuring communication between ASIL containers

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 ASIL applications 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 ASIL applications, 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

  • A custom manifest file, such as the manifest file that you created in Embedding RPM packages in the AutoSD image.
  • Two or more containers embedded in your image that you want to configure to communicate. In this example, these containers are the radio-service and engine-service containers from the sample apps repository.

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 ASIL socket resides:

      Volume=/run/asil-ipc-demo:/run/asil-ipc-demo
      
    2. Add this line to the [Container] section of the radio.container file to mount the volume where the ASIL socket resides:

      Volume=/run/asil-ipc-demo:/run/asil-ipc-demo
      
  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:

      [Unit]
      Description=example systemd unix socket
      
      [Socket]
      ListenStream=%t/asil-ipc-demo/asil_ipc.socket
      RuntimeDirectory=asil-ipc-demo
      
      [Install]
      WantedBy=sockets.target
      
    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:

      Requires=radio.socket
      After=radio.socket
      
    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:

          - path: /etc/systemd/system/radio.socket
            source_path: ./radio.socket
      
    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:

      systemd:
          enabled_services:
            - radio.socket
      

Sample code

The following are fully functioning demo code samples for configuring a systemd Unix socket for IPC communications between ASIL containers.

Sample asil-asil.aib.yml file
# asil-asil IPC communications demo

name: asil-asil-IPC-communications

content:
  repos:
    - id: copr-sample-apps
      baseurl: https://download.copr.fedorainfracloud.org/results/alexl/cs9-sample-images/centos-stream-9-$arch/
  rpms:
    - podman
    - containernetworking-plugins
    - vsomeip3-routingmanager
    - dlt-daemon
    # For testing the image only:
    - openssh-server
    - openssh-clients

  container_images:
    # Get the auto-apps container image from gitlab
    - source: registry.gitlab.com/centos/automotive/sample-images/demo/auto-apps
      tag: latest
      name: localhost/auto-apps

  add_files:
    - path: /etc/containers/systemd/radio.container
      source_path: ./radio.container
    - path: /etc/containers/systemd/engine.container
      source_path: ./engine.container
    - path: /etc/systemd/system/radio.socket
      source_path: ./radio.socket

  # Required for testing the image only:
  systemd:
    enabled_services:
      # Enable ssh daemon
      - sshd.service
      # Enable the dlt daemon
      - dlt
      # Enable the IPC socket
      - radio.socket

auth:
  # "password"
  root_password: $6$xoLqEUz0cGGJRx01$H3H/bFm0myJPULNMtbSsOFd/2BnHqHkMD92Sfxd.EKM9hXTWSmELG8cf205l6dktomuTcgKGGtGDgtvHVXSWU.
  # Required for testing the image only:
  sshd_config:
    PasswordAuthentication: true
    PermitRootLogin: true
Sample engine.container file
[Unit]
Description=Demo engine service container
Requires=routingmanagerd.socket
After=routingmanagerd.socket

[Container]
Image=localhost/auto-apps
Exec=/usr/bin/engine-service
Volume=/run/vsomeip:/run/vsomeip
Volume=/run/asil-ipc-demo:/run/asil-ipc-demo

[Service]
Restart=always

[Install]
WantedBy=multi-user.target
Sample radio.container file
[Unit]
Description=Demo radio service container
Requires=routingmanagerd.socket
After=routingmanagerd.socket
Requires=radio.socket
After=radio.socket
Wants=engine.service

[Container]
Image=localhost/auto-apps
Exec=/usr/bin/radio-service
Volume=/run/vsomeip:/run/vsomeip
Volume=/run/asil-ipc-demo:/run/asil-ipc-demo

[Service]
Restart=always

[Install]
WantedBy=multi-user.target
Sample radio.socket file
[Unit]
Description=example systemd unix socket

[Socket]
ListenStream=%t/asil-ipc-demo/asil_ipc.socket
RuntimeDirectory=asil-ipc-demo

[Install]
WantedBy=sockets.target

Next steps

  • Now that you configured communication between ASIL containers, you can build your AutoSD image. For more information, see Building an AutoSD image.
  • Alternatively, you can continue customizing your image. For more information, see Containerizing applications.

Additional resources


© Red Hat