Guide for doing multiple mopidy and shairport-sync instances on pi-muiscbox: Part 2 - mopidy setup
Once you have your sound card configured and working, you can prepare for running multiple instance of mopidy services. I used WinSCP to do most of the copying/editting as it’s much easier than using the command line with putty. You will need to have new cache_dir (/var/cache/mopidy) and data_dir (var/lib/mopidy) for each instance you will be running. I just duplicated the folders in each location and named them mopidy1-4.
I also duplicated /etc/mopidy/logging.conf and /etc/mopidy/logging-debug.conf for each instance, changing file name to match instance number. I left the original mopidy folders in place for ease of naming in config files.
Duplicate the mopidy binary file at /usr/local/bin/mopidy and again name each the instance number for ease of reference.
Next I created a blank config file - mopidy1.conf which will house only the changes needed for each instance. Attached is an example. You need [core] - cache_dir and data_dir info (folders you just made), [logging] config_file, debug_file, [http], port = new port for web interface, [mpd], port = new ports for mpd, and lastly you will need [audio], output pointing to your device for each stereo output. This will follow asound.conf created earlier, i.e. output = alsasink device = pcmName, or hw:X,X in my case for source 4.
mopidy1.conf
//Service Home Channel 1 Config
[core]
cache_dir = /var/cache/mopidy1
data_dir = /var/lib/mopidy1
[logging]
config_file = /etc/mopidy/logging1.conf
debug_file = /var/log/mopidy/logging-debug1.log
[http]
port = 6681
[mpd]
port = 6601
[audio]
output = alsasink device=ch1 //setting for channel 1 of 5.1 card from asound.conf
output = alsasink device=hw:0,0 // setting for hardware device of channel 4
Finally rename the init script for mopidy to mopidy1 (/etc/init.d/mopidy) and duplicate it and name each the instance number. Now you will have to edit each init script to run properly. Edit Provides, DESC, Name, DAEMON to match increment number (mopidy1-4). Also append CONFIG_FILES with :/etc/config/mopidy#.conf so mopidy will see the instance specific config files. This way you only need to specify changes for each instance. Once you have created all your init scripts, run “update-rc.d mopidy# defaults” for each instance so it will read your configs.
First part of /etc/init.d/mopidy1
//!/bin/sh
//BEGIN INIT INFO
// Provides: mopidy1
// Required-Start: $network $remote_fs
// Required-Stop: $network $remote_fs
// Should-Start: $named alsa-utils avahi dbus pulseaudio
// Should-Stop: $named alsa-utils avahi dbus pulseaudio
// Default-Start: 2 3 4 5
// Default-Stop: 0 1 6
// Short-Description: Mopidy music server
// END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC=“Home Ch1 Mopidy music server"
NAME=mopidy1
DAEMON=/usr/local/bin/mopidy1
DAEMON_USER=mopidy
DAEMON_GROUP=audio
CONFIG_FILES=”/usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:/etc/mopidy/mopidy1.conf"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
…rest is default
Now you can test mopidy services to see if they will run by running “service mopidy# start” for each instance. To access the web interface, you will have to use the port for each instance as in the config file. I would suggest rebooting to make sure all your mopidy instance start as they should.