Earlier today, I had the occasion to follow an expert's advise on editing systemd service files. Here is that advice which came in the form of an e-mail received about a week ago.
Dear Michel,
I am writing you because I have found your web pages and read your tutorial about bluealsa on raspberry pi (https://www.sigmdel.ca/michel/ha/rpi/bluetooth_n_buster_01_en.html). Firstly, I have to congratulate you if you are only an IT enthusiastic. Good work!
But I realized that I need to recommend you modify the part about editing SystemD service files. SystemD has several locations to store them. Some of them are places where service files are deployed automatically during a package installation (like /lib/systemd/system/ from your tutorial) and others are for own daemons or for modification of ones that are part of a package (like /etc/systemd/system/). It is important because any package upgrade can overwrite your changes. Fortunately, systemctl has a command for it so you do not have to do much!
$ export EDITOR=vim # Optional step if you do not like nano as me. 😁
$ sudo -E systemctl edit --full bluetooth # It opens the service file copied to the right location - /etc/systemd/system/bluetooth.service
$ systemctl daemon-reload # Say SystemD to see new service files.
$ systemctl restart bluetooth # Restart the service using the new service file.
Do not find this badly I just think that it should be correct when it is on the Internet. 🙂
Best wishes!
Jiří Juřica
Jiří is
pi@tarte:~ $ sudo systemctl status blue*
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-03-16 15:44:24 ADT; 56s ago
Docs: man:bluetoothd(8)
Main PID: 530 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 1597)
CPU: 100ms
CGroup: /system.slice/bluetooth.service
└─530 /usr/libexec/bluetooth/bluetoothd
Mar 16 15:44:24 tarte systemd[1]: Starting Bluetooth service...
Mar 16 15:44:24 tarte bluetoothd[530]: Bluetooth daemon 5.55
Mar 16 15:44:24 tarte systemd[1]: Started Bluetooth service.
Mar 16 15:44:24 tarte bluetoothd[530]: Starting SDP server
Mar 16 15:44:24 tarte bluetoothd[530]: Bluetooth management interface 1.18 initialized
Mar 16 15:44:25 tarte bluetoothd[530]: profiles/sap/server.c:sap_server_register() Sap driver initialization failed.
Mar 16 15:44:25 tarte bluetoothd[530]:
sap-server: Operation not permitted (1)
Mar 16 15:44:25 tarte bluetoothd[530]:
Failed to set privacy: Rejected (0x0b)
● bluetooth.target - Bluetooth
Loaded: loaded (/lib/systemd/system/bluetooth.target; static)
Active: active since Wed 2022-03-16 15:44:24 ADT; 56s ago
Docs: man:systemd.special(7)
Mar 16 15:44:24 tarte systemd[1]: Reached target Bluetooth.
From before, I knew that editing the service file could get rid of the SAP related error messages. As Jiří said the service file is in two directories. First there's the original file that was part of the bluez package.
The same file is copied to the SystemD directory of enabled enabled services.
pi@tarte:~ $ sudo systemctl daemon-reload
pi@tarte:~ $ sudo systemctl restart bluetooth
pi@tarte:~ $ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/etc/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-03-16 15:51:23 ADT; 17s ago
Docs: man:bluetoothd(8)
Main PID: 856 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 1597)
CPU: 81ms
CGroup: /system.slice/bluetooth.service
└─856 /usr/libexec/bluetooth/bluetoothd --noplugin=sap
Mar 16 15:51:22 tarte systemd[1]: Starting Bluetooth service...
Mar 16 15:51:23 tarte bluetoothd[856]: Bluetooth daemon 5.55
Mar 16 15:51:23 tarte systemd[1]: Started Bluetooth service.
Mar 16 15:51:23 tarte bluetoothd[856]: Starting SDP server
Mar 16 15:51:23 tarte bluetoothd[856]: Excluding (cli) sap
Mar 16 15:51:23 tarte bluetoothd[856]: Bluetooth management interface 1.18 initialized
Mar 16 15:51:23 tarte bluetoothd[856]: Failed to set privacy: Rejected (0x0b)
pi@tarte:~ $ diff /lib/systemd/system/bluetooth.service /etc/systemd/system/bluetooth.service -w
9c9
< ExecStart=/usr/libexec/bluetooth/bluetoothd
---
> ExecStart=/usr/libexec/bluetooth/bluetoothd --noplugin=sap