Merge branch '2.5.x-installer' into saas-installer-albert

Conflicts:
	.gitignore
	airtime_mvc/application/Bootstrap.php
	airtime_mvc/application/configs/conf.php
	airtime_mvc/application/controllers/SystemstatusController.php
	airtime_mvc/application/controllers/UpgradeController.php
	airtime_mvc/application/upgrade/Upgrades.php
	airtime_mvc/application/views/scripts/systemstatus/index.phtml
	airtime_mvc/build/airtime.conf
	airtime_mvc/build/sql/defaultdata.sql
	airtime_mvc/public/index.php
	airtime_mvc/tests/application/helpers/AirtimeInstall.php
	install_minimal/airtime-install
	install_minimal/include/airtime-constants.php
	install_minimal/include/airtime-copy-files.sh
	install_minimal/include/airtime-db-install.php
	install_minimal/include/airtime-initialize.sh
	install_minimal/include/airtime-install.php
	install_minimal/include/airtime-installed-check.php
	install_minimal/include/airtime-remove-files.sh
	install_minimal/include/airtime-upgrade.php
	python_apps/media-monitor/install/media-monitor-copy-files.py
	python_apps/monit/monit-airtime-generic.cfg
	python_apps/pypo/airtime-playout
	python_apps/pypo/install/pypo-copy-files.py
	python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py
	python_apps/pypo/liquidsoap/ls_script.liq
	python_apps/pypo/pypo/__main__.py
	python_apps/pypo/pypo/media/update/replaygain.py
	python_apps/pypo/pypo/media/update/replaygainupdater.py
	python_apps/pypo/pypo/media/update/silananalyzer.py
	python_apps/python-virtualenv/airtime_virtual_env.pybundle
	python_apps/python-virtualenv/requirements
	utils/airtime-check-system.php
This commit is contained in:
Albert Santoni 2015-05-22 16:05:29 -04:00
commit 11c6818e61
335 changed files with 5114 additions and 10061 deletions

View file

@ -1,48 +0,0 @@
#!/bin/bash -e
debug="f"
showhelp () {
echo "Usage: airtime-liquidsoap [options]
--help|-h Displays usage information.
--debug|-d Print error messages to console"
}
set -- $(getopt -l help,debug "hd" "$@")
while [ $# -gt 0 ]
do
case "$1" in
(-h|--help) showhelp; exit 0;;
(-d|--debug) debug="t";;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/"
. ${virtualenv_bin}activate
export HOME="/var/tmp/airtime/pypo/"
api_client_path="/usr/lib/airtime/"
if [ $debug = "t" ]; then
ls_path="/usr/bin/airtime-liquidsoap --verbose -f"
else
ls_path="/usr/bin/airtime-liquidsoap --verbose -f -d"
fi
ls_param="/usr/lib/airtime/pypo/bin/liquidsoap_scripts/ls_script.liq"
export PYTHONPATH=${api_client_path}
SCRIPT=`readlink -f $0`
# Absolute directory this script is in
SCRIPTPATH=`dirname $SCRIPT`
cd $SCRIPTPATH/liquidsoap_scripts
python generate_liquidsoap_cfg.py
exec ${ls_path} ${ls_param} 2>&1
# EOF

View file

@ -1,125 +0,0 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: airtime-liquidsoap
# Required-Start: $local_fs $remote_fs $network $syslog $all
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Liquidsoap daemon
### END INIT INFO
USERID=pypo
GROUPID=pypo
NAME="Liquidsoap Playout Engine"
DAEMON=/usr/lib/airtime/pypo/bin/airtime-liquidsoap
PIDFILE=/var/run/airtime-liquidsoap.pid
EXEC='/usr/bin/airtime-liquidsoap'
start () {
mkdir -p /var/log/airtime/pypo-liquidsoap
chown $USERID:$GROUPID /var/log/airtime/pypo-liquidsoap
chown $USERID:$GROUPID /etc/airtime
touch /etc/airtime/liquidsoap.cfg
chown $USERID:$GROUPID /etc/airtime/liquidsoap.cfg
touch $PIDFILE
chown $USERID:$GROUPID $PIDFILE
#start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
#--pidfile $PIDFILE --nicelevel -15 --startas $DAEMON
start-stop-daemon --start --quiet --chuid $USERID:$GROUPID \
--nicelevel -15 --startas $DAEMON --exec $EXEC
}
stop () {
timeout --version >/dev/null 2>&1
RESULT="$?"
#send term signal after 10 seconds
if [ "$RESULT" = "0" ]; then
timeout -s9 10s /usr/lib/airtime/airtime_virtualenv/bin/python \
/usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
else
#some earlier versions of Ubuntu (Lucid) had a different timeout
#command that takes different input parameters.
timeout 10 /usr/lib/airtime/airtime_virtualenv/bin/python \
/usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap_prepare_terminate.py
fi
# Send TERM after 5 seconds, wait at most 30 seconds.
#start-stop-daemon --stop --oknodo --retry=TERM/10/KILL/5 --quiet --pidfile $PIDFILE
start-stop-daemon --stop --oknodo --retry=TERM/10/KILL/5 --quiet --exec $EXEC
rm -f $PIDFILE
sleep 2
}
start_with_monit () {
start
monit monitor airtime-liquidsoap >/dev/null 2>&1
}
stop_with_monit() {
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
stop
}
case "${1:-''}" in
'stop')
echo "* Stopping Liquidsoap without notifying Monit process watchdog. If Monit is
* running it will automatically bring the Liquidsoap back up. You probably want
* 'stop-with-monit' instead of 'stop'."
echo -n "Stopping $NAME: "
stop
echo "Done."
;;
'start')
echo "* Starting $NAME without Monit process watchdog. To make sure Monit is watching
* Liquidsoap, use 'start-with-monit' instead of 'start'."
echo -n "Starting $NAME: "
start
echo "Done."
;;
'restart')
# restart commands here
echo -n "Restarting $NAME: "
stop
start
echo "Done."
;;
'status')
if [ -f "$PIDFILE" ]; then
pid=`cat $PIDFILE`
if [ -d "/proc/$pid" ]; then
echo "$NAME is running"
exit 0
fi
fi
echo "$NAME is not running"
exit 1
;;
'start-with-monit')
# restart commands here
echo -n "Starting $NAME: "
start_with_monit
echo "Done."
;;
'stop-with-monit')
# restart commands here
echo -n "Stopping $NAME: "
stop_with_monit
echo "Done."
;;
*) # no parameter specified
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac

View file

@ -1,35 +0,0 @@
#!/bin/bash
virtualenv_bin="/usr/lib/airtime/airtime_virtualenv/bin/"
. ${virtualenv_bin}activate
# Absolute path to this script
SCRIPT=`readlink -f $0`
# Absolute directory this script is in
pypo_path=`dirname $SCRIPT`
api_client_path="/usr/lib/airtime/"
pypo_script="pypocli.py"
cd ${pypo_path}
set +e
cat /etc/default/locale | grep -i "LANG=.*UTF-\?8"
set -e
if [ "$?" != "0" ]; then
echo "non UTF-8 default locale found in /etc/default/locale." > /var/log/airtime/pypo/error.log
exit 1
fi
export HOME="/var/tmp/airtime/pypo/"
export PYTHONPATH=${api_client_path}:$PYTHONPATH
export LC_ALL=`cat /etc/default/locale | grep "LANG=" | cut -d= -f2 | tr -d "\n\""`
export TERM=xterm
#Nothing to do with Pypo, but for container maintenance. Let's parse the IP address
#so we may more easily manage our instance containers
ifconfig eth0 | egrep -o 'inet addr:([0-9]{1,3}\.){3}[0-9]{1,3}' | cut -d':' -f2 > /etc/airtime_ip_addr
exec python ${pypo_path}/${pypo_script} > /var/log/airtime/pypo/py-interpreter.log 2>&1
# EOF

View file

@ -0,0 +1,5 @@
#!/usr/bin/python
import runpy
# Run the liquidsoap python module
runpy.run_module('liquidsoap')

View file

@ -0,0 +1,5 @@
#!/usr/bin/python
import runpy
runpy.run_module("pypo", run_name="__main__")

View file

