Require and start podman network interface using systemd

Viewed 892

I have a host service managed by systemd which listens on the Podman default network interface (cni-podman0) so that containers can talk to it.

The problem I have, is that Podman only creates the network interface when the first container is started. That means when the host service which the containers depend on is started, the network interface isn't up and the service fails to listen on it.

So the dependency chain is: Podman container -needs> Host Service -needs> CNI network interface

But currently the only why I know of to bring up the interface is starting the container.

How can I make systemd tell Podman / CNI to start the default bridge network interface, so that I can depend on that in the host service unit?

Is there a command to bring up the interface explicitly, I could put in a unit file?

2 Answers

Unless I misunderstood the question, it's possible to use the After and Wants parameters in your systemd service file.

Open your service file, e.g. vim /etc/systemd/system/my_custom_daemon.service and make sure you have the following:

[Unit]
After=network.target
Wants=network.target

If it's not the host network that you need to satisfy as a precondition then you'd need to create a custom systemd target and reference it in your After/Wants.

I solved it for now by adding a oneshot systemd service unit, which runs an immediately exiting alpine container using Podman, to the host service dependencies, which runs an immediately exiting alpine container using Podman. This "tricks" Podman into bringing up the bridge network interface.

Less hacky solutions are still more than welcome.

Related