[Question] Several instances of Libretime

From @yarik2720 on Wed Jul 26 2017 10:28:46 GMT+0000 (UTC)

How to properly install several instances of Libretime with vagrant?

Copied from original issue: https://github.com/LibreTime/libretime/issues/255

From @hairmare on Wed Jul 26 2017 17:00:23 GMT+0000 (UTC)

You would need to change the port mappings in Vagrantfile so each instance uses its own ports and you should probably call the installer in the box without the -I argument.

The Vagrantfile in the repo is optimized for setting up a local developer/tester environment so it might not be the best fit for “production” deploys.

From @yarik2720 on Wed Jul 26 2017 17:12:39 GMT+0000 (UTC)

Is there another ways to install several instances currently?

From @hairmare on Wed Jul 26 2017 17:29:05 GMT+0000 (UTC)

You should be able to run multiple instances of LibreTime based on just one install by creating multiple vhosts and setting the LIBRETIME_CONF_DIR env variable for each virtualhost.

You would also need to change LIBRETIME_LOG_DIR.

They both default to the airtime locations here.

You would also need to create a separate config dir for each instance and run the python services once per instance. Each one with LIBRETIME_CONF_DIR and LIBRETIME_LOG_DIR envs matching what your virtualhosts use.

I’m not sure if everything works when installing multiple instances as I don’t believe anyone has tested such a set up. Please report back if it works or any issues you run into.

If you are on a systemd based distro this should not be too hard to set up. Let us know if you need help and I’ll try to write up a quick how to.

It’ll probably make sense to close this issue by adding some info/examples to the docs once the feature is tested.

From @yarik2720 on Wed Jul 26 2017 17:35:30 GMT+0000 (UTC)

What about database? I thought it must be unique for each virtualhost to make individual programs for every virtualhost.
Also, can you tell how to setup correctly variables on apache or nginx (if you have examples)?

From @hairmare on Thu Jul 27 2017 17:44:15 GMT+0000 (UTC)

The database server (and RabbitMQ) can be shared by the instances. You would create an individual database per instance in PostgreSQL & a vhost per instance in RabbitMQ. The LibreTime instances should also have their own user/password combos to access those.

In apache you can use SetEnv in a virtualhost to set env variables.

<VirtualHost *:80>
    # ...
    SetEnv LIBRETIME_CONF_DIR /etc/libretime/instance1
    SetEnv LIBRETIME_LOG_DIR /var/log/libretime/instance1
    # ...
</VirtualHost>

In nginx you can set env variables that are passed to php-fcgi with fastgci_param.

location / {
    # ...
    fastcgi_param LIBRETIME_CONF_DIR /etc/libretime/instance1
    fastcgi_param LIBRETIME_LOG_DIR /var/log/libretime/instance1
    # ...
}

From @yarik2720 on Fri Jul 28 2017 21:13:09 GMT+0000 (UTC)

Stucked on setup on step 4, after filling in folder I have this error:
Error moving rabbitmq-analyzer.ini or deleting /tmp/rabbitmq.ini.tmp!

From @hairmare on Fri Jul 28 2017 22:38:20 GMT+0000 (UTC)

Most likely the step failed because $LIBRETIME_CONF_DIR doesn’t contain the env symlink hack.

ln -s $LIBRETIME_CONF_DIR $LIBRETIME_CONF_DIR/production

The config structure should get easier to handle with #253 (ie. it won’t need multiple files and the weird symlink once that is merged).

On larger installs your best bet might be to skip the setup wizard completely by creating all the needed configs manually before connecting to the webinterface and starting services.

From @yarik2720 on Sat Jul 29 2017 18:59:13 GMT+0000 (UTC)

Currently have no success with it, first instance set up on default paths and after that moved configs to folder /etc/airtime/instance1. Libretime started well after that. For second instance I don’t know how to create new host for rabbitmq.
Maybe there is full guide how to setup rabbitmq and postgresql for several instances?

From @hairmare on Sun Jul 30 2017 19:40:24 GMT+0000 (UTC)

Yes, docs would be nice… We should be sure that it works before writing those though.

To set up an additional rabbitmq vhost you can run the commands the installer uses for each instance:

RABBITMQ_VHOST="instance1"
RABBITMQ_USER="instance1user"
RABBITMQ_PASSWORD="instance1password"

rabbitmqctl add_vhost "${RABBITMQ_VHOST}"
rabbitmqctl add_user "${RABBITMQ_USER}" "${RABBITMQ_PASSWORD}"
rabbitmqctl set_permissions -p "${RABBITMQ_VHOST}" "${RABBITMQ_USER}" ".\*" ".\*" ".\*"

From @yarik2720 on Wed Aug 02 2017 16:33:34 GMT+0000 (UTC)

