Skip to content

Commit

Permalink
Switch librespot to run under pulseaudio user mode
Browse files Browse the repository at this point in the history
Pulse audio system wide is a bit buggy and doesn't work great with
all types of audio service. For user mode audio to work
a user constantly has to be logged in so we auto login media user on tty
  • Loading branch information
tomodachi committed Sep 9, 2023
1 parent 0af1b67 commit 5b592c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
2 changes: 0 additions & 2 deletions roles/dns-over-tls/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

# Cloudflare DNS related settings
cloudflared_release_ver: https://github.com/cloudflare/cloudflared/releases/download/2023.7.1/

Expand All @@ -8,7 +7,6 @@ cloudflared_release_arch:
arm64: cloudflared-linux-arm64.deb
armhf: cloudflared-linux-armhf.deb


doh_dns_1: "1.1.1.1"
doh_dns_2: "1.0.0.1"

Expand Down
71 changes: 25 additions & 46 deletions roles/librespot/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---

- name: Copy librespot for arm pulseaudio enabled version
- name: Enable auto login on TTY for media user (required for audio to work)
include_role:
name: autottylogin

- name: Copy librespot for ARM pulseaudio enabled version
become: true
ansible.builtin.copy:
src: files/librespot.arm64_pulse
Expand All @@ -9,36 +13,28 @@
group: root
mode: '655'

- name: Copy librespot and pulseaudio systemd service file
become: true
- name: Create user systemd folder
ansible.builtin.file:
path: /home/media/.config/systemd/user/
state: directory
owner: media
group: media

- name: Create librespot service
ansible.builtin.template:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: '644'
loop:
- librespot.service
- pulseaudio-system-wide.service
tags: servicefile
src: librespot.service
dest: /home/media/.config/systemd/user/librespot.service
owner: media
group: media
mode: '600'
notify: Reload systemd

- name: Install pulseaudio
ansible.builtin.apt:
name: pulseaudio
state: present
install_recommends: false

- name: Disable per user pulseaudio sessions
ansible.builtin.systemd:
name: "{{ item }}"
enabled: false
state: stopped
scope: global
loop:
- pulseaudio.service
- pulseaudio.socket
when: not ansible_check_mode

- name: Set default output to HDMI instead of analogue
ansible.builtin.lineinfile:
create: yes
Expand All @@ -49,31 +45,14 @@
group: root
mode: '0644'

- name: Disable pulsaudio autospawn
ansible.builtin.lineinfile:
create: yes
path: /etc/pulse/client.conf
line: autospawn = no
insertbefore: EOF

- name: Create librespot service user
ansible.builtin.user:
name: librespot
groups: pulse-access
system: true
shell: /bin/false
create_home: true
state: present

- name: Enable librespot service
become: true
become: false
remote_user: media
ansible.builtin.systemd:
name: "{{ item }}"
name: librespot
state: started
enabled: true
daemon_reload: true
when: not ansible_check_mode
scope: user
notify: Reload systemd

loop:
- librespot
- pulseaudio-system-wide
when: not ansible_check_mode
2 changes: 0 additions & 2 deletions roles/librespot/templates/librespot.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ After=network-online.target
Wants=network-online.target

[Service]
User=librespot

ExecStart=/usr/local/bin/librespot.arm64_pulse -b 320 -n {{ spotify_connect_name }} -G -F speaker
Restart=always
RestartSec=5
Expand Down

0 comments on commit 5b592c6

Please sign in to comment.