my laboratory experiment served hot by Benoit Beauchamp

mopidy tag

My updated music setup

I’ve updated how I use part of my music system at home from the previous example here. I took inspiration from the following mopidy issue at GitHub.The big difference in how I’ve set it up before is that mopidy now use the audio output and send it to a UDP sink with the following tibits.

output = tee name=t ! queue ! autoaudiosink t. ! queue ! udpsink host= port=5555

I then use socat to make it a fifo so that forked-daapd can stream it wherever I want. Here is the script that I use to launch it during boot.


createFifo() {
fifo='/srv/music/mopidy.fifo' # this is where my forked-daapd will read it
rm $fifo

mkfifo "$fifo"
while :; do socat -d -d -T 1 -u UDP4-LISTEN:5555 OPEN:"$fifo"; done

var=`ps -C socat -F | grep [s]ocat | tr -s " " | cut -d " " -f2`
if [ -z "$var" ]; then

Here is the breakdown of what’s happening in the previous script. I create a simple bash function to make the fifo and make sure to only run it if no other instance of socat is running. If you have another instance of socat running you probably just need to kill that particular instance if it’s not working.

I also created a simple systemd service file to load it up at boot time which I put in /etc/systemd/system/

Description=Startup mopidy udplink to fifo



My music setup at home with mopidy, forked-daapd and shairport-sync

UPDATE 1: I’ve modified a bit of a section from this here.

Here is my music setup at home. I have a mac mini that’s been transformed to a server running debian stretch. It runs a few deamons. I have mopidy as my main web interface which is also connected to Spotify and Soundcloud through mopidy plugins. What is mopidy? Taken from their github site ‘Mopidy is an extensible music server that plays music from local disk, Spotify, SoundCloud, Google Play Music, and more.’ The backend is forked-daapd which is a Linux/FreeBSD DAAP (iTunes) with support for AirPlay devices (multiroom). Mopidy connects to forked-daapd that then streams to any AirPlay devices to multiple rooms in my house. Im pretty happy with this setup but I wanted more. I wanted to be able to use my iDevices or having my spouse or kids to be able to steam to our multiroom setup. That’s when shairport-sync comes in. I can pipe the music stream to forked-daapd that send audio to all AirPlay devices and not only that but also the metadata from the shairport-sync.

I know you could do with something like Rogue Amoeba Airfoil but then you need your mac to be on at all time which I didnt want to do. Part of the reason that I installed linux on the mini is also because I run Kodi on it. It runs these daemons and kodi. I didnt want the bloat of running macOS just for that.

Here is the kicker with this setup, I could put speakers anywhere either inside or outside the house thats connected to the network and play music from any devices to them. Putting speakers outside is on my to-do list which seems to be getting longer and longer. Ohh the joy of owning a house in Upstate NY. But in any case I digress, it’s super easy to transform a raspberrypi into an audio hub with shairport-sync. The quality of the audio isnt that great on the first generation of raspberrypi devices but seem to be fairly decent on newer 2+ models. Dont quote me on this.

Here are the steps I’ve used.


To download mopidy you should follow the instructions on this page For my debian box, here is what I did.

I added the mopidy GPG key:

$ wget -q -O - | sudo apt-key add -

Added the APT repo to your package sources:

$ sudo wget -q -O /etc/apt/sources.list.d/mopidy.list

Install Mopidy and all dependencies:

$ sudo apt-get update
$ sudo apt-get install mopidy

You can search for every extensions on the repository with the search command which is very useful. For example, installing extensions spotify and soundcloud.

$ apt search mopidy
$ sudo apt install mopidy-spotify mopidy-soundcloud

mopidy config files

If you have a local music library then make sure you point it to the right directory. Here is my config file located in /etc/mopidy/mopidy.conf. You should check out to fully understand all the possibilities. I disabled MPD because I didnt need it. You should replace $USER with your actual home folder.

cache_dir = /var/cache/mopidy
config_dir = /etc/mopidy
data_dir = /var/lib/mopidy

config_file = /etc/mopidy/logging.conf

output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink

enabled = false

enabled = true
hostname =
port = 6680
zeroconf = Mopidy HTTP server on $hostname

enabled = true

enabled = true
library = json
media_dir = /home/$USER/music
scan_timeout = 1000
scan_flush_threshold = 100
excluded_file_extensions =

enabled = true
username = alice
password = secret
bitrate = 320
client_id = client_id value you got from
client_secret = client_secret value you got from

username = alice
password = secret

auth_token = 1-1111-1111111


For more information on the mopidy-spotify plugins check out What I had to do to be able to fun spotify was to modify the config files /etc/mopidy/mopidy.conf. You will need to find your spotify username and password that are located in your account overview page at and put it instead of the ones below. After you put your info in the conf files you will need to visit to authorize this extension against your Spotify account:

username = alice
password = secret
client_id = client_id value you got from
client_secret = client_secret value you got from


To configure mopidy-soundcloud located you need to follow the following steps stated on the website:

  1. You must register for a user account at
  2. You need a SoundCloud authentication token for Mopidy from
  3. Add the authentication token to the mopidy.conf config file:
auth_token = 1-1111-1111111
explore_songs = 25

mopidy running as a service

Systemd ways of running services is fairly easy. You should enable it using:

$ sudo systemctl enable mopidy

Now that this is enabled, it will start mopidy after each boot.

To start, stop and restart you use the following command:

$ sudo systemctl start mopidy
$ sudo systemctl stop mopidy
$ sudo systemctl restart mopidy

You can check the status of the service with:

$ sudo systemctl status mopidy

mopidy web extensions

We will need a web interface to be the front end of mopidy. My two favorite are Mopidy-MusicBox-Webclient and Mopidy-Mopify both available with pip. Mopify is great for spotify access and musicbox is great for iDevices.

$ sudo pip install Mopidy-Mopify
$ sudo pip install Mopidy-MusicBox-Webclient

Now that its installed you should go to the URL to see if it worked.


Here are the step that I use to install forked-daapd.

$ sudo apt-get install build-essential git autotools-dev autoconf libtool gettext gawk gperf antlr3 libantlr3c-dev libconfuse-dev libunistring-dev libsqlite3-dev libavcodec-dev libavformat-dev libavfilter-dev libswscale-dev libavutil-dev libasound2-dev libmxml-dev libgcrypt11-dev libavahi-client-dev zlib1g-dev libevent-dev libplist-dev libsodium-dev libjson-c-dev libwebsockets-dev

Optional packages:

Feature Configure argument Packages
Chromecast —enable-chromecast libgnutls-dev libprotobuf-c-dev
LastFM —enable-lastfm libcurl4-gnutls-dev OR libcurl4-openssl-dev
iTunes XML —disable-itunes libplist-dev
Device verification —disable-verification libplist-dev libsodium-dev
Live web UI —with-libwebsockets libwebsockets-dev
Pulseaudio —with-pulseaudio libpulse-dev
$ git clone
$ cd forked-daapd
$ autoreconf -i
$ ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-pulseaudio --enable-lastfm
$ make
$ sudo make install

Now that it’s installed check the config file /etc/forked-daapd.conf and make sure you have your music directory in the config file like below.

# Directories to index
directories = { "/home/$USER/music" }

and to stream the music from other devices via the pipe that we will create later we need to make sure it set to true. Let’s adjust one more thing in the config file.

# Watch named pipes in the library for data and autostart playback when
# there is data to be read. To exclude specific pipes from watching,
# consider using the above _ignore options.
pipe_autostart = true

I disabled a bunch of other options because I didnt need them like MPD, spotify and such.

forked-daapd running as a service

Done with config file, lets move to have it run it as a service. Here is my forked-daapd.service file located in my /etc/systemd/system folder. I use the following options are

  • Running in the foreground with -f
  • Debug log level -d 0
  • Location of the config file with -c /etc/forked-daapd.conf
Description=DAAP/DACP (iTunes), RSP and MPD server, supports AirPlay and Remote
Documentation=man:forked-daapd(8) pulseaudio.service avahi-daemon.service

ExecStart=/usr/sbin/forked-daapd -f -d 0 -c /etc/forked-daapd.conf

# Restart, but not more than once every 10 minutes


Like mopidy and any other systemd services, to enable forked-daapd to run here is what I do.

$ sudo systemctl enable forked-daapd

Now that this is enabled, it will start forked-daapd after each boot.

To start, stop and restart you use the following command:

$ sudo systemctl start forked-daapd
$ sudo systemctl stop forked-daapd
$ sudo systemctl restart forked-daapd

You can check the status of the service with:

$ sudo systemctl status forked-daapd

If it’s running you should be able to go to http://[your_server_address_here]:3689 and see your current AirPlay devices. You will be able to toggle them on or off.


Now, here is where the magic will happen, creating a pipe. Make sure you have the right permissions meaning that $USER can read/write to the music folder. Maybe perharps a chmod -R 755 music. Lets also restart forked-daapd.

$ mkfifo /home/$USER/music/shairport
$ mkfifo /home/$USER/music/shairport.metadata
$ chmod 777 shairport shairport.metadata
$ sudo systemctl restart forked-daapd

Now that we have forked-daapd running we need to start installing shairport-sync in order to have other user or devices able to stream to the AirPlay devices.

sudo apt install build-essential git xmltoman autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev libasound2-dev libpulse-dev avahi-daemon libavahi-client-dev libsoxr-dev

Let’s download shairport-sync and build it. I used the following settings for building shairport-sync. Do check the file for more information about each settings. It has tons of information. I also run shairport-sync on a raspberrypi

$ git clone
$ cd shairport-sync
$ autoreconf -i -f
$ ./configure --sysconfdir=/etc --with-alsa --with-pa --with-avahi --with-ssl=openssl --with-metadata --with-soxr --with-systemd
$ make -j4
$ sudo make install

My shairport-sync.conf file in /etc

general = {
  name = "SHAIRPORT";
  output_backend = "pipe";

metadata = {
  enabled = "yes";
  include_cover_art = "yes";
  pipe_name = "/home/$USER/music/shairport.metadata";

sessioncontrol = {
  allow_session_interruption = "yes";
  session_timeout = 20;

pipe = {
  name = "/home/$USER/music/shairport";
  audio_backend_buffer_desired_length = 48000;

Now that you have the pipe set up you will be able to have music sent to all your speakers selecting the SHAIRPORT device. You should now make shairport-sync start at boot time. Lets use systemd again. It should have installed the file already in the /lib/systemd/system/shairport-sync.service folder and possibly created a shairport-sync user and group. Here is the conf file just in case.

Description=ShairportSync AirTunes receiver



Let’s make sure it will run after each reboot enabling it in systemd and then let’s restart it.

$ sudo systemctl enable shairport-sync.service
$ sudo systemctl restart shairport-sync.service

In any of the systemd services conf file above either for mopidy, forked-daapd or shairport-sync you should make sure if it’s running. Troubleshooting various issues like permissions, wrong ExecStart configuration would be where I would start if you run into trouble.

Now you should be able to stream either via mopidy using the web interface within the URL to your AirPlay speakers or you could also use your iDevices/laptop to stream to all your AirPlay speakers. Ive been running this setup for quite some time and its rocking the house. I should also mention that it does have a 4-5 sec latency issue but I dont mind since its only for our listening pleasure. No mixing involve yet..