I tried that method of initialising configs:

  1. Complete setup wizard
  2. setup env in virtualhost
  3. move configs to /etc/airtime/instance1

after that I have setup wizard showing again, that stucks at step 4: Error moving rabbitmq-analyzer.ini or deleting /tmp/rabbitmq.ini.tmp!

From @yarik2720 on Sun Sep 17 2017 16:01:58 GMT+0000 (UTC)

Now I have success on two instances on ubuntu 16.04. (setting up still in progress)
This needs to
*create copy of database
CREATE DATABASE instance2 TEMPLATE airtime;
*set up additional vhost

rabbitmqctl add_vhost /instance2
rabbitmqctl add_user instance2user instance2password
rabbitmqctl set_permissions -p /instance2 instance2user ".\*" ".\*" ".\*"

*after creating main instance of libretime copy generated configurations and edit them on api_key and on settings of rabbitmq and database
also need to change path of logging dirs

now have problem on settings saving, I got error:
An internal application error has occurred.: PhpAmqpLib\Exception\AMQPProtocolChannelException: ACCESS_REFUSED - access to exchange 'airtime-pypo' in vhost '/instance2' refused for user 'instance2user' in /usr/share/airtime/php/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php:188
edit: fixed with code: rabbitmqctl set_permissions -p /instance2 instance2user .\* .\* .\*

Met another problem: instance 2 can’t connect to liquidsoap and liquidsoap.cfg don’t changes after making some configuration on Libretime, maybe I forgot to setup something in aitime.conf?

Also, how I can change music dir for instance 2?

From @hairmare on Mon Sep 18 2017 17:46:55 GMT+0000 (UTC)

> Met another problem: instance 2 can’t connect to liquidsoap and liquidsoap.cfg don’t changes after making some configuration on Libretime, maybe I forgot to setup something in aitime.conf?

Most likely liquidsoaps telnet port needs to be changed on the second instance from the hardcoded default: https://github.com/LibreTime/libretime/blob/9739d64063a390bc5c953dc9186d0b80449f80cf/python_apps/pypo/liquidsoap/ls_script.liq#L5

We should probably make it configurable through the usual way through the generated liquidsoap.cfg.

Also, how I can change music dir for instance 2?

The music dir is stored in the database in the table cc_music_dirs your best bet is to change it directly in the second instances database.

From @yarik2720 on Mon Sep 18 2017 18:19:31 GMT+0000 (UTC)

after setting up variables for first instance as default path as in code below

<VirtualHost *:80>
    # ...
    SetEnv LIBRETIME_CONF_DIR /etc/airtime
    SetEnv LIBRETIME_LOG_DIR /var/log/airtime
    # ...
</VirtualHost>

I have in pypo.log errors:
2017-09-18 21:14:08,534 [api_client] [INFO ] Unable to get Airtime API version number.
and after that main instance can’t connect to liquidsoap

From @hairmare on Tue Sep 19 2017 17:43:43 GMT+0000 (UTC)

The SetEnv LIBRETIME_CONF_DIR line only work for the PHP parts. You also need to set the env variable for the python parts. One possible way to do this would be using a systemd override or by copying and hacking the SysV/upstart scripts for the services. this depends on the distro you are using. Which one are you on?

From @yarik2720 on Tue Sep 19 2017 20:12:11 GMT+0000 (UTC)

Now I’m testing on Ubuntu 16.04

From @hairmare on Wed Sep 20 2017 17:56:52 GMT+0000 (UTC)

Great, so your setup is systemd based. To support multiple instances natively we would need to switch to using systemd templates, this isn’t very high on the priority list but you can work around it by duplicating an existing config and add matching Environment=LIBRETIME_CONF_DIR=/etc/airtime lines.
You can do something similar to the following and then hack the instance1 files. Keep in mind that the liquidsoap telnet issue still needs fixing/working around.

cp /etc/systemd/system/airtime-playout.service /etc/systemd/system/airtime-playout-instance1.service
cp /etc/systemd/system/airtime-liquidsoap.service /etc/systemd/system/airtime-liquidsoap-instance1.service

Any news here?
I tried to install at local virtual machine two instances of libretime with Docker (on ubuntu), that works, but have problem that at one time you can login only at one instance

Nothing has really happened with this, so you have them both installed but what is the issue in terms of logging in ? My suspicion is that it has to do with virtual name-based resolution for the nameserver. Did you setup a custom config with apache for each of the separate sites using a different domain name for each ? That would be another part of the equation, although I’m not sure that the rest of the site wouldn’t also need changes implemented. This isn’t a high priority for me at the moment because most people are doing stand-alone or VPS based installs and we still have some issues there to resolve.

Which docker image did you used?