CC-4040: Pypo can start before Liquidsoap

-fixed
This commit is contained in:
Martin Konecny 2012-06-28 16:15:39 -04:00
parent a322e4678e
commit 226b6e8709
1 changed files with 41 additions and 14 deletions

View File

@ -5,6 +5,8 @@ Python part of radio playout (pypo)
from optparse import OptionParser from optparse import OptionParser
from datetime import datetime from datetime import datetime
import telnetlib
import time import time
import sys import sys
import signal import signal
@ -50,6 +52,15 @@ parser.add_option("-c", "--check", help="Check the cached schedule and exit", de
#need to wait for Python 2.7 for this.. #need to wait for Python 2.7 for this..
#logging.captureWarnings(True) #logging.captureWarnings(True)
# configure logging
try:
logging.config.fileConfig("logging.cfg")
logger = logging.getLogger()
LogWriter.override_std_err(logger)
except Exception, e:
print "Couldn't configure logging"
sys.exit()
def configure_locale(): def configure_locale():
logger.debug("Before %s", locale.nl_langinfo(locale.CODESET)) logger.debug("Before %s", locale.nl_langinfo(locale.CODESET))
current_locale = locale.getlocale() current_locale = locale.getlocale()
@ -61,8 +72,8 @@ def configure_locale():
if default_locale[1] is None: if default_locale[1] is None:
logger.debug("No default locale exists. Let's try loading from /etc/default/locale") logger.debug("No default locale exists. Let's try loading from /etc/default/locale")
if os.path.exists("/etc/default/locale"): if os.path.exists("/etc/default/locale"):
config = ConfigObj('/etc/default/locale') locale_config = ConfigObj('/etc/default/locale')
lang = config.get('LANG') lang = locale_config.get('LANG')
new_locale = lang new_locale = lang
else: else:
logger.error("/etc/default/locale could not be found! Please run 'sudo update-locale' from command-line.") logger.error("/etc/default/locale could not be found! Please run 'sudo update-locale' from command-line.")
@ -84,14 +95,6 @@ def configure_locale():
logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding) logger.error("Need a UTF-8 locale. Currently '%s'. Exiting..." % current_locale_encoding)
sys.exit(1) sys.exit(1)
# configure logging
try:
logging.config.fileConfig("logging.cfg")
logger = logging.getLogger()
LogWriter.override_std_err(logger)
except Exception, e:
print "Couldn't configure logging"
sys.exit()
configure_locale() configure_locale()
@ -118,9 +121,26 @@ def keyboardInterruptHandler(signum, frame):
logger.info('\nKeyboard Interrupt\n') logger.info('\nKeyboard Interrupt\n')
sys.exit(0) sys.exit(0)
def liquidsoap_running_test(telnet_lock, host, port, logger):
logger.debug("Checking to see if Liquidsoap is running")
success = True
try:
telnet_lock.acquire()
tn = telnetlib.Telnet(host, port)
msg = "version\n"
tn.write(msg)
tn.write("exit\n")
logger.info("Liquidsoap version %s", tn.read_all())
except Exception, e:
logger.error(str(e))
success = False
finally:
telnet_lock.release()
return success
if __name__ == '__main__': if __name__ == '__main__':
logger = logging.getLogger()
logger.info('###########################################') logger.info('###########################################')
logger.info('# *** pypo *** #') logger.info('# *** pypo *** #')
logger.info('# Liquidsoap Scheduled Playout System #') logger.info('# Liquidsoap Scheduled Playout System #')
@ -137,9 +157,16 @@ if __name__ == '__main__':
# initialize # initialize
g = Global() g = Global()
while not g.selfcheck(): time.sleep(5) while not g.selfcheck():
time.sleep(5)
logger = logging.getLogger() telnet_lock = Lock()
ls_host = config['ls_host']
ls_port = config['ls_port']
while not liquidsoap_running_test(telnet_lock, ls_host, ls_port, logger):
logger.warning("Liquidsoap not started yet. Sleeping one second and trying again")
time.sleep(1)
if options.test: if options.test:
g.test_api() g.test_api()
@ -152,7 +179,7 @@ if __name__ == '__main__':
recorder_q = Queue() recorder_q = Queue()
pypoPush_q = Queue() pypoPush_q = Queue()
telnet_lock = Lock()
""" """
This queue is shared between pypo-fetch and pypo-file, where pypo-file This queue is shared between pypo-fetch and pypo-file, where pypo-file