# Restart ModemManager from container

**URL:** <https://forums.balena.io/t/restart-modemmanager-from-container/218462>\
**Category:** balenaOS\
**Tags:** systemd\
**Created:** [December 5, 2020, 7:47pm UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462 "2020-12-05T19:47:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tibhel](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tibhel/32/3604_2.png) [@tibhel](https://forums.balena.io/u/tibhel)\
**Post date:** [December 5, 2020, 7:47pm UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462/1 "2020-12-05T19:47:50Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![ghlens](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@ghlens](https://forums.balena.io/u/ghlens)\
**Post date:** [December 5, 2020, 8:58pm UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462/3 "2020-12-05T20:58:35Z")

</div>

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.

```auto
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"`

---

<div class="post-metadata">

**Author:** ![tibhel](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tibhel/32/3604_2.png) [@tibhel](https://forums.balena.io/u/tibhel)\
**Post date:** [December 5, 2020, 9:31pm UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462/4 "2020-12-05T21:31:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ghlens](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@ghlens](https://forums.balena.io/u/ghlens)\
**Post date:** [December 5, 2020, 10:09pm UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462/5 "2020-12-05T22:09:32Z")

</div>

Hopefully my edited reply is of use to you.

---

<div class="post-metadata">

**Author:** ![tibhel](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/tibhel/32/3604_2.png) [@tibhel](https://forums.balena.io/u/tibhel)\
**Post date:** [December 6, 2020, 12:59am UTC](https://forums.balena.io/t/restart-modemmanager-from-container/218462/6 "2020-12-06T00:59:32Z")

</div>

Thanks the function worked perfectly!
