Not able to access system device from session service

Simon McVittie smcv at collabora.com
Mon Aug 20 17:40:39 UTC 2018


On Mon, 20 Aug 2018 at 19:22:09 +0530, deepan muthusamy wrote:
> My session.serviceĀ  has dependency on mysystem.service, so I mentioned in
> Requires and After command in session.service.

This is really a fact about systemd, not about D-Bus, but you can't do
that. The Requires, After etc. fields in systemd system services refer to
other system services. The Requires, After etc. fields in user services
refer to other user services. There is no way to make a user service
depend on a system service.

However, you probably don't need to do that anyway. If you set up
your system service to be "activatable", then it can be started by
dbus-daemon on-demand the first time it receives a message from one of
its clients (in your case that's your user/session service). ModemManager
(org.freedesktop.ModemManager1) is a good example of an activatable
system service that works like this.

Here's how that looks:

/usr/share/dbus-1/system-services/com.example.YourService.service:

    [D-BUS Service]
    Name=com.example.YourService
    Exec=...
    User=...
    SystemdService=dbus-com.example.YourService.service

/lib/systemd/system/your-service.service:

    [Unit]
    ...

    [Service]
    ...

    [Install]
    WantedBy=...
    Alias=dbus-com.example.YourService.service

Replace "..." with whatever is most appropriate for your service,
replace com.example.YourService (in both filenames and content) with
your service's well-known D-Bus bus name (use a domain name that you or
your company owns), and replace the filename your-service.service with
whatever short name is most appropriate for your service.

In the systemd service, you'll probably want to use Type=dbus and
BusName=com.example.YourService. That means systemd will only think your
service is ready for use when it has requested and obtained its well-known
bus name com.example.YourService.

The systemd [Service] ExecStart should probably be very similar to the
D-Bus Exec.

Similarly, the User should probably be the same for both. In the systemd
service file the default is root, but in the D-Bus service file there
is no default and you must always specify a User (even if it's root,
as it is for ModemManager).

    smcv


More information about the dbus mailing list