Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mopidy: Rewrite installer to use venv. #105

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Gadgetoid
Copy link
Member

@Gadgetoid Gadgetoid commented Nov 11, 2024

⚠️ Note: This branch and install.sh are highly experimental and may do horrible things to your system that I haven't anticipated. Use with care.

⚠️ Because life is short, this script will set Mopidy to run as the user you install with, you should run ./install.sh and not sudo ./install.sh

With a "mopidy" user configured I would get permissions denied errors trying to start the systemd unit, I couldn't find a workaround to this with a half hour of prodding. If anyone's got some ideas I'm all ears.

I have split out the Pirate Audio specific config using /usr/share/mopidy/conf.d/pirate-audio.conf, I'm not actually sure this is working yet!

@Gadgetoid
Copy link
Member Author

I have pivoted the service to a user service, so you will need to start/stop/status with:

systemctl --user start mopidy
systemctl --user stop mopidy
systemctl --user status mopidy

This allows the user Mopidy session to access the default user pipewire audio sink without any additional configuration fiddling. The downside, aiui, is that you need an active user session.

Config files have also been moved to $HOME/.config/mopidy, defaults.config is intended to be a basic functional Mopidy config, and mopidy.config contains the Pirate Audio customisations.

@vinnybad
Copy link

@Gadgetoid so if an active user session is needed for a user service, does this mean we need to auto log in the user for non-interactive use?

Comment on lines 128 to 129
rm $MOPIDY_CONFIG
rm $MOPIDY_DEFAULT_CONFIG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we call rm $MOPIDY_CONFIG but there is no file at that path, it will error out. We should either perform a file exists check before calling each of these or use -f.

rm -f $MOPIDY_CONFIG
rm -f $MOPIDY_DEFAULT_CONFIG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to add sudo raspi-config nonint do_boot_behaviour B2 to the script to auto-log in the user. I haven't yet tried it but from what I understand, user services won't be launched until the user logs in.

apt update
apt install -y python3-rpi.gpio python3-spidev python3-pip python3-pil python3-numpy libopenjp2-7
sudo apt update
sudo apt install -y python3-spidev python3-pip python3-pil python3-numpy python3-lgpio python3-virtualenvwrapper virtualenvwrapper libopenjp2-7
Copy link

@vinnybad vinnybad Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran sudo apt-get update && sudo apt-get upgrade -y before running install.sh so maybe this is why I get an error: ModuleNotFoundError: No module named 'gi'.

sudo apt install -y python3-spidev python3-pip python3-pil python3-numpy python3-lgpio python3-virtualenvwrapper virtualenvwrapper libopenjp2-7 python3-gi


However, after doing that, I received an error saying ValueError: Namespace Gst not available. Perhaps this is because I installed a raspberry pi lite version instead of the desktop?

So I added some packages to get:

sudo apt install -y \
  python3-spidev \
  python3-pip \
  python3-pil \
  python3-numpy \
  python3-lgpio \
  python3-virtualenvwrapper \
  virtualenvwrapper \
  libopenjp2-7 \
  python3-gi \
  gstreamer1.0-plugins-base \
  gstreamer1.0-plugins-good \
  gstreamer1.0-plugins-bad \
  gstreamer1.0-plugins-ugly \
  gstreamer1.0-tools \
  gstreamer1.0-gl \
  gstreamer1.0-gtk3

@@ -193,11 +188,40 @@ echo
# MAYBE?: Remove the sources.list to avoid any future issues with apt.mopidy.com failing
# rm -f /etc/apt/sources.list.d/mopidy.list

Copy link

@vinnybad vinnybad Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some things in the service's logs. Mainly:

  • Ignoring config section 'spotify' because no matching extension was found
    • Suggestion: remove the spotify section in mopidy.conf and the messaging about Spotify account details at the end of the script
  • Ignoring config section 'mpd' because no matching extension was found
    • Suggestion: remove the mpd section from mopidy.conf
  • /home/pi/Music is not a directory. Please create the directory or update the file/media_dirs config value.
    • I think we should mkdir -p /home/$MOPIDY_USER/Music somewhere in the install script

@vinnybad
Copy link

Ok - so it was easier to just make changes and put them in a gist: https://gist.github.com/vinnybad/52aa2339c444000aa3b5e10595a15ad8

Also - I dug a bit and found that these lines were missing in /boot/firmware/config.txt:

dtoverlay=hifiberry-dac
gpio=25=op,dh

Once I did this and restarted the device (something we should consider adding into the script, or at least adding output asking the user to restart), audio started flowing.

I still see errors like this in the mopidy user service though:

Nov 12 00:14:04 rpiz-music mopidy[616]: WARNING  2024-11-12 00:14:04,050 [616:FileBackend-3 (_actor_loop)] mopidy.file.library
Nov 12 00:14:04 rpiz-music mopidy[616]:   Failed looking up file:///home/pi/Music/Compilations/Blah: gst-resource-error-quark: "/home/pi/Music/Compilations/Blah" is a directory. (5)

Not sure what that's about...but it plays 🎉

@Gadgetoid
Copy link
Member Author

@vinnybad thanks for an amazingly thorough review on this.

I was also seeing those "blah" "is a directory" errors, looks like a red herring but coincided with my playback not only not working but hanging mopidy 🤦

Do you mind if I grab your changes into a new commit on this branch and set you as the author?

@Gadgetoid
Copy link
Member Author

@Gadgetoid so if an active user session is needed for a user service, does this mean we need to auto log in the user for non-interactive use?

Yeah, I'm not super happy about this, but the alternative was making configuration changes to Pipewire that I didn't understand, and which might have knock-on effects. These changes, in fact, absolutely hosed my audio and caused the Mopidy lockups.

I'm very much inclined to believe that the less config we mess with, the better.

@vinnybad
Copy link

Do you mind if I grab your changes into a new commit on this branch and set you as the author?
@Gadgetoid sounds good to me.

vinnybad and others added 2 commits November 14, 2024 13:33
Fix errors when removing old configs.
Add more required packages (and additional packages for Raspberry Pi OS lite)
Fix Music directory to /home/$MOPIDY_USER/Music
Add groups to $MOPIDY_USER
@simon3270
Copy link

HI @Gadgetoid , if you want a user to be able to run their "--user" systemctl services without logging in, do:
loginctl enable-linger <user_name>
e.g.
loginctl enable-linger pi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants