[systemd-devel] how to correctly specify dependency on dbus
Lennart Poettering
lennart at poettering.net
Sat Apr 29 17:06:38 UTC 2017
On Wed, 26.04.17 10:09, prashantkumar dhotre (prashantkumardhotre at gmail.com) wrote:
> Hi
> For my service, I have:
>
> # cat my.service
> [Unit]
> Description=My Service
> After=dbus.service
> Requires=dbus.service
> ...
> ...
>
> Some time i see that my service fails to get dbus connection
> (dbus_bus_get_private() fails without any error msg).
> one possibility i think is that dbus is not fully initialized.
> From above service file config, i understand when i start my service,
> dbus service is started 1st and then my service.
> but i am not sure if my service start step is delayed until dbus is
> fully up , initialized and running and ready to accept conections.
> is there a way to specify this in my service file.
Regular system services do not have to declare any explicit dependency
on D-Bus, as D-Bus is always and unconditionally available in the later
boot phase (where regular services are started) and during runtime.
If your service runs during the early boot phase however (i.e. before
basic.target is reached, meaning your service has
DefaultDependencies=no set), then you do need an explicit dependency,
but should only specify it as After=dbus.socket +
Requires=dbus.socket (i.e. on the socket rather than the service).
If you don't know whether your service is an early or late boot
service then it's almost certainly a late boot service.
> For ex, for systemd-networkd,service, i see it specify like :
>
> # On kdbus systems we pull in the busname explicitly, because it
> # carries policy that allows the daemon to acquire its name.
> Wants=org.freedesktop.network1.busname
> After=org.freedesktop.network1.busname
>
>
> Can i use same (specifying After/Wants on a dbus name) ?
Please ignore anything related to kdbus in the source, this is
supported no longer, and does not apply to regular D-Bus.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list