@ -1,3 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import traceback
@ -50,7 +51,7 @@ parser.add_option("-n", "--liquidsoap-started", help="notify liquidsoap started"
(options, args) = parser.parse_args()
# configure logging
logging.config.fileConfig("notify_logging.cfg")
logging.config.fileConfig('/etc/airtime/notify_logging.cfg')
logger = logging.getLogger('notify')
LogWriter.override_std_err(logger)
@ -59,7 +60,7 @@ LogWriter.override_std_err(logger)
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
logger.error('Error loading config file: %s', e)

View file

@ -1,140 +0,0 @@
import os
import grp
import stat
import shutil
import sys
import subprocess
import random
import string
import re
from configobj import ConfigObj
if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
def get_current_script_dir():
current_script_dir = os.path.realpath(__file__)
index = current_script_dir.rindex('/')
return current_script_dir[0:index]
def copy_dir(src_dir, dest_dir):
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
shutil.rmtree(dest_dir)
if not (os.path.exists(dest_dir)):
#print "Copying directory "+os.path.realpath(src_dir)+" to "+os.path.realpath(dest_dir)
shutil.copytree(src_dir, dest_dir)
def create_dir(path):
try:
os.makedirs(path)
except Exception, e:
pass
def get_rand_string(length=10):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
def get_rand_string(length=10):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
def get_monit_version():
version = 0
try:
p = subprocess.Popen(['monit', '-V'], stdout=subprocess.PIPE)
out = p.communicate()[0].strip()
search = re.search(r'This is Monit version (.*)\n', out, re.IGNORECASE)
if search:
matches = search.groups()
if len(matches) == 1:
version = matches[0]
except Exception:
print "Could not get monit version"
return version
#return 1 if version1 > version2
#return 0 if version1 == version2
#return -1 if version1 < version2
def version_compare(version1, version2):
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
return cmp(normalize(version1), normalize(version2))
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
try:
# Absolute path this script is in
current_script_dir = get_current_script_dir()
if not os.path.exists(PATH_INI_FILE):
shutil.copy('%s/../pypo.cfg'%current_script_dir, PATH_INI_FILE)
try:
os.remove("/etc/airtime/liquidsoap.cfg")
except Exception, e:
pass
gid = grp.getgrnam("pypo").gr_gid
os.chown("/etc/airtime", -1, gid)
os.chmod("/etc/airtime", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
# load config file
try:
config = ConfigObj(PATH_INI_FILE)
except Exception, e:
print 'Error loading config file: ', e
sys.exit(1)
#copy monit files
shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/')
subprocess.call('sed -i "s/\$admin_pass/%s/g" /etc/monit/conf.d/monit-airtime-generic.cfg' % get_rand_string(), shell=True)
monit_version = get_monit_version()
if version_compare(monit_version, "5.3.0") >= 0:
shutil.copy('%s/../monit-airtime-liquidsoap.cfg' % current_script_dir, \
'/etc/monit/conf.d/monit-airtime-liquidsoap.cfg')
else:
shutil.copy('%s/../monit-pre530-airtime-liquidsoap.cfg' % current_script_dir, \
'/etc/monit/conf.d/monit-airtime-liquidsoap.cfg')
shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/')
#create pypo log dir
create_dir(config['pypo_log_dir'])
os.system("chown -R pypo:pypo "+config["pypo_log_dir"])
#create liquidsoap log dir
create_dir(config['liquidsoap_log_dir'])
os.system("chown -R pypo:pypo "+config["liquidsoap_log_dir"])
#create cache, tmp, file dirs
create_dir(config['cache_dir'])
create_dir(config['file_dir'])
create_dir(config['tmp_dir'])
create_dir(config["base_recorded_files"])
#copy files to bin dir
copy_dir("%s/.."%current_script_dir, config["bin_dir"]+"/bin/")
# delete /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap.cfg
# as we don't use it anymore.(CC-2552)
os.remove(config["bin_dir"]+"/bin/liquidsoap_scripts/liquidsoap.cfg")
#set permissions in bin dir and cache dir
os.system("chmod 755 "+os.path.join(config["bin_dir"], "bin/liquidsoap_scripts/notify.sh"))
os.system("chown -R pypo:pypo "+config["bin_dir"])
os.system("chown -R pypo:pypo "+config["cache_base_dir"])
os.system("chown -R pypo:pypo "+config["base_recorded_files"])
#copy init.d script
shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout")
shutil.copy(config["bin_dir"]+"/bin/airtime-liquidsoap-init-d", "/etc/init.d/airtime-liquidsoap")
#copy log rotate script
shutil.copy(config["bin_dir"]+"/bin/liquidsoap_scripts/airtime-liquidsoap.logrotate", "/etc/logrotate.d/airtime-liquidsoap")
except Exception, e:
print e

View file

@ -1,95 +0,0 @@
import platform
import shutil
from subprocess import Popen, PIPE
import subprocess
import sys
import os
sys.path.append('/usr/lib/airtime/')
from api_clients import api_client
from configobj import ConfigObj
import logging
if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
"""
This function returns the codename of the host OS by querying lsb_release.
If lsb_release does not exist, or an exception occurs the codename returned
is 'unknown'
"""
def get_os_codename():
try:
p = Popen("which lsb_release > /dev/null", shell=True)
sts = os.waitpid(p.pid, 0)[1]
if (sts == 0):
#lsb_release is available on this system. Let's get the os codename
p = Popen("lsb_release -sc", shell=True, stdout=PIPE)
codename = p.communicate()[0].strip('\r\n')
p = Popen("lsb_release -sd", shell=True, stdout=PIPE)
fullname = p.communicate()[0].strip('\r\n')
return (codename, fullname)
except Exception, e:
pass
return ("unknown", "unknown")
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
PATH_LIQUIDSOAP_BIN = '/usr/lib/airtime/pypo/bin/liquidsoap_bin'
#any debian/ubuntu codename in this et will automatically use the natty liquidsoap binary
arch_map = dict({"32bit":"i386", "64bit":"amd64"})
# load config file
try:
config = ConfigObj(PATH_INI_FILE)
except Exception, e:
print 'Error loading config file: ', e
sys.exit(1)
try:
#select appropriate liquidsoap file for given system os/architecture
architecture = platform.architecture()[0]
arch = arch_map[architecture]
print "* Detecting OS: ...",
(codename, fullname) = get_os_codename()
print " Found %s (%s) on %s architecture" % (fullname, codename, arch)
print " * Creating symlink to Liquidsoap binary"
p = Popen("which liquidsoap", shell=True, stdout=PIPE)
liq_path = p.communicate()[0].strip()
symlink_path = "/usr/bin/airtime-liquidsoap"
if p.returncode == 0:
try:
os.unlink(symlink_path)
except Exception:
#liq_path DNE, which is OK.
pass
os.symlink(liq_path, symlink_path)
else:
print " * Liquidsoap binary not found!"
sys.exit(1)
#initialize init.d scripts
subprocess.call("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True)
subprocess.call("update-rc.d airtime-liquidsoap defaults >/dev/null 2>&1", shell=True)
#clear out an previous pypo cache
print "* Clearing previous pypo cache"
subprocess.call("rm -rf /var/tmp/airtime/pypo/cache/scheduler/* >/dev/null 2>&1", shell=True)
if "airtime_service_start" in os.environ and os.environ["airtime_service_start"] == "t":
print "* Waiting for pypo processes to start..."
subprocess.call("invoke-rc.d airtime-liquidsoap start > /dev/null 2>&1", shell=True)
subprocess.call("invoke-rc.d airtime-playout start > /dev/null 2>&1", shell=True)
except Exception, e:
print e

View file

@ -1,54 +0,0 @@
import os
import shutil
import sys
from configobj import ConfigObj
if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
def remove_file(path):
try:
os.remove(path)
except Exception, e:
pass
# load config file
try:
config = ConfigObj(PATH_INI_FILE)
except Exception, e:
print 'Error loading config file: ', e
sys.exit(1)
try:
#remove log rotate script
print " * Removing Pypo Log Rotate Script"
remove_file("/etc/logrotate.d/airtime-liquidsoap")
#remove init.d script
print " * Removing Pypo init.d Script"
remove_file("/etc/init.d/airtime-playout")
remove_file("/etc/init.d/airtime-liquidsoap")
#remove bin, cache, tmp and file dir
print " * Removing Pypo Program Directory"
shutil.rmtree(config['bin_dir'], ignore_errors=True)
shutil.rmtree(config['cache_dir'], ignore_errors=True)
shutil.rmtree(config['file_dir'], ignore_errors=True)
shutil.rmtree(config['tmp_dir'], ignore_errors=True)
#remove liquidsoap and pypo log dir
print " * Removing Pypo Log Directories"
shutil.rmtree(config['liquidsoap_log_dir'], ignore_errors=True)
shutil.rmtree(config['pypo_log_dir'], ignore_errors=True)
#remove monit files
print " * Removing Pypo Monit Files"
remove_file("/etc/monit/conf.d/monit-airtime-playout.cfg")
remove_file("/etc/monit/conf.d/monit-airtime-liquidsoap.cfg")
remove_file("/etc/monit/conf.d/monit-airtime-generic.cfg")
except Exception, e:
print e

View file

@ -1,33 +0,0 @@
import os
import sys
import subprocess
if os.geteuid() != 0:
print "Please run this as root."
sys.exit(1)
try:
#stop pypo and liquidsoap processes
print "Waiting for Pypo process to stop...",
try:
os.remove("/usr/bin/airtime-liquidsoap")
except Exception, e:
pass
if (os.path.exists('/etc/init.d/airtime-playout')):
subprocess.call("invoke-rc.d airtime-playout stop", shell=True)
print "OK"
else:
print "Wasn't running"
print "Waiting for Liquidsoap process to stop...",
if (os.path.exists('/etc/init.d/airtime-liquidsoap')):
subprocess.call("invoke-rc.d airtime-liquidsoap stop", shell=True)
print "OK"
else:
print "Wasn't running"
subprocess.call("update-rc.d -f airtime-playout remove".split(" "))
subprocess.call("update-rc.d -f airtime-liquidsoap remove".split(" "))
except Exception, e:
print e

View file

@ -0,0 +1,78 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: airtime-liquidsoap
# Required-Start: $local_fs $remote_fs $network $syslog $all
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage airtime-liquidsoap daemon
### END INIT INFO
USERID=www-data
GROUPID=www-data
NAME=airtime-liquidsoap
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
start () {
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
--make-pidfile --pidfile $PIDFILE --startas $DAEMON
}
stop () {
# Send TERM after 5 seconds, wait at most 30 seconds.
start-stop-daemon --stop --oknodo --retry TERM/5/0/30 --quiet --pidfile $PIDFILE
rm -f $PIDFILE
}
case "${1:-''}" in
'start')
# start commands here
echo -n "Starting $NAME: "
start
echo "Done."
;;
'stop')
# stop commands here
echo -n "Stopping $NAME: "
stop
echo "Done."
;;
'restart')
# restart commands here
echo -n "Restarting $NAME: "
stop
start
echo "Done."
;;
'force-reload')
# reload commands here
echo -n "Reloading $NAME: "
stop
start
echo "Done."
;;
'status')
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*) # no parameter specified
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac

