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" \
string:"replace"
}
You would use the function like this:
dbus_restart_service "ModemManager.service"