Giter Site home page Giter Site logo

mopidy_multiple-instances's Introduction

Making Multiple Mopidy Instances

This script/instruction detials how to create multiple instances of mopidy which pipe their outputs to separate mopidy streams.

This enables you to have the flexibility to play one song across multiple speakers or have each speaker play its own song.

Prerequistes

Automatically

$ wget https://github.com/ESteanes/Mopidy_Multiple-Instances/releases/download/v0.1.0/multiple_mopidy.sh
$ bash multiple_mopidy.sh -N <number of instances> -H <hostname> -O snapcast

Note: leaving the hostname blank will result in 127.0.0.1 which means that mopidy will only listen to local requests. Generally unfavourable setup.

Manually

<n> represents the number of instances

  1. Create additional mopidy_<n>.conf files
$ sudo touch /etc/mopidy/mopidy_<n>.conf
  1. Using a text editor, edit the file you created and add the following information in your mopidy_<n>.conf
[core]
cache_dir = /var/cache/mopidy_<n>
data_dir = /var/lib/mopidy_<n>

[http]
port = 668<n>

[audio]
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! filesink location=/tmp/snapfifo_<n>
  1. Optional Adding custom settings

You may want to add custom information such as spotify accounts to different mopidy instances as that can help with personalisation. Do that in the corresponding file

For example spotify settings:

[spotify]
enabled = true
username = [email protected]
password = your_spotify_password
client_id = your_client_id
client_secret = your_client_secret
  1. Modify the original mopidy.conf file

Add in all the allowed origins for however many mopidy instances you created. This will allow you to access your 2nd mopidy

$ nano /etc/mopidy/mopidy.conf

allowed_origins = <hostname>:6680,<hostname>:668<n> (for all n)
  1. Create and give ownership of cache and data directoires

If creating multiple directories, can use * wildcard for chown command

$ mkdir /var/cache/mopidy_<n>
$ mkdir /var/lib/mopidy_<n>
$ chown mopidy:audio /var/cache/mopidy_<n> /var/lib/mopidy_<n>
  1. Create copies of the mopidyctl script

Creating copies of the mopidyctl script will enable you to run these mopidy instances as a service without having to manually enable them upon reboot.

$ cp /usr/sbin/mopidyctl /usr/sbin/mopidyctl_<n>

Then inside usr/sbin/mopidyctl_<n>, change the CONFIG_FILES variable to the following:

CONFIG_FILES="/usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:/etc/mopidy/mopidy_<n>.conf"

This will make sure that the service will utilise the appropriate configuration files unique to the extra instances, overwriting that in the base mopidy.conf file with the details in mopidy_<n>.conf that you altered previously.

  1. Creating additional systemd scripts

You need to create copies of the systemd scripts to activate systemd for all the different instances

$ cp /lib/systemd/system/mopidy.service /lib/systemd/system/mopidy_<n>.service

Then, using a text editor, edit the mopidy_<n>.service file with the following:

ExecStart=/usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:/etc/mopidy/mopidy_<n>.conf
  1. Adding additional streams to Snapcast

Since we are creating multiple instances of mopidy, we need to add these filesink locations in the snapcast configuration file that we are referencing in section 2.

$ nano /etc/snapserver.conf

then under the [Stream] heading, add the following:

source = pipe:///tmp/snapfifo_<n>?name=<your custom name>

Here you can specify a custom name for each source. You can set up each of the mopidy instances for different people or sections of your house/apartment.

  1. Restart all the services

Restart all the services and complete the initialising processes

$ systemctl restart snapserver.service
$ mopidyctl_<n> local scan
$ systemctl enable mopidy*.service
$ systemctl start mopidy*.service

mopidy_multiple-instances's People

Contributors

esteanes avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

mopidy_multiple-instances's Issues

2nd argument doesn't work

I receive this issue when executing without a 2nd argument (localhost hostname)
bashtest.sh: line 3: test: -eq: unary operator expected

Missing directory

Found this when running the code
Executing Step 4 cat: /etc/mopidy.conf: No such file or directory

Issue with the script

First issue that came up when running the script:
multiple_mopidy.sh: line 3: test: -eq: unary operator expected

What do you think is wrong? Looks like something wrong with the test function.

Mopid-Iris

When using Mopidy-Iris to control Modipy then the Iris scripts to start local scan and restart server fails.

A simple solution is to edit the file /usr/local/lib/python3.9/dist-packages/mopidy_iris/system.sh

The restart lines are these two:

RESTART="$(sudo service mopidy restart)"
echo -e "${RESTART}"

Change it to:

RESTART="$(sudo service mopidy_1 restart)"
echo -e "${RESTART}"
RESTART="$(sudo service mopidy_<n> restart)"
echo -e "${RESTART}"

And the start local scan is this lines:
SCAN=$(sudo mopidyctl local scan)

Change that to these:

SCAN=$(sudo mopidyctl_1 local scan)
SCAN=$(sudo mopidyctl_2 local scan)

Without this the start local scan will run on the original mopidy folders and not the extra instances and the restart will start the local mopidy and keep the extra instances running without a restart.
The downside to this quick fix is that there is no specific instance control.
A click on the restart button will restart all the instances and a click on the start local scan button will scan the media folder once for each instance. Especially the local scan might take some time with large media libraries and/or many instances.

Error when running

When I ran the script this happened:
chown: cannot access '/var/cache/mopidy_4': No such file or directory

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.