View file

@ -9,16 +9,29 @@
# Short-Description: Manage airtime-playout daemon
### END INIT INFO
USERID=root
NAME="Airtime Scheduler"
USERID=www-data
GROUPID=www-data
NAME=airtime-playout
DAEMON=/usr/lib/airtime/pypo/bin/airtime-playout
PIDFILE=/var/run/airtime-playout.pid
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
start () {
mkdir -p /var/log/airtime/pypo
start-stop-daemon --start --background --quiet --chuid $USERID:$USERID \
start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID \
--make-pidfile --pidfile $PIDFILE --startas $DAEMON
}
@ -28,16 +41,6 @@ stop () {
rm -f $PIDFILE
}
start_with_monit() {
start
monit monitor airtime-playout >/dev/null 2>&1
}
stop_with_monit() {
monit unmonitor airtime-playout >/dev/null 2>&1
stop
}
case "${1:-''}" in
'start')
# start commands here
@ -58,26 +61,18 @@ case "${1:-''}" in
start
echo "Done."
;;
'start-with-monit')
# restart commands here
echo -n "Starting $NAME: "
start_with_monit
'force-reload')
# reload commands here
echo -n "Reloading $NAME: "
stop
start
echo "Done."
;;
'stop-with-monit')
# restart commands here
echo -n "Stopping $NAME: "
stop_with_monit
echo "Done."
;;
'status')
# status commands here
/usr/bin/airtime-check-system
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*) # no parameter specified
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac

