Restart ModemManager from container


I need to restart the HostOS’s systemd service ModemManager from a container.
Running systemctl restart ModemManager.service from hostOS works fine but I cannot do that from the container.

I have dbus configured in the docker files and mmcli works in the container.

How can I do this?

Thanks in advance

I used the D-Bus socket to restart a host systemd service from a container. Maybe there is a cleaner way of doing it, but for me, this works good enough.

If you mount the D-Bus socket into your container with a bind mount when you start your container using the following:

-v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket

You can then use the dbus-send command-line tool that comes with dbus from within the container to talk to systemd on the host OS via the D-Bus socket that you mounted.

I created a bash function that accepts the name of the service you want to restart.

dbus_restart_service () {
  dbus-send --system --print-reply=literal \
    --dest=org.freedesktop.systemd1 \
    /org/freedesktop/systemd1 \
    org.freedesktop.systemd1.Manager.RestartUnit \
    string:"$1" \

You would use the function like this:

dbus_restart_service "ModemManager.service"

1 Like

Thanks but the command you sent seems incomplete, did you miss out something in the beginning?

Hopefully my edited reply is of use to you.

Thanks the function worked perfectly!