DBus service stops too early

Hey there,

I’m trying to run a script at shutdown, but I can’t access upower anymore, as dbus is already shutting down. I tried to add dbus.service as required,upholds and after in the service file of my script, but dbus is still shutting down too early.
I also added ExecStop=/bin/true and KillMode=none to dbus.service, but this didn’t solve the issue either.

Any idea is welcome!
Thanks in advance! :slight_smile:

Hi @Tobi_Peter,

I suspect you’ll have to use either a Before, or After dependency in your unit file. See here:


But it’ll have to be “before shutdown of dbus”.

The usual Before= or After= doesn’t apply here because they are for starting services, not their shutdown.

You could add an override to dbus and add a ExecStopPre if that exists.


Or probably not, you could tell your service to not have a ExecStart but a ExecStop and a After dbus. This means that during shutdown, it’ll be the reverse, so its actually before stopping dbus.

1 Like

I probably should enter my complete service file here, to make things clear.
It does indeed only have /bin/true as start script and the real script is then executed at shutdown.

The file looks like this:
RequiresMountsFor=/ /home /boot
Requires=dbus.service dbus.socket network-online.target multi-user.target local-fs-pre.target local-fs.target NetworkManager.service
Upholds=dbus.service dbus.socket network-online.target multi-user.target local-fs-pre.target local-fs.target NetworkManager.service
After=dbus.service multi-user.target
Before=systemd-poweroff.service shutdown.target umount.target final.target systemd-halt.service



But, when executed, it needs multriple dbus services for multiple minutes, so dbus has to be kept awake. But I couldn’t find a way yet.
Journalctl -br -1 always just tells me that the command could not be executed, because dbus is already stopping.