View file

@ -0,0 +1,15 @@
description "Airtime Liquidsoap"
author "help@sourcefabric.org"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid WEB_USER
setgid WEB_USER
env LANG='en_US.UTF-8'
env LC_ALL='en_US.UTF-8'
exec airtime-liquidsoap

View file

@ -0,0 +1,15 @@
description "Pypo"
author "help@sourcefabric.org"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid WEB_USER
setgid WEB_USER
env LANG='en_US.UTF-8'
env LC_ALL='en_US.UTF-8'
exec airtime-playout

View file

@ -0,0 +1,27 @@
""" Runs Airtime liquidsoap
"""
import argparse
import os
import generate_liquidsoap_cfg
PYPO_HOME = '/var/tmp/airtime/pypo/'
def run():
'''Entry-point for this application'''
print "Airtime Liquidsoap"
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", help="run in debug mode", action="store_true")
args = parser.parse_args()
os.environ["HOME"] = PYPO_HOME
generate_liquidsoap_cfg.run()
script_path = os.path.join(os.path.dirname(__file__), 'ls_script.liq')
if args.debug:
os.execl('/usr/bin/liquidsoap', 'airtime-liquidsoap', script_path, '--verbose', '-f', '--debug')
else:
os.execl('/usr/bin/liquidsoap', 'airtime-liquidsoap', script_path, '--verbose', '-f')
run()

View file

@ -6,6 +6,6 @@
notifempty
sharedscripts
postrotate
start-stop-daemon --stop --signal USR1 --quiet --pidfile /var/run/airtime-liquidsoap.pid
start-stop-daemon --stop --signal USR1 --quiet --pidfile /var/run/airtime/airtime-liquidsoap.pid
endscript
}

View file

@ -30,27 +30,27 @@ def generate_liquidsoap_config(ss):
fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/<script>.log"\n')
fh.close()
logging.basicConfig(format='%(message)s')
attempts = 0
max_attempts = 10
successful = False
while not successful:
try:
ac = AirtimeApiClient(logging.getLogger())
ss = ac.get_stream_setting()
generate_liquidsoap_config(ss)
successful = True
except Exception, e:
if attempts == max_attempts:
def run():
logging.basicConfig(format='%(message)s')
attempts = 0
max_attempts = 10
successful = False
while not successful:
try:
ac = AirtimeApiClient(logging.getLogger())
ss = ac.get_stream_setting()
generate_liquidsoap_config(ss)
successful = True
except Exception, e:
print "Unable to connect to the Airtime server."
logging.error(str(e))
logging.error("traceback: %s", traceback.format_exc())
sys.exit(1)
else:
logging.error(str(e))
logging.error("traceback: %s", traceback.format_exc())
logging.info("Retrying in 3 seconds...")
time.sleep(3)
attempts += 1
if attempts == max_attempts:
logging.error("giving up and exiting...")
sys.exit(1)
else:
logging.info("Retrying in 3 seconds...")
time.sleep(3)
attempts += 1

View file

@ -3,9 +3,9 @@ import telnetlib
import sys
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
LS_HOST = config['ls_host']
LS_PORT = config['ls_port']
config = ConfigObj('/etc/airtime/airtime.conf')
LS_HOST = config['pypo']['ls_host']
LS_PORT = config['pypo']['ls_port']
tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write("master_harbor.stop\n")

