aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Piggott <nick+work@piggott.eu>2015-08-28 17:12:17 +0100
committerNick Piggott <nick+work@piggott.eu>2015-08-28 17:12:17 +0100
commit79a58e5b66c76044ed083265c90b853cb4924da8 (patch)
treef1a4e1ab6a5476baf6131a5208674c87031f9529
parent358774ca2aaef07f8282a00ca672e6fc62068e3c (diff)
downloaddab-scripts-79a58e5b66c76044ed083265c90b853cb4924da8.tar.gz
dab-scripts-79a58e5b66c76044ed083265c90b853cb4924da8.tar.bz2
dab-scripts-79a58e5b66c76044ed083265c90b853cb4924da8.zip
Add Support to start MOT Encoder
Some changes to the configuration.sh file and encoder launchers to start mot-encoders for services using toolame.
-rw-r--r--encode-mot.sh92
-rw-r--r--examplesite/configuration.sh18
-rwxr-xr-xkill-all-encoders.sh2
-rwxr-xr-xlaunch-all-encoders.sh12
-rw-r--r--mot.sh51
5 files changed, 165 insertions, 10 deletions
diff --git a/encode-mot.sh b/encode-mot.sh
new file mode 100644
index 0000000..ad60bad
--- /dev/null
+++ b/encode-mot.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+#
+# Encode programme using libVLC input from
+# dabplus-enc or toolame
+#
+# monitor processes, and restart if necessary
+# Optionally send an email when restart happens
+
+printerr() {
+ echo -e "\033[01;31m$1\033[0m"
+ logger -p local0.error -t "$ID" "$1"
+}
+
+printmsg() {
+ echo -e "\033[01;32m$1\033[0m"
+ logger -p local0.notice -t "$ID" "$1"
+}
+
+set -u
+
+# check number of arguments
+if [[ "$#" -lt 3 ]] ; then
+ echo "Usage $0 id options"
+ exit 1
+fi
+
+ID=$1
+shift 2
+
+OPTIONS=$@
+
+running=1
+
+encoderpid=0
+
+# The trap for Ctrl-C
+sigint_trap() {
+ printerr "Got Ctrl-C, killing mot-encoder"
+ running=0
+
+ if [[ "$encoderpid" != "0" ]] ; then
+ kill -TERM $encoderpid
+ fi
+
+ printmsg "quitting"
+ exit
+}
+
+trap sigint_trap SIGTERM
+trap sigint_trap SIGINT
+
+while [[ "$running" == "1" ]]
+do
+
+ printmsg "Launching mot-encoder"
+ mot-encoder $OPTIONS &
+ encoderpid=$!
+ printerr "Detected crash of encoder!"
+
+ sleep 5
+
+ checkloop=1
+ while [[ "$checkloop" == "1" ]]
+ do
+ sleep 2
+
+ kill -s 0 $encoderpid
+ if [[ "$?" != "0" ]] ; then
+ printerr "the mot-encoder died"
+
+ encoderpid=0
+ checkloop=0
+ fi
+ done
+
+ MAILTO=$(cat ./mail-warning.txt)
+
+ if [[ "$MAILTO" != "" ]] ; then
+ NOW=$(date)
+
+ mail -s "MOT Encoder $ID restart $URL" "$MAILTO" << EOF
+The encoder id:$ID
+encoding using mot-encoder was restarted at
+$NOW
+
+EOF
+
+ fi
+ sleep 5
+
+done
+
diff --git a/examplesite/configuration.sh b/examplesite/configuration.sh
index a065697..bcbffc0 100644
--- a/examplesite/configuration.sh
+++ b/examplesite/configuration.sh
@@ -1,17 +1,23 @@
# Configuration file for the encoder scripts
-all_radios=(
- "radio1"
- "radio2" )
+all_radios=("radio1" "radio2" "radio3")
+all_mot=("radio1" "radio3")
# declare radios to be an associative array, DO NOT REMOVE
declare -A radios
+declare -A mot
# for each radio, write here the full encoder command.
# encode-jack needs:
# URL ID dabmux-URL [amplitude correction]
-radios[radio1]="./encode-libvlc.sh http://fbpc5.epfl.ch:8000/fb_192 radio1 tcp://localhost:9001"
-# Attenuate radio2 by 3dB
-radios[radio2]="./encode-libvlc.sh http://mp3lg.tdf-cdn.com/fip/all/fiphautdebit.mp3 radio2 tcp://localhost:9002 toolame -b 128 -s 48 -m j -y 2 -L"
+# radio1
+radios[radio1]="./encode-libvlc.sh http://radio1.aac Radio1 tcp://localhost:9001 toolame -b 128 -s 48 -m j -y 2 -L -W dls/radio1.txt -p 6 -P dls/radio1.dls"
+mot[radio]="./encode-mot.sh Radio1 --pad 6 --remove-dls --dls dls/radio1.txt --output dls/radio1.dls"
+# radio2
+radios[radio2]="./encode-libvlc.sh http://radio2.aac Radio2 tcp://localhost:9002 toolame -b 128 -s 48 -m j -y 2 -L"
+
+# radio3
+radios[radio3]="./encode-libvlc.sh http://radio3.aac Radio3 tcp://localhost:9003 toolame -b 128 -s 48 -m j -y 2 -L -W dls/radio3.txt -p 6 -P dls/radio3.dls"
+mot[radio3]="./encode-mot.sh Radio3 --pad 6 --remove-dls --dls dls/radio3.txt --output dls/radio3.dls"
diff --git a/kill-all-encoders.sh b/kill-all-encoders.sh
index c572517..38a6f34 100755
--- a/kill-all-encoders.sh
+++ b/kill-all-encoders.sh
@@ -3,4 +3,4 @@
# kill all processes
pkill -INT "radio.sh"
-
+pkill -INT "mot.sh"
diff --git a/launch-all-encoders.sh b/launch-all-encoders.sh
index e4ca3db..699fe4f 100755
--- a/launch-all-encoders.sh
+++ b/launch-all-encoders.sh
@@ -3,18 +3,24 @@
set -e
-if [ -f site/configuration.sh ]
+if [ -f ./configuration.sh ]
then
- source site/configuration.sh
+ source ./configuration.sh
for radio in ${all_radios[*]}
do
echo "Launching $radio encoder"
- screen -t "$radio" ./radio.sh "$radio"
+ screen -t "Audio Encoder $radio" ./radio.sh "$radio"
sleep 0.4
done
+ for mot in ${all_mot[*]}
+ do
+ echo "Launching $mot mot-encoder"
+ screen -t "MOT Encoder $mot" ./mot.sh "$mot"
+ sleep 0.4
+ done
else
echo "Error: No site configuration available!"
exit 1
diff --git a/mot.sh b/mot.sh
new file mode 100644
index 0000000..2a61e3d
--- /dev/null
+++ b/mot.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# Start the mot-encoder for the radio
+
+set -e
+
+source ./configuration.sh
+
+printerr() {
+ echo -e "\033[01;31m$1\033[0m"
+}
+
+printmsg() {
+ echo -e "\033[01;32m$1\033[0m"
+}
+
+script_pid=0
+sigint_trap() {
+ printerr "Got Ctrl-C, killing radio encoder script"
+ if [[ "$script_pid" != "0" ]] ; then
+ kill $script_pid
+ script_pid=0
+ wait
+ fi
+}
+
+set -e
+
+# check number of arguments
+if [[ "$#" -lt 1 ]] ; then
+ echo "Usage $0 radio-id"
+ echo "You must specify which radio to start"
+ exit 1
+fi
+
+RADIO=$1
+
+if [ "${mot[$RADIO]+_}" ] ; then
+ COMMAND=${mot[$RADIO]}
+
+ trap sigint_trap SIGINT
+
+ # execute script
+ $COMMAND &
+ script_pid=$!
+ wait
+else
+ echo "Radio $RADIO not defined in configuration"
+ exit 1
+fi
+