Merge branch 'liquidsoap-on-error-callback' into devel
This commit is contained in:
commit
6751b290d9
|
@ -23,6 +23,8 @@ class ApiController extends Zend_Controller_Action
|
|||
->addActionContext('get-stream-setting', 'json')
|
||||
->addActionContext('status', 'json')
|
||||
->addActionContext('register-component', 'json')
|
||||
->addActionContext('update-liquidsoap-error', 'json')
|
||||
->addActionContext('update-liquidsoap-connection', 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
||||
|
@ -696,5 +698,21 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
Application_Model_ServiceRegister::Register($component, $remoteAddr);
|
||||
}
|
||||
|
||||
public function updateLiquidsoapErrorAction(){
|
||||
$request = $this->getRequest();
|
||||
|
||||
$error_msg = $request->getParam('error_msg');
|
||||
$stream_id = $request->getParam('stream_id');
|
||||
Application_Model_StreamSetting::setLiquidsoapError($stream_id, $error_msg);
|
||||
}
|
||||
|
||||
public function updateLiquidsoapConnectionAction(){
|
||||
$request = $this->getRequest();
|
||||
|
||||
$stream_id = $request->getParam('stream_id');
|
||||
// setting error_msg as "" when there is no error_msg
|
||||
Application_Model_StreamSetting::setLiquidsoapError($stream_id, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,8 @@ class Application_Model_StreamSetting {
|
|||
public static function getStreamSetting(){
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT *"
|
||||
." FROM cc_stream_setting";
|
||||
." FROM cc_stream_setting"
|
||||
." WHERE keyname not like '%_error'";
|
||||
|
||||
$rows = $CC_DBC->getAll($sql);
|
||||
return $rows;
|
||||
|
@ -74,4 +75,33 @@ class Application_Model_StreamSetting {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function setLiquidsoapError($stream_id, $msg){
|
||||
global $CC_DBC;
|
||||
|
||||
$keyname = "s".$stream_id."_liquidsoap_error";
|
||||
$sql = "SELECT COUNT(*) FROM cc_stream_setting"
|
||||
." WHERE keyname = '$keyname'";
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
|
||||
if ($result == 1){
|
||||
$sql = "UPDATE cc_stream_setting"
|
||||
." SET value = '$value'"
|
||||
." WHERE keyname = '$keyname'";
|
||||
}else{
|
||||
$sql = "INSERT INTO cc_stream_setting (keyname, value, type)"
|
||||
." VALUES ($keyname, '$msg', 'string')";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLiquidsoapError($stream_id){
|
||||
global $CC_DBC;
|
||||
|
||||
$keyname = "s".$stream_id."_liquidsoap_error";
|
||||
$sql = "SELECT value FROM cc_stream_setting"
|
||||
." WHERE keyname = '$key'";
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,18 +10,12 @@ from fabric.contrib.files import comment, sed, append
|
|||
# Globals
|
||||
|
||||
env.user = 'martin'
|
||||
env.hosts = ['192.168.5.36']
|
||||
env.hosts = []
|
||||
env.host_string
|
||||
|
||||
"""
|
||||
Main dispatcher function to be called from the command-line. Allows us to specify source and target version of Airtime,
|
||||
to test upgrade scripts, along with whether we should load a fresh version of the OS (from a VM snapshot), the OS version
|
||||
and architecture.
|
||||
"""
|
||||
def dispatcher(source_version="182", target_version="194", fresh_os=True, os_version='10.04', os_arch='amd64'):
|
||||
if (fresh_os):
|
||||
create_fresh_os(os_version, os_arch)
|
||||
globals()["airtime_%s"%source_version]()
|
||||
globals()["airtime_%s"%target_version]()
|
||||
env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox"
|
||||
|
||||
#fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar
|
||||
|
||||
|
||||
def test():
|
||||
|
@ -29,19 +23,67 @@ def test():
|
|||
print x.failed
|
||||
print x.succeeded
|
||||
print x.return_code
|
||||
|
||||
def download_if_needed(vdi_tmp_dir, xml_tmp_dir, vm_name, vm_vdi_file, vm_xml_file):
|
||||
if not os.path.exists(vdi_tmp_dir):
|
||||
os.makedirs(vdi_tmp_dir)
|
||||
|
||||
if os.path.exists(os.path.join(vdi_tmp_dir, vm_vdi_file)):
|
||||
print "File %s already exists. No need to re-download" % os.path.join(vdi_tmp_dir, vm_vdi_file)
|
||||
else:
|
||||
print "File %s not found. Downloading" % vm_vdi_file
|
||||
local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, os.path.join(vdi_tmp_dir, vm_vdi_file)))
|
||||
|
||||
if os.path.exists(os.path.join(xml_tmp_dir, vm_xml_file)):
|
||||
print "File %s already exists. No need to re-download" % os.path.join(xml_tmp_dir, vm_xml_file)
|
||||
else:
|
||||
print "File %s not found. Downloading" % vm_xml_file
|
||||
local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_tmp_dir, vm_xml_file)))
|
||||
|
||||
def create_fresh_os(os_version, os_arch):
|
||||
ret = local('VBoxManage snapshot ubuntu_64_server restore Fresh', capture=True)
|
||||
if (ret.failed):
|
||||
print ret
|
||||
print "Restoring snapshot failed, are you sure it's not already running?"
|
||||
|
||||
vdi_tmp_dir = os.path.expanduser('~/tmp/vms/')
|
||||
xml_tmp_dir = os.path.expanduser('~/.VirtualBox')
|
||||
vm_name = 'Ubuntu_%s_%s'%(os_version, os_arch)
|
||||
vm_vdi_file = 'Ubuntu_%s_%s.vdi'%(os_version, os_arch)
|
||||
vm_xml_file = 'Ubuntu_%s_%s.xml'%(os_version, os_arch)
|
||||
|
||||
downloaded = download_if_needed(vdi_tmp_dir, xml_tmp_dir, vm_name, vm_vdi_file, vm_xml_file)
|
||||
|
||||
ret = local('VBoxManage startvm ubuntu_64_server', capture=True)
|
||||
if (ret.failed):
|
||||
print ret
|
||||
print "Starting Virtual Machine failed, are you sure it's not already running?"
|
||||
local("VBoxManage registervm %s"%os.path.join(xml_tmp_dir, vm_xml_file))
|
||||
local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)
|
||||
local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_tmp_dir, vm_vdi_file)))
|
||||
|
||||
#if downloaded:
|
||||
local('VBoxManage snapshot "%s" take "fresh_install_test2"'%vm_name)
|
||||
#else:
|
||||
# local('VBoxManage snapshot %s restore fresh_install'%vm_name)
|
||||
|
||||
time.sleep(15)
|
||||
local('VBoxManage startvm %s'%vm_name)
|
||||
|
||||
time.sleep(20)
|
||||
|
||||
ret = local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name)
|
||||
|
||||
triple = ret.partition(':')
|
||||
ip_addr = triple[2].strip(' \r\n')
|
||||
print "Address found %s"%ip_addr
|
||||
env.hosts.append(ip_addr)
|
||||
env.host_string = ip_addr
|
||||
|
||||
|
||||
def ubuntu_lucid_32(fresh_os=True):
|
||||
if (fresh_os):
|
||||
create_fresh_os('10.04', '32')
|
||||
|
||||
def ubuntu_lucid_64(fresh_os=True):
|
||||
pass
|
||||
|
||||
def ubuntu_natty_32(fresh_os=True):
|
||||
pass
|
||||
|
||||
def ubuntu_natty_64(fresh_os=True):
|
||||
pass
|
||||
|
||||
def airtime_182():
|
||||
sudo('apt-get update')
|
||||
|
@ -57,12 +99,12 @@ def airtime_182():
|
|||
|
||||
sudo('mkdir -p /tmp/pear/cache')
|
||||
sudo('pear channel-discover pear.phing.info || true')
|
||||
sudo('pear install phing/phing-2.4.2')
|
||||
sudo('pear install phing/phing-2.4.2 || true')
|
||||
|
||||
sudo('ln -sf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled')
|
||||
sudo('ln -sf /etc/apache2/mods-available/rewrite.* /etc/apache2/mods-enabled')
|
||||
|
||||
sed('/etc/php5/apache2/php.ini', ";upload_tmp_dir =", "upload_tmp_dir = /tmp", use_sudo=True)
|
||||
sed('/etc/php5/apache2/php.ini', ";upload_vdi_tmp_dir =", "upload_vdi_tmp_dir = /tmp", use_sudo=True)
|
||||
sed('/etc/php5/apache2/php.ini', ";date.timezone =", 'date.timezone = "America/Toronto"', use_sudo=True)
|
||||
|
||||
put('airtime.vhost', '/etc/apache2/sites-available/airtime', use_sudo=True)
|
||||
|
|
|
@ -27,7 +27,7 @@ apt-get -y install tar gzip curl apache2 php5-pgsql libapache2-mod-php5 \
|
|||
php-pear php5-gd postgresql odbc-postgresql python2.6 lame libsoundtouch-ocaml \
|
||||
libmp3lame-dev libtaglib-ocaml libao-ocaml libmad-ocaml ecasound \
|
||||
libesd0 icecast2 libportaudio2 libsamplerate0 rabbitmq-server patch \
|
||||
php5-curl mpg123 monit python-virtualenv multitail
|
||||
php5-curl mpg123 monit python-virtualenv multitail libcamomile-ocaml-data
|
||||
|
||||
#possibly remove?
|
||||
#libvorbis-ocaml-dev
|
||||
|
|
|
@ -92,6 +92,12 @@ generate_range_url = 'generate_range_dp.php'
|
|||
# URL to tell Airtime we want to get stream setting
|
||||
get_stream_setting = 'get-stream-setting/format/json/api_key/%%api_key%%/'
|
||||
|
||||
#URL to update liquidsoap error msg
|
||||
update_liquidsoap_error = 'update-liquidsoap-error/format/json/api_key/%%api_key%%/error_msg/%%error_msg%%/stream_id/%%stream_id%%'
|
||||
|
||||
#URL to update liquidsoap connection
|
||||
update_liquidsoap_connection = 'update-liquidsoap-connection/format/json/api_key/%%api_key%%/stream_id/%%stream_id%%'
|
||||
|
||||
##############
|
||||
# OBP config #
|
||||
##############
|
||||
|
|
|
@ -140,6 +140,12 @@ class ApiClientInterface:
|
|||
def register_component(self):
|
||||
pass
|
||||
|
||||
def notify_liquidsoap_error(self, error_msg, stream_id):
|
||||
pass
|
||||
|
||||
def notify_liquidsoap_connection(self, stream_id):
|
||||
pass
|
||||
|
||||
# Put here whatever tests you want to run to make sure your API is working
|
||||
def test(self):
|
||||
pass
|
||||
|
@ -564,7 +570,34 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
response = urllib2.urlopen(req).read()
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
|
||||
def notify_liquidsoap_error(self, error_msg, stream_id):
|
||||
logger = logging.getLogger()
|
||||
try:
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_error"])
|
||||
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
url = url.replace("%%error_msg%%", error_msg)
|
||||
url = url.replace("%%stream_id%%", stream_id)
|
||||
logger.debug(url)
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
def notify_liquidsoap_connection(self, stream_id):
|
||||
logger = logging.getLogger()
|
||||
try:
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_liquidsoap_connection"])
|
||||
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
url = url.replace("%%stream_id%%", stream_id)
|
||||
logger.debug(url)
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
################################################################################
|
||||
# OpenBroadcast API Client
|
||||
################################################################################
|
||||
|
|
|
@ -46,7 +46,7 @@ def is_natty():
|
|||
split = line.split("=")
|
||||
split[0] = split[0].strip(" \r\n")
|
||||
split[1] = split[1].strip(" \r\n")
|
||||
if split[0] == "DISTRIB_CODENAME" and split[1] == "natty":
|
||||
if split[0] == "DISTRIB_CODENAME" and (split[1] == "natty" or split[1] == "oneiric"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
@ -37,7 +37,17 @@ def to_live(old,new) =
|
|||
end
|
||||
|
||||
|
||||
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s) =
|
||||
def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, user, s, stream) =
|
||||
def on_error(msg)
|
||||
system("airtime-check-system > ~/temp/temp1.log 2>&1")
|
||||
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream} > ~/temp/temp.log 2>&1")
|
||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --error='#{msg}' --stream-id=#{stream}")
|
||||
5.
|
||||
end
|
||||
def on_connect()
|
||||
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
|
||||
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --connect --stream-id=#{stream}")
|
||||
end
|
||||
if output_type == "icecast" then
|
||||
user_ref = ref user
|
||||
if user == "" then
|
||||
|
@ -52,7 +62,9 @@ def output_to(output_type, type, bitrate, host, port, pass, mount_point, url, de
|
|||
url = url,
|
||||
description = description,
|
||||
genre = genre,
|
||||
user = !user_ref)
|
||||
user = !user_ref,
|
||||
on_error = on_error,
|
||||
on_connect = on_connect)
|
||||
if type == "mp3" then
|
||||
if bitrate == 24 then
|
||||
ignore(output(%mp3(bitrate = 24),s))
|
||||
|
|
|
@ -56,17 +56,18 @@ end
|
|||
|
||||
if s1_output != "disabled" then
|
||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
||||
output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s)
|
||||
output_to(s1_output, s1_type, s1_bitrate, s1_host, s1_port, s1_pass, s1_mount, s1_url, s1_description, s1_genre, s1_user, s, "1")
|
||||
end
|
||||
|
||||
if s2_output != "disabled" then
|
||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
||||
output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s)
|
||||
output_to(s2_output, s2_type, s2_bitrate, s2_host, s2_port, s2_pass, s2_mount, s2_url, s2_description, s2_genre, s2_user, s, "2")
|
||||
|
||||
end
|
||||
|
||||
if s3_output != "disabled" then
|
||||
#output_to(output_type, type, bitrate, host, port, pass, mount_point, url, description, genre, s)
|
||||
output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s)
|
||||
output_to(s3_output, s3_type, s3_bitrate, s3_host, s3_port, s3_pass, s3_mount, s3_url, s3_description, s3_genre, s3_user, s, "3")
|
||||
end
|
||||
|
||||
ignore(output.dummy(blank()))
|
||||
|
|
|
@ -47,6 +47,9 @@ parser = OptionParser(usage=usage)
|
|||
# Options
|
||||
parser.add_option("-d", "--data", help="Pass JSON data from liquidsoap into this script.", metavar="data")
|
||||
parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id")
|
||||
parser.add_option("-e", "--error", help="liquidsoap error msg.", metavar="error_msg")
|
||||
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id")
|
||||
parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
@ -76,8 +79,26 @@ class Notify:
|
|||
logger.debug('data = '+ str(data))
|
||||
response = self.api_client.notify_media_item_start_playing(data, media_id)
|
||||
logger.debug("Response: "+json.dumps(response))
|
||||
|
||||
|
||||
|
||||
def notify_liquidsoap_error(self, error_msg, stream_id):
|
||||
logger = logging.getLogger()
|
||||
|
||||
logger.debug('#################################################')
|
||||
logger.debug('# Calling server to update liquidsoap error #')
|
||||
logger.debug('#################################################')
|
||||
logger.debug('error msg = '+ str(error_msg))
|
||||
response = self.api_client.notify_liquidsoap_error(error_msg, stream_id)
|
||||
logger.debug("Response: "+json.dumps(response))
|
||||
|
||||
def notify_liquidsoap_connection(self, stream_id):
|
||||
logger = logging.getLogger()
|
||||
|
||||
logger.debug('#################################################')
|
||||
logger.debug('# Calling server to update liquidsoap connection#')
|
||||
logger.debug('#################################################')
|
||||
response = self.api_client.notify_liquidsoap_connection(stream_id)
|
||||
logger.debug("Response: "+json.dumps(response))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print
|
||||
print '#########################################'
|
||||
|
@ -87,17 +108,30 @@ if __name__ == '__main__':
|
|||
|
||||
# initialize
|
||||
logger = logging.getLogger()
|
||||
|
||||
if not options.data:
|
||||
print "NOTICE: 'data' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
if not options.media_id:
|
||||
print "NOTICE: 'media_id' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
n = Notify()
|
||||
n.notify_media_start_playing(options.data, options.media_id)
|
||||
except Exception, e:
|
||||
print e
|
||||
if options.error_msg and options.stream_id:
|
||||
try:
|
||||
n = Notify()
|
||||
n.notify_liquidsoap_error(options.error_msg, options.stream_id)
|
||||
except Exception, e:
|
||||
print e
|
||||
elif optioins.connect and options.stream_id:
|
||||
try:
|
||||
n = Notify()
|
||||
n.notify_liquidsoap_connection(options.stream_id)
|
||||
except Exception, e:
|
||||
print e
|
||||
else:
|
||||
if not options.data:
|
||||
print "NOTICE: 'data' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
if not options.media_id:
|
||||
print "NOTICE: 'media_id' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
n = Notify()
|
||||
n.notify_media_start_playing(options.data, options.media_id)
|
||||
except Exception, e:
|
||||
print e
|
||||
|
|
Loading…
Reference in New Issue