summaryrefslogtreecommitdiffstats
path: root/roles/stream/templates
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xroles/stream/templates/icecast-emacsconf.init.d8
-rw-r--r--roles/stream/templates/icecast.xml30
-rwxr-xr-xroles/stream/templates/lowres.init.d76
-rwxr-xr-xroles/stream/templates/lowres.sh6
-rwxr-xr-xroles/stream/templates/on-connect12
-rwxr-xr-xroles/stream/templates/on-disconnect29
6 files changed, 141 insertions, 20 deletions
diff --git a/roles/stream/templates/icecast-emacsconf.init.d b/roles/stream/templates/icecast-emacsconf.init.d
index b3ad491..3d880c1 100755
--- a/roles/stream/templates/icecast-emacsconf.init.d
+++ b/roles/stream/templates/icecast-emacsconf.init.d
@@ -30,14 +30,10 @@ test -x $DAEMON || exit 0
# Defaults
CONFIGFILE="/etc/icecast2/icecast-emacsconf.xml"
-CONFIGDEFAULTFILE="/etc/default/icecast2"
-USERID=icecast2
-GROUPID=icecast
+USERID={{ icecast_user }}
+GROUPID={{ icecast_group }}
PIDFILE=/var/run/icecast-emacsconf
-# Reads config file (will override defaults above)
-[ -r "$CONFIGDEFAULTFILE" ] && . $CONFIGDEFAULTFILE
-
set -e
case "$1" in
diff --git a/roles/stream/templates/icecast.xml b/roles/stream/templates/icecast.xml
index d2bb89c..e09e6a0 100644
--- a/roles/stream/templates/icecast.xml
+++ b/roles/stream/templates/icecast.xml
@@ -190,33 +190,35 @@
{% for track in emacsconf_tracks %}
<mount type="normal">
<mount-name>/emacsconf/{{ track.id }}.webm</mount-name>
- <username>emacsconf</username>
+ <username>{{ icecast_emacsconf_user }}</username>
<password>{{ icecast_emacsconf_password }}</password>
- <dump-file>/data/emacsconf-{{ emacsconf_year }}-{{ track.id }}_%Y-%m-%d_%H-%M-%S.webm</dump-file>
- <stream-name>EmacsConf {{ emacsconf_year }} - {{ track.name }} track</stream-name>
- <stream-description>The livestream for the {{ track.name }} track of EmacsConf {{ emacsconf_year }}</stream-description>
- <stream-url>https://emacsconf.org/{{ emacsconf_year }}/watch/{{ track.id }}/</stream-url>
+ <dump-file>/data/{{ emacsconf_id }}-{{ emacsconf_year }}-{{ track.id }}_%Y-%m-%d_%H-%M-%S.webm</dump-file>
+ <stream-name>{{ emacsconf_name }} {{ emacsconf_year }} - {{ track.name }} track</stream-name>
+ <stream-description>The livestream for the {{ track.name }} track of {{ emacsconf_name }} {{ emacsconf_year }}</stream-description>
+ <stream-url>{{ track.watch }}</stream-url>
<type>video/webm</type>
<public>1</public>
+ <on-connect>/usr/local/bin/{{ emacsconf_id }}-lowres-{{ track.id }}-on-connect</on-connect>
+ <on-disconnect>/usr/local/bin/{{ emacsconf_id }}-lowres-{{ track.id }}-on-disconnect</on-disconnect>
</mount>
<mount type="normal">
- <mount-name>/emacsconf/{{ track.id }}-host.webm</mount-name>
- <username>emacsconf</username>
+ <mount-name>/{{ emacsconf_id }}/{{ track.id }}-host.webm</mount-name>
+ <username>{{ icecast_emacsconf_user }}</username>
<password>{{ icecast_emacsconf_password }}</password>
<stream-name>EmacsConf {{ emacsconf_year }} - {{ track.name }} track</stream-name>
- <stream-description>The host stream for the {{ track.name }} track of EmacsConf {{ emacsconf_year }}</stream-description>
- <stream-url>https://emacsconf.org/{{ emacsconf_year }}/watch/{{ track.id }}/</stream-url>
+ <stream-description>The host stream for the {{ track.name }} track of {{ emacsconf_name }} {{ emacsconf_year }}</stream-description>
+ <stream-url>{{ track.watch }}</stream-url>
<type>video/webm</type>
<public>1</public>
<hidden>1</hidden>
</mount>
<mount type="normal">
- <mount-name>/emacsconf/{{ track.id }}-480p.webm</mount-name>
- <username>emacsconf</username>
+ <mount-name>/{{ emacsconf_id }}/{{ track.id }}-480p.webm</mount-name>
+ <username>{{ icecast_emacsconf_user }}</username>
<password>{{ icecast_emacsconf_password }}</password>
- <stream-name>EmacsConf {{ emacsconf_year }} - {{ track.name }} track (480p)</stream-name>
- <stream-description>The 480p livestream for the {{ track.name }} track of EmacsConf {{ emacsconf_year }}</stream-description>
- <stream-url>https://emacsconf.org/{{ emacsconf_year }}/watch/{{ track.id }}/</stream-url>
+ <stream-name>{{ emacsconf_name }} {{ emacsconf_year }} - {{ track.name }} track (480p)</stream-name>
+ <stream-description>The low-res livestream for the {{ track.name }} track of {{ emacsconf_name }} {{ emacsconf_year }}</stream-description>
+ <stream-url>{{ track.watch_lowres }}</stream-url>
<type>video/webm</type>
<public>1</public>
</mount>
diff --git a/roles/stream/templates/lowres.init.d b/roles/stream/templates/lowres.init.d
new file mode 100755
index 0000000..41da95c
--- /dev/null
+++ b/roles/stream/templates/lowres.init.d
@@ -0,0 +1,76 @@
+#!/bin/sh
+# {{ ansible_managed }}
+
+### BEGIN INIT INFO
+# Provides: {{ emacsconf_id }}-lowres-{{ item.id }}
+# Required-Start: $local_fs $remote_fs $network $syslog
+# Required-Stop: $local_fs $remote_fs $network $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: 480p restreaming for {{ item.name }}
+# Description: 480p restreaming for {{ item.name }} using start-stop-daemon
+### END INIT INFO
+
+PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
+USER="{{ icecast_user }}"
+GROUP="{{ icecast_group }}"
+DESC="Low-res restream for {{ item.name }}"
+NAME="{{ emacsconf_id }}-lowres-{{ item.id }}"
+
+set -e
+
+. /lib/lsb/init-functions
+
+start() {
+ echo "Starting $DESC... "
+ start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec "/usr/local/bin/{{ emacsconf_id }}-lowres-{{ item.id }}.sh http://localhost:{{ icecast_port }}/{{ item.id }}.webm http:// > /var/log/$NAME.log" || true
+ echo "done"
+}
+
+#We need this function to ensure the whole process tree will be killed
+killtree() {
+ local _pid=$1
+ local _sig=${2-TERM}
+ for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
+ killtree ${_child} ${_sig}
+ done
+ kill -${_sig} ${_pid}
+}
+
+stop() {
+ echo "Stopping $DESC... "
+ if test -f /var/run/$NAME.pid; then
+ while test -d /proc/$(cat /var/run/$NAME.pid); do
+ killtree $(cat /var/run/$NAME.pid) 15
+ sleep 0.5
+ done
+ rm /var/run/$NAME.pid
+ fi
+ echo "done"
+}
+
+status() {
+ status_of_proc -p /var/run/$NAME.pid "" "$NAME" && exit 0 || exit $?
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ status)
+ status
+ ;;
+ *)
+ echo "Usage: $NAME {start|stop|restart|status}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/roles/stream/templates/lowres.sh b/roles/stream/templates/lowres.sh
new file mode 100755
index 0000000..1f74215
--- /dev/null
+++ b/roles/stream/templates/lowres.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+# {{ ansible_managed }}
+sleep 10
+for i in 1 2 3 4 5; do
+ ffmpeg -loglevel 24 -f webm -reconnect_at_eof 1 -reconnect_streamed 1 -re -i "http://localhost:{{ icecast_port }}/{{ emacsconf_id }}/{{ item.id }}.webm" -vf scale="{{ icecast_lowres_scale }}" -f webm -c:a copy -b:v 500k -maxrate 1M -bufsize 1M -content_type video/webm -c:v libvpx "icecast://{{ icecast_emacsconf_user }}:{{ icecast_emacsconf_password }}@localhost:{{ icecast_port }}/{{ emacsconf_id }}/{{ item.id }}-480p.webm" >> {{ icecast_restream_dir }}/{{ emacsconf_id }}-lowres-{{ item.id }}.log || sleep 5
+done
diff --git a/roles/stream/templates/on-connect b/roles/stream/templates/on-connect
new file mode 100755
index 0000000..0f613bf
--- /dev/null
+++ b/roles/stream/templates/on-connect
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
+PIDFILE="{{ icecast_restream_dir }}/{{ emacsconf_id }}-lowres-{{ item.id }}.pid"
+echo $(date) " on connect {{ item.id }} $*" >> {{ icecast_restream_dir }}/restream.log
+
+. /lib/lsb/init-functions
+
+start-stop-daemon --start --quiet --background \
+ --make-pidfile --pidfile $PIDFILE \
+ --oknodo \
+ --exec /usr/local/bin/{{ emacsconf_id }}-lowres-{{ item.id }}.sh > /dev/null
diff --git a/roles/stream/templates/on-disconnect b/roles/stream/templates/on-disconnect
new file mode 100755
index 0000000..5847356
--- /dev/null
+++ b/roles/stream/templates/on-disconnect
@@ -0,0 +1,29 @@
+#!/bin/bash
+set -e
+PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
+PIDFILE="{{ icecast_restream_dir }}/{{ emacsconf_id }}-lowres-{{ item.id }}.pid"
+echo $(date) " on disconnect {{ item.id }} $*" >> {{ icecast_restream_dir }}/restream.log
+
+. /lib/lsb/init-functions
+
+#We need this function to ensure the whole process tree will be killed
+killtree() {
+ local _pid=$1
+ local _sig=${2-TERM}
+ for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
+ killtree ${_child} ${_sig}
+ done
+ kill -${_sig} ${_pid}
+}
+
+stop() {
+ echo "Stopping $DESC... "
+ if test -f $PIDFILE; then
+ while test -d /proc/$(cat $PIDFILE); do
+ killtree $(cat $PIDFILE) 15
+ sleep 0.5
+ done
+ rm $PIDFILE
+ fi
+ echo "done"
+}