0

I am on Manjaro with kernel 5.15.28-1

My problem relates to bluetooth. I have bluez 5.61-1 (which I downgraded from 5.63-2).

I can activate bluetooth with systemctl but not from a systemd service that I wrote:

#/etc/systemd/system/bt-restart.service

 [Unit]
 Description=restart bt and connect keypad

 [Service]
 Type=oneshot
 User=root

 RemainAfterExit=yes

 ExecStart=/usr/bin/sleep 1
 ExecStart=-/usr/lib/systemd/system/bluetooth
 ExecStart=/usr/bin/sleep 3
 ExecStart=/home/jcw/bin/enable-bt.sh

 [Install]
 WantedBy=multi-user.target

Output from

sudo systemctl status bt-restart

● bt-restart.service - restart bt and connect keypad
     Loaded: loaded (/etc/systemd/system/bt-restart.service; enabled; vendor preset: disabled)
     Active: active (exited) since Sat 2022-03-19 09:00:35 CET; 1h 27min ago
    Process: 2762 ExecStart=/usr/bin/sleep 1 (code=exited, status=0/SUCCESS)
    Process: 2763 ExecStart=/usr/lib/systemd/system/bluetooth (code=exited, status=0/SUCCESS)
    Process: 2764 ExecStart=/usr/bin/sleep 3 (code=exited, status=0/SUCCESS)
    Process: 2766 ExecStart=/home/jcw/bin/enable-bt.sh (code=exited, status=0/SUCCESS)
   Main PID: 2766 (code=exited, status=0/SUCCESS)
        CPU: 41ms

mars 19 08:59:50 jcw-k30amjafk31amj systemd[1]: Starting restart bt and connect keypad...
mars 19 08:59:51 jcw-k30amjafk31amj systemd[2763]: bt-restart.service: Executable /usr/lib/systemd/system/bluetooth missing,>
mars 19 09:00:35 jcw-k30amjafk31amj enable-bt.sh[2767]: Attempting to connect to 2B:24:13:DB:7C:99
mars 19 09:00:35 jcw-k30amjafk31amj enable-bt.sh[2767]: Failed to connect: org.bluez.Error.Failed
mars 19 09:00:35 jcw-k30amjafk31amj systemd[1]: Finished restart bt and connect keypad.

As you can see from Executable /usr/lib/systemd/system/bluetooth missing, systemd did not find bluetooth.service.

But the file exists. It can be reached by systemctl. So what?

EDIT: End of the second line is "Executable /usr/lib/systemd/system/bluetooth missing, skipping: No such file or directory"

3
  • The > at the end of the message Executable /usr/lib/systemd/system/bluetooth missing,> indicates there is more text that was cut off. It's probably Executable ... missing, or <some other error condition that might be applicable in this case>. Use systemctl status -l bt-restart: you won't need sudo when you're just querying a service status.
    – telcoM
    Mar 19, 2022 at 12:32
  • You're right. The line is ending with "Executable /usr/lib/systemd/system/bluetooth missing, skipping: No such file or directory"
    – kart-able
    Mar 19, 2022 at 13:06
  • As you can see from Executable /usr/lib/systemd/system/bluetooth missing, systemd did not find bluetooth.service. How did you come to that conclusion?
    – tkausl
    Mar 19, 2022 at 13:25

1 Answer 1

1

There should be no executable files in directory /usr/lib/systemd/system/.

There might be a /usr/lib/systemd/system/bluetooth.service, but that is not an executable file: it is just a service definition file, like your own /etc/systemd/system/bt-restart.service.

Although you can omit the .service suffix with the systemctl command, you cannot omit any suffixes in the ExecStart= definitions, so ExecStart=-/usr/lib/systemd/system/bluetooth makes no sense. Even if you specified .../bluetooth.service, you cannot start a .service file this way.

If you just want to have your bt-restart.service to have the bluetooth.service available as it runs, you should add two lines in the [Unit] section of your bt-restart.service:

Wants=bluetooth.service
After=bluetooth.service

i.e. "bt-restart.service needs to have bluetooth.service running (but the system should not crash into recovery mode if it fails at boot), and bt-restart.service should run after bluetooth.service is started."

Then you won't need the ExecStart=-/usr/lib/systemd/system/bluetooth line at all.

Depending on the exact behavior you're after, you might want to use BindsTo= or PartOf= in place of Wants=.

If you explicitly want to always stop bluetooth.service if it's running and restart it within your bt-restart.service, then you should replace your ExecStart=-/usr/lib/systemd/system/bluetooth with:

ExecStart=/bin/systemctl restart bluetooth.service

But if your goal is to just have your enable-bt.sh script run every time bluetooth.service is started or restarted, then the combination of

PartOf=bluetooth.service
After=bluetooth.service

should do the job.

0

You must log in to answer this question.

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