3

I have a headless Debian server that I use for music. It's connected to some speakers and I've set it up so that I can play music from my phone to the server via bluetooth pairing.

However, I've found that I need to have a user logged in so that I can start the bluetooth agent and pulseaudio server. What I end up doing is logging in via ssh and running pulseaudio -D and then bt-agent -d. This allows me to pair my phone to the server and play music from my phone. The problem with this is that I have to keep the user logged in and running otherwise it stops working.

How can I automatically start these daemons on boot that will persist?

1 Answer 1

1

Assuming systemd you could create the two systemd units shown below, enable them with systemctl --user enable bt-agent-d.service; systemctl --user enable pulseaudio-d.service and finally enable lingering in order to start them at boot and not to stop them if the user logs out with loginctl enable-linger username.

PS The 'username' in the last command is a placeholder for an actual username and the last command needs root privileges to succeed.

~/.config/systemd/user/bt-agent-d.service:

[Unit]
Description=Bt-agent-d service

[Service]
ExecStart=/bin/bt-agent -d

[Install]
WantedBy=default.target

~/.config/systemd/user/pulseaudio-d.service:

[Unit]
Description=Pulseaudio-d service

[Service]
ExecStart=/bin/pulseaudio -D

[Install]
WantedBy=default.target
6
  • It doesn't quite work yet. I forgot to mention that bt-agent -d has to be run after pulseaudio -D, if that makes any difference.
    – Erik
    Mar 31, 2020 at 20:48
  • I managed to fix it partially. It works with /bin/pulseaudio -D and /bin/bt-agent -d (not sure what the difference is) but somehow lingering is not working.
    – Erik
    Mar 31, 2020 at 20:59
  • I got lingering to work by enabling it with pulse.
    – Erik
    Mar 31, 2020 at 21:01
  • On my Arch box '/bin' symlinks to '/usr/bin', where the executables are normally located, slightly different in case of Debian. Anyways, glad you got it going :) PS. Sorry for the delay, busy with work and sleep and such.
    – muthuh
    Apr 1, 2020 at 14:28
  • 1
    In case the services depend on one another (for instance one service must wait for another) it can be achieved by adding a After=xyz.target in the '[Unit] section of the service file, in this case 'After=pulseaudio-d.target' in the 'bt-agent-d.service' '[Unit]' section.
    – muthuh
    Apr 1, 2020 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.