View file

@ -1,5 +1,5 @@
def notify(m)
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --media-id=#{m['schedule_table_id']} &"
command = "timeout --signal=KILL 45 pyponotify --media-id=#{m['schedule_table_id']} &"
log(command)
system(command)
end
@ -15,7 +15,7 @@ def notify_stream(m)
#if a string has a single apostrophe in it, let's comment it out by ending the string before right before it
#escaping the apostrophe, and then starting a new string right after it. This is why we use 3 apostrophes.
json_str = string.replace(pattern="'",(fun (s) -> "'\''"), json_str)
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --webstream='#{json_str}' --media-id=#{!current_dyn_id} &"
command = "timeout --signal=KILL 45 pyponotify --webstream='#{json_str}' --media-id=#{!current_dyn_id} &"
if !current_dyn_id != "-1" then
log(command)
@ -93,14 +93,14 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
source = ref s
def on_error(msg)
connected := "false"
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} --time=#{!time} &"
command = "timeout --signal=KILL 45 pyponotify --error='#{msg}' --stream-id=#{stream} --time=#{!time} &"
system(command)
log(command)
5.
end
def on_connect()
connected := "true"
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream} --time=#{!time} &"
command = "timeout --signal=KILL 45 pyponotify --connect --stream-id=#{stream} --time=#{!time} &"
system(command)
log(command)
end

View file

@ -3,7 +3,7 @@
set("log.file.path", log_file)
set("server.telnet", true)
set("server.telnet.port", 1234)
set("init.daemon.pidfile.path", "/var/run/airtime-liquidsoap.pid")
set("init.daemon.pidfile.path", "/var/run/airtime/airtime-liquidsoap.pid")
%include "library/pervasives.liq"
@ -189,7 +189,7 @@ def make_scheduled_play_unavailable()
end
def update_source_status(sourcename, status) =
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --source-name=#{sourcename} --source-status=#{status} &"
command = "timeout --signal=KILL 45 pyponotify --source-name=#{sourcename} --source-status=#{status} &"
system(command)
log(command)
end
@ -419,6 +419,6 @@ if s4_enable == true then
end
command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --liquidsoap-started &"
command = "timeout --signal=KILL 45 pyponotify --liquidsoap-started &"
log(command)
system(command)

@ -1 +0,0 @@
Subproject commit 492242f4bb7367afebbf2f096067cb5a5d3c0449

View file

@ -1,14 +0,0 @@
#!/bin/bash
############################################
# just a wrapper to call the notifyer #
# needed here to keep dirs/configs clean #
# and maybe to set user-rights #
############################################
# Absolute path to this script
SCRIPT=`readlink -f $0`
# Absolute path this script is in
SCRIPTPATH=`dirname $SCRIPT`
cd ${SCRIPTPATH}/../
timeout --signal=KILL 45 python pyponotify.py "$@"

View file

@ -1,17 +0,0 @@
set daemon 15 # Poll at 5 second intervals
set logfile /var/log/monit.log
set httpd port 2812
check process airtime-liquidsoap matching "airtime-liquidsoap.*airtime.*ls_script"
if does not exist for 3 cycles then restart
start program = "/etc/init.d/airtime-liquidsoap start" with timeout 30 seconds
stop program = "/etc/init.d/airtime-liquidsoap stop"
if mem > 600 MB for 3 cycles then restart
if failed host localhost port 1234
send "version\r\nexit\r\n"
expect "Liquidsoap"
with timeout 2 seconds retry 3 for 2 cycles
then restart

View file

@ -1,9 +0,0 @@
set daemon 10 # Poll at 5 second intervals
set logfile /var/log/monit.log
set httpd port 2812
check process airtime-playout
with pidfile "/var/run/airtime-playout.pid"
start program = "/etc/init.d/airtime-playout start" with timeout 5 seconds
stop program = "/etc/init.d/airtime-playout stop"

View file

@ -1,8 +0,0 @@
set daemon 15 # Poll at 5 second intervals
set logfile /var/log/monit.log
set httpd port 2812
check process airtime-liquidsoap with pidfile "/var/run/airtime-liquidsoap.pid"
start program = "/etc/init.d/airtime-liquidsoap start" with timeout 5 seconds
stop program = "/etc/init.d/airtime-liquidsoap stop"

View file

