How to let the D-Bus service start automatically?

Created by Alexander Knaub
automatic start dbus service file system-services debug parameters path

You have the possibility to let the D-Bus service start automatically when it is needed the first time (i.e. creation of the first ReaderWriter object in Automatic start of the readerwriter module (e.g. via udev rules) is currently not possible.

1. Create file org.nfcpy.NFC.service with following content:

[D-BUS Service]

2. Place this file in the folder /usr/share/dbus-1/system-services. You need root rights for this action:

sudo cp org.nfcpy.NFC.service /usr/share/dbus-1/system-services/org.nfcpy.NFC.service

Note: in the Exec line you have to write the absolute path to the file You need quotation marks if the path contains spaces, otherwise they are voluntary.

Note: The file has to be marked as an executable.

Note: If you use automatic start of the NFC D-Bus service, you can still provide command line parameters in the .service file. Just write them in the end of the "Exec=" line, outside the quotation marks if you use them. Since the automatically started D-Bus service does not have an output, if you want to see debug messages you are bound to use the command line parameters like following:

Exec="...path/to/dbus_examples/" -dnfc.dbus -f"...path/to/nfc_dbus.log"

This would enable debugging and write the output into the file nfc_dbus.log in the given directory. Here also only absolute paths are allowed and it's recommended to use quotation marks.