diff --git a/vagrant-test/.gitignore b/vagrant-test/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d5f501f828173fba8beaf79bccd73722862407d9 --- /dev/null +++ b/vagrant-test/.gitignore @@ -0,0 +1,3 @@ +.vagrant +*.deb +song*.ogg diff --git a/vagrant-test/Vagrantfile b/vagrant-test/Vagrantfile index e451cd8e515f0418018f8b62b0d1f7cd67a18642..dc657e3960b89e4c0990e40a915b0f5db83e05d3 100644 --- a/vagrant-test/Vagrantfile +++ b/vagrant-test/Vagrantfile @@ -1,7 +1,15 @@ +# Vagrantfile for a test 3-node autoradio cluster. +# +# By default it will pull autoradio packages from the public +# repository. Set the environment variable LOCAL to a non-empty value +# if you want to use local packages, in which case the 'etcd' and +# 'autoradio' packages should be placed in the same directory as this +# file. API_VERSION = "2" -# Note: we shouldn't need to create a host entry for 'etcd'... +# Note: we shouldn't need to create a host entry for 'etcd' but it is +# faster to set up the cluster this way. $setup_host_file = <<SCRIPT cat >/etc/hosts <<EOF 127.0.0.1 localhost @@ -18,7 +26,11 @@ Vagrant.configure(API_VERSION) do |config| config.vm.provision "shell", inline: $setup_host_file config.vm.provision "shell" do |s| - s.path = "bootstrap.sh" + if ENV['LOCAL'].nil? + s.path = "bootstrap.sh" + else + s.path = "bootstrap-local.sh" + end s.args = "autora.dio" end @@ -32,7 +44,6 @@ Vagrant.configure(API_VERSION) do |config| config.vm.define "node2" do |m| m.vm.hostname = "node2" m.vm.network "private_network", ip: "192.168.50.3" - #m.vm.provision "shell", inline: "hostname node2" m.vm.provision "shell", inline: "echo ETCD_SERVER=node1 > /etc/default/etcd" end @@ -42,8 +53,10 @@ Vagrant.configure(API_VERSION) do |config| m.vm.network "private_network", ip: "192.168.50.4" m.vm.provision "shell", inline: "echo ETCD_SERVER=node1 > /etc/default/etcd" + + # Create a test mountpoint. m.vm.provision "shell", - inline: "sleep 3 && radioctl create-mount sample.ogg" + inline: "sleep 3 && radioctl create-mount /stream.ogg" end end diff --git a/vagrant-test/bootstrap-local.sh b/vagrant-test/bootstrap-local.sh new file mode 100644 index 0000000000000000000000000000000000000000..bf2de032d7352489090d4f98c5f8f64d7262920d --- /dev/null +++ b/vagrant-test/bootstrap-local.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +cat >/etc/default/icecast2 <<EOF +CONFIGFILE="/etc/icecast2/icecast.xml" +USERID=icecast2 +GROUPID=icecast +ENABLE=true +EOF + +most_recent_match() { + local pattern="$1" + ls -t ${pattern} | head -1 +} + +# Install the required packages. +export DEBIAN_FRONTEND=noninteractive +apt-get -q update +yes N 2>/dev/null | apt-get install -q -y runit icecast2 libcap2-bin liquidsoap +dpkg -i $(most_recent_match /vagrant/etcd_*.deb) +dpkg -i $(most_recent_match /vagrant/autoradio_*.deb) + +# Install the configuration. +DOMAIN="${DOMAIN:-$1}" +if [ -n "${DOMAIN}" ]; then + echo "Autoconfigured with domain: ${DOMAIN}" 1>&2 + echo "DOMAIN=${DOMAIN}" > /etc/default/autoradio +fi +echo "REDIRECTORD_OPTIONS=\"--enable-icecast-proxy\"" >> /etc/default/autoradio + +echo "All done (?)" 1>&2 +exit 0 + diff --git a/vagrant-test/ices.xml.tmpl b/vagrant-test/ices.xml.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..c03d0402ac07beb2b612b209a40b41a73e9e36b1 --- /dev/null +++ b/vagrant-test/ices.xml.tmpl @@ -0,0 +1,100 @@ +<?xml version="1.0"?> +<ices> + <!-- run in background --> + <background>0</background> + <!-- where logs, etc go. --> + <logpath>/tmp</logpath> + <logfile>ices.log</logfile> + <!-- 1=error,2=warn,3=info,4=debug --> + <loglevel>4</loglevel> + <!-- set this to 1 to log to the console instead of to the file above --> + <consolelog>1</consolelog> + + <!-- optional filename to write process id to --> + <!-- <pidfile>/home/ices/ices.pid</pidfile> --> + + <stream> + <!-- metadata used for stream listing (not currently used) --> + <metadata> + <name>Jesus</name> + <genre>Example genre</genre> + <description>A short description of your stream</description> + </metadata> + + <!-- input module + + The module used here is the playlist module - it has + 'submodules' for different types of playlist. There are + two currently implemented, 'basic', which is a simple + file-based playlist, and 'script' which invokes a command + to returns a filename to start playing. --> + + <input> + <module>playlist</module> + <param name="type">basic</param> + <param name="file">ices-playlist.txt</param> + <!-- random play --> + <param name="random">0</param> + <!-- if the playlist get updated that start at the beginning --> + <param name="restart-after-reread">1</param> + <!-- if set to 1 , plays once through, then exits. --> + <param name="once">0</param> + </input> + + <!-- Stream instance + You may have one or more instances here. This allows you to + send the same input data to one or more servers (or to different + mountpoints on the same server). Each of them can have different + parameters. This is primarily useful for a) relaying to multiple + independent servers, and b) encoding/reencoding to multiple + bitrates. + If one instance fails (for example, the associated server goes + down, etc), the others will continue to function correctly. + This example defines two instances as two mountpoints on the + same server. --> + <instance> + <!-- Server details: + You define hostname and port for the server here, along with + the source password and mountpoint. --> + <hostname>192.168.50.3</hostname> + <port>80</port> + <username>@USERNAME@</username> + <password>@PASSWORD@</password> + <mount>/stream.ogg</mount> + + <!-- Reconnect parameters: + When something goes wrong (e.g. the server crashes, or the + network drops) and ices disconnects from the server, these + control how often it tries to reconnect, and how many times + it tries to reconnect. Delay is in seconds. + If you set reconnectattempts to -1, it will continue + indefinately. Suggest setting reconnectdelay to a large value + if you do this. + --> + <reconnectdelay>1</reconnectdelay> + <reconnectattempts>100000</reconnectattempts> + + <!-- maxqueuelength: + This describes how long the internal data queues may be. This + basically lets you control how much data gets buffered before + ices decides it can't send to the server fast enough, and + either shuts down or flushes the queue (dropping the data) + and continues. + For advanced users only. + --> + <maxqueuelength>80</maxqueuelength> + + <!-- Live encoding/reencoding: + Currrently, the parameters given here for encoding MUST + match the input data for channels and sample rate. That + restriction will be relaxed in the future. + --> + <encode> + <nominal-bitrate>64000</nominal-bitrate> <!-- bps. e.g. 64000 for 64 kbps --> + <samplerate>44100</samplerate> + <channels>2</channels> + </encode> + </instance> + + </stream> +</ices> diff --git a/vagrant-test/start-source b/vagrant-test/start-source new file mode 100755 index 0000000000000000000000000000000000000000..82bb5d87cf8f0fdcf8dd3dce1a7e47132cb6ed94 --- /dev/null +++ b/vagrant-test/start-source @@ -0,0 +1,32 @@ +#!/bin/sh +# +# Stream data to the test mountpoint, using 'ices2'. +# + +stream=/stream.ogg + +# Download a couple of test songs. +for song in song1.ogg song2.ogg ; do + test -e /vagrant/${song} || wget -O /vagrant/${song} http://www.incal.net/ale/test-songs/${song} +done + +# Install Ices2. +sudo apt-get -q -y install ices2 + +# Create the Ices2 config file. +username=$(radioctl show-mount ${stream} | awk -F= '/^username/ {print $2}') +password=$(radioctl show-mount ${stream} | awk -F= '/^password/ {print $2}') +if [ -z "${username}" ]; then + echo "ERROR: stream ${stream} not found" + exit 1 +fi + +sed -e s/@USERNAME@/${username}/ -e s/@PASSWORD@/${password}/ \ + < /vagrant/ices.xml.tmpl > /tmp/ices.xml +cat > /tmp/ices-playlist.txt <<EOF +/vagrant/song1.ogg +/vagrant/song2.ogg +EOF + +cd /tmp +ices2 /tmp/ices.xml