@ -1,85 +0,0 @@
############################################
# pypo - configuration #
############################################
# Set the type of client you are using.
# Currently supported types:
# 1) "obp" = Open Broadcast Platform
# 2) "airtime"
#
api_client = "airtime"
############################################
# Cache Directories #
# *include* trailing slash !! #
############################################
cache_dir = '/var/tmp/airtime/pypo/cache/'
file_dir = '/var/tmp/airtime/pypo/files/'
tmp_dir = '/var/tmp/airtime/pypo/tmp/'
############################################
# Setup Directories #
# Do *not* include trailing slash !! #
############################################
cache_base_dir = '/var/tmp/airtime/pypo'
bin_dir = '/usr/lib/airtime/pypo'
log_base_dir = '/var/log/airtime'
pypo_log_dir = '/var/log/airtime/pypo'
liquidsoap_log_dir = '/var/log/airtime/pypo-liquidsoap'
############################################
# Liquidsoap settings #
############################################
ls_host = '127.0.0.1'
ls_port = '1234'
############################################
# RabbitMQ settings #
############################################
rabbitmq_host = 'localhost'
rabbitmq_user = 'guest'
rabbitmq_password = 'guest'
rabbitmq_vhost = '/'
############################################
# pypo preferences #
############################################
# Poll interval in seconds.
#
# This will rarely need to be changed because any schedule changes are
# automatically sent to pypo immediately.
#
# This is how often the poll script downloads new schedules and files from the
# server in the event that no changes are made to the schedule.
#
poll_interval = 3600 # in seconds.
# Push interval in seconds.
#
# This is how often the push script checks whether it has something new to
# push to liquidsoap.
#
# It's hard to imagine a situation where this should be more than 1 second.
#
push_interval = 1 # in seconds
# 'pre' or 'otf'. 'pre' cues while playlist preparation
# while 'otf' (on the fly) cues while loading into ls
# (needs the post_processor patch)
cue_style = 'pre'
############################################
# Recorded Audio settings #
############################################
record_bitrate = 256
record_samplerate = 44100
record_channels = 2
record_sample_size = 16
#can be either ogg|mp3, mp3 recording requires installation of the package "lame"
record_file_type = 'ogg'
# base path to store recordered shows at
base_recorded_files = '/var/tmp/airtime/show-recorder/'

View file

View file

@ -73,17 +73,24 @@ parser.add_option("-c",
LIQUIDSOAP_MIN_VERSION = "1.1.1"
PYPO_HOME='/var/tmp/airtime/pypo/'
#need to wait for Python 2.7 for this..
#logging.captureWarnings(True)
def configure_environment():
os.environ["HOME"] = PYPO_HOME
os.environ["TERM"] = 'xterm'
configure_environment()
# need to wait for Python 2.7 for this..
logging.captureWarnings(True)
# configure logging
try:
logging.config.fileConfig("logging.cfg")
logging.config.fileConfig("/etc/airtime/pypo_logging.cfg")
logger = logging.getLogger()
LogWriter.override_std_err(logger)
except Exception, e:
print "Couldn't configure logging"
print "Couldn't configure logging", e
sys.exit(1)
def configure_locale():
@ -134,7 +141,7 @@ configure_locale()
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
logger.error('Error loading config file: %s', e)
sys.exit(1)
@ -238,8 +245,8 @@ if __name__ == '__main__':
telnet_lock = Lock()
ls_host = config['ls_host']
ls_port = config['ls_port']
ls_host = config['pypo']['ls_host']
ls_port = config['pypo']['ls_port']
liquidsoap_startup_test()
@ -262,19 +269,20 @@ if __name__ == '__main__':
"""
media_q = Queue()
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config)
# Pass only the configuration sections needed; PypoMessageHandler only needs rabbitmq settings
pmh = PypoMessageHandler(pypoFetch_q, recorder_q, config['rabbitmq'])
pmh.daemon = True
pmh.start()
pfile = PypoFile(media_q, config)
pfile = PypoFile(media_q, config['pypo'])
pfile.daemon = True
pfile.start()
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config)
pf = PypoFetch(pypoFetch_q, pypoPush_q, media_q, telnet_lock, pypo_liquidsoap, config['pypo'])
pf.daemon = True
pf.start()
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config)
pp = PypoPush(pypoPush_q, telnet_lock, pypo_liquidsoap, config['pypo'])
pp.daemon = True
pp.start()

View file

View file

@ -23,7 +23,7 @@ from timeout import ls_timeout
# configure logging
logging_cfg = os.path.join(os.path.dirname(__file__), "logging.cfg")
logging_cfg = "/etc/airtime/pypo_logging.cfg"
logging.config.fileConfig(logging_cfg)
logger = logging.getLogger()
LogWriter.override_std_err(logger)

View file

@ -19,7 +19,8 @@ from std_err_override import LogWriter
CONFIG_PATH = '/etc/airtime/airtime.conf'
# configure logging
logging.config.fileConfig("logging.cfg")
logging_cfg = "/etc/airtime/pypo_logging.cfg"
logging.config.fileConfig(logging_cfg)
logger = logging.getLogger()
LogWriter.override_std_err(logger)

View file

@ -2,6 +2,7 @@
import logging
import traceback
import os
import sys
from threading import Thread
import time
@ -15,7 +16,8 @@ import json
from std_err_override import LogWriter
# configure logging
logging.config.fileConfig("logging.cfg")
logging_cfg = "/etc/airtime/pypo_logging.cfg"
logging.config.fileConfig(logging_cfg)
logger = logging.getLogger('message_h')
LogWriter.override_std_err(logger)
@ -36,10 +38,10 @@ class PypoMessageHandler(Thread):
try:
schedule_exchange = Exchange("airtime-pypo", "direct", durable=True, auto_delete=True)
schedule_queue = Queue("pypo-fetch", exchange=schedule_exchange, key="foo")
connection = BrokerConnection(self.config["rabbitmq_host"], \
self.config["rabbitmq_user"], \
self.config["rabbitmq_password"], \
self.config["rabbitmq_vhost"])
connection = BrokerConnection(self.config["host"], \
self.config["user"], \
self.config["password"], \
self.config["vhost"])
channel = connection.channel()
self.simple_queue = SimpleQueue(channel, schedule_queue)

View file

@ -26,7 +26,7 @@ from timeout import ls_timeout
# configure logging
logging_cfg = os.path.join(os.path.dirname(__file__), "logging.cfg")
logging_cfg = "/etc/airtime/pypo_logging.cfg"
logging.config.fileConfig(logging_cfg)
logger = logging.getLogger()
LogWriter.override_std_err(logger)

View file

@ -34,7 +34,7 @@ def api_client(logger):
# loading config file
try:
config = ConfigObj('/etc/airtime/pypo.cfg')
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
print ('Error loading config file: %s', e)
sys.exit()
@ -73,18 +73,18 @@ class ShowRecorder(Thread):
filename = self.start_time
filename = filename.replace(" ", "-")
if config["record_file_type"] in ["mp3", "ogg"]:
filetype = config["record_file_type"]
if config["pypo"]["record_file_type"] in ["mp3", "ogg"]:
filetype = config["pypo"]["record_file_type"]
else:
filetype = "ogg";
joined_path = os.path.join(config["base_recorded_files"], filename)
filepath = "%s.%s" % (joined_path, filetype)
br = config["record_bitrate"]
sr = config["record_samplerate"]
c = config["record_channels"]
ss = config["record_sample_size"]
br = config["pypo"]["record_bitrate"]
sr = config["pypo"]["record_samplerate"]
c = config["pypo"]["record_channels"]
ss = config["pypo"]["record_sample_size"]
#-f:16,2,44100
#-b:256

71
python_apps/pypo/setup.py Normal file
View file

@ -0,0 +1,71 @@
from setuptools import setup
from subprocess import call
import sys
import os
script_path = os.path.dirname(os.path.realpath(__file__))
print script_path
os.chdir(script_path)
# Allows us to avoid installing the upstart init script when deploying on Airtime Pro:
if '--no-init-script' in sys.argv:
data_files = []
sys.argv.remove('--no-init-script') # super hax
else:
pypo_files = []
for root, dirnames, filenames in os.walk('pypo'):
for filename in filenames:
pypo_files.append(os.path.join(root, filename))
data_files = [
('/etc/init', ['install/upstart/airtime-playout.conf.template']),
('/etc/init', ['install/upstart/airtime-liquidsoap.conf.template']),
('/etc/init.d', ['install/sysvinit/airtime-playout']),
('/etc/init.d', ['install/sysvinit/airtime-liquidsoap']),
('/etc/airtime', ['install/notify_logging.cfg']),
('/etc/airtime', ['install/pypo_logging.cfg']),
('/var/log/airtime/pypo', []),
('/var/log/airtime/pypo-liquidsoap', []),
('/var/tmp/airtime/pypo', []),
('/var/tmp/airtime/pypo/cache', []),
('/var/tmp/airtime/pypo/files', []),
('/var/tmp/airtime/pypo/tmp', []),
]
print data_files
setup(name='airtime-playout',
version='1.0',
description='Airtime Playout Engine',
url='http://github.com/sourcefabric/Airtime',
author='sourcefabric',
license='AGPLv3',
packages=['pypo', 'pypo.media', 'pypo.media.update',
'liquidsoap', 'liquidsoap.library'],
package_data={'': ['*.liq', '*.cfg']},
scripts=[
'bin/airtime-playout',
'bin/airtime-liquidsoap',
'bin/pyponotify'
],
install_requires=[
'amqplib',
'anyjson',
'argparse',
'configobj',
'docopt',
'kombu',
'mutagen',
'poster',
'PyDispatcher',
'pyinotify',
'pytz',
'wsgiref'
],
zip_safe=False,
data_files=data_files)
# Reload the initctl config so that playout services works
if data_files:
print "Reloading initctl configuration"
#call(['initctl', 'reload-configuration'])
print "Run \"sudo service airtime-playout start\" and \"sudo service airtime-liquidsoap start\""