Mopidy, MusicBox WebClient, autostart

Hi there,

I’m having issues with Mopidy. I’m trying to setup my pirate audio board so it immediately plays a song on boot. However, because I installed Musicbox as a WebClient for Mopidy ( using this command : sudo python3 -m pip install Mopidy-MusicBox-Webclient) I don’t have a setup.sh file that I can edit.

To make my question even clearer : how can I setup some sort of autostart on Mopidy?

Thanks in advance !

It’s difficult to answer, because many things depends on your particular system setup.

Basically what I would do is, at after booting :

  • start mopidy
  • use a command line client to add a song and play it

To autorun programs at boot, there are basically two solutions:

  • run as the program a systemd service
  • autologin a user and have that user autostart the program

Another thing to take into consideration is that mopidy likely takes some seconds to start, so you would have to add some delay between mopidy startup and the client commands.

1 Like

My exact setup is :
Hardwarewise :
-raspberry pi zero v1.3
-wifi dongle
-Pirate audio board
-sandisk ultra 16gb 10A1

Softwarewise:
-raspbian buster with desktop
-slightly modified script for pirate audio : instead of installing Iris install musicbox
(Link to the actual file : https://drive.google.com/file/d/16dBKwnT_sk8GPvq7YLioVXwKPNfg5FIr/view?usp=drivesdk)

Do you have any tutorial that would explain how to do what you think would be best?

Thanks and sorry for the late reply,
Take care!

Ok so it appears you are running mopidy with a systemd service (you can see that with all the systemctlcommands in the install script.
I thing the easiest way to go would be to create a custom service that would sleep for a while, then add a song and trigger playback. For this you need :

  1. install mopidy-mpd, and mpc
  2. Configure mpc to connect it with mopidy (i guess)
  3. Write and save a script like
#! /bin/bash
sleep 10
mpc add "some song"
mpc play
  1. Make the script executable: chmod +x /path/to/script.sh
  2. Write a systemd service file like
[Service]
Type=simple
RemainAfterExit=no
ExecStart=/path/to/script.sh 
  1. Save the service file in /etc/systemd/system/autoplay.service
  2. You can test if the service works using systemctl start autoplay, which should trigger the song after 10 seconds (addapt to your needs)
  3. To enable the script and run it at each startup, run systemctl enable autoplay in a terminal.

I might have forgotten a step or made some mistakes, but that should be the general idea.

1 Like

Thanks a lot dude, it worked !
just had to add this to the service sript to be able to enable it :
"
[Unit]
Description=Automatically play a song on boot
After=network.target

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/home/pi/script/autostart.sh

[Install]
WantedBy=multi-user.target
"
while the [Unit] part is not required, the [Install] section is required to enable the service.

Thanks a lot for your time !!
Take care !

Nice, glad you made it work !

1 Like