[systemd-devel] how to correctly specify dependency on dbus

prashantkumar dhotre prashantkumardhotre at gmail.com
Tue May 23 17:31:08 UTC 2017


Thanks.
my service runs during early bootup.
one intermittent issue I am seeing is that my service fails in
dbus_bus_get_private() with error:

 07:45:19 : dbus_bus_get_private() failed with error: Failed to
connect to socket /var/run/dbus/system_bus_socket: No such file or
directory


dbus service started at 07:44:34  and my service started at  07:45:19
which is 45 sec after dbus and also I see
/var/run/dbus/system_bus_socket present before this error.


#systemctl status dbus :
 * dbus.service - D-Bus System Message Bus
   Loaded: loaded (/lib/systemd/system/dbus.service; static; vendor
preset: enabled)
   Active: active (running) since Tue 2017-05-02 07:44:34 UTC; 40s ago
     Docs: man:dbus-daemon(1)
 Main PID: 1574 (dbus-daemon)
   CGroup: /system.slice/dbus.service
           `-1574 /usr/bin/dbus-daemon --system --address=systemd:
--nofork --nopidfile --systemd-activation

 07:45:15:  netstat -anp | grep dbus :
 unix  2      [ ACC ]     STREAM     LISTENING     11681    1/init
         /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     11831    1574/dbus-daemon
unix  3      [ ]         STREAM     CONNECTED     10907    1574/dbus-daemon
unix  3      [ ]         STREAM     CONNECTED     11830    1574/dbus-daemon
unix  3      [ ]         STREAM     CONNECTED     11833
1574/dbus-daemon    /var/run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     11832
1574/dbus-daemon    /var/run/dbus/system_bus_socket


not sure why dbus API is failing even though the socket is present.
So am I missing to add any dependency in my service file ?


On Sat, Apr 29, 2017 at 10:36 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> 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