1

I've created a service that runs a Bluetooth server application and is started like this:

[Unit]
After=bluetooth.service
Requires=bluetooth.service

[Service]
Type=simple
ExecStartPre=/usr/bin/sdptool add SP
ExecStartPre=/bin/sleep 0.5
ExecStartPre=/bin/hciconfig hci0 piscan
ExecStart=/usr/local/bin/my-service.py
ExecStartPost=/usr/bin/bluetoothctl discoverable on
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

When I look at the logs for this unit after a system boot, I always see the first start failed and the second succeeds. When looking at the full log, I see that my service is started first, then fails, and later only the bluetooth service is started. My service is retried after that and then the required dependencies are there.

Why does Systemd ignore the After and Requires options in my service?

I've read other web texts, man pages and questions here that suggest using exactly these options for my task. But it's not working for me.

The device is a Raspberry Pi 3B+ with Raspbian OS, Linux kernel 5.4.51 and Systemd 241.

2
  • Maybe check if your bluetooth.service starts successfully the first time around. If the bluetooth service fails then so will your service
    – hakskel
    Commented Aug 14, 2020 at 17:51
  • @hakskel The bluetooth service is only started after my service, never before, and it never fails. Something else is wrong here (either in my script or in Systemd).
    – ygoe
    Commented Aug 16, 2020 at 8:53

1 Answer 1

0

Seems to be some quirks with the bluetooth.service from bluez (see this issue). I don't fully understand the reasons behind it. But changing the service WantedBy from multi-user.target to bluetooth.target has fixed it for me.

[Install]
WantedBy=bluetooth.target

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .