From a6eb74b1fdc57c11e1dc7675f9ba118d96185218 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Tue, 26 Jun 2012 17:00:14 -0400 Subject: [PATCH] CC-4017: Run airtime-playour process as root user -Done --- python_apps/pypo/airtime-playout-init-d | 5 +-- python_apps/pypo/pypofile.py | 43 ++++++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/python_apps/pypo/airtime-playout-init-d b/python_apps/pypo/airtime-playout-init-d index 75ea3f6d7..0723a657d 100755 --- a/python_apps/pypo/airtime-playout-init-d +++ b/python_apps/pypo/airtime-playout-init-d @@ -10,6 +10,7 @@ ### END INIT INFO USERID=pypo +ROOTUSERID=root GROUPID=pypo NAME=Airtime\ Playout @@ -47,7 +48,7 @@ start () { chown pypo:pypo /etc/airtime chown pypo:pypo /etc/airtime/liquidsoap.cfg - start-stop-daemon --start --background --quiet --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0 + start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0 monit monitor airtime-playout >/dev/null 2>&1 liquidsoap_start @@ -80,7 +81,7 @@ monit_restart() { } start_no_monit() { - start-stop-daemon --start --background --quiet --chuid $USERID:$GROUPID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0 + start-stop-daemon --start --background --quiet --chuid $ROOTUSERID:$ROOTUSERID --make-pidfile --pidfile $PIDFILE0 --startas $DAEMON0 liquidsoap_start } diff --git a/python_apps/pypo/pypofile.py b/python_apps/pypo/pypofile.py index 7b948000c..eb19fbcd2 100644 --- a/python_apps/pypo/pypofile.py +++ b/python_apps/pypo/pypofile.py @@ -9,6 +9,7 @@ import logging.config import shutil import os import sys +import stat from std_err_override import LogWriter @@ -33,21 +34,21 @@ except Exception, e: class PypoFile(Thread): - + def __init__(self, schedule_queue): Thread.__init__(self) self.logger = logging.getLogger() self.media_queue = schedule_queue self.media = None self.cache_dir = os.path.join(config["cache_dir"], "scheduler") - + def copy_file(self, media_item): """ Copy media_item from local library directory to local cache directory. - """ + """ src = media_item['uri'] dst = media_item['dst'] - + try: src_size = os.path.getsize(src) except Exception, e: @@ -59,14 +60,14 @@ class PypoFile(Thread): dst_size = os.path.getsize(dst) except Exception, e: dst_exists = False - + do_copy = False if dst_exists: if src_size != dst_size: do_copy = True else: do_copy = True - + if do_copy: self.logger.debug("copying from %s to local cache %s" % (src, dst)) try: @@ -74,9 +75,13 @@ class PypoFile(Thread): copy will overwrite dst if it already exists """ shutil.copy(src, dst) - except: + + #make file world readable + os.chmod(dst, stat.S_IRUSR | stat.S_IRGRP | stat.S_IXOTH) + except Exception, e: self.logger.error("Could not copy from %s to %s" % (src, dst)) - + self.logger.error(e) + def get_highest_priority_media_item(self, schedule): """ Get highest priority media_item in the queue. Currently the highest @@ -84,17 +89,17 @@ class PypoFile(Thread): """ if schedule is None or len(schedule) == 0: return None - + sorted_keys = sorted(schedule.keys()) - + if len(sorted_keys) == 0: return None - + highest_priority = sorted_keys[0] media_item = schedule[highest_priority] - + self.logger.debug("Highest priority item: %s" % highest_priority) - + """ Remove this media_item from the dictionary. On the next iteration (from the main function) we won't consider it for prioritization @@ -103,11 +108,11 @@ class PypoFile(Thread): again. In this situation, the worst possible case is that we try to copy the file again and realize we already have it (thus aborting the copy). """ - del schedule[highest_priority] - + del schedule[highest_priority] + return media_item - - + + def main(self): while True: try: @@ -128,7 +133,7 @@ class PypoFile(Thread): self.media = self.media_queue.get_nowait() except Empty, e: pass - + media_item = self.get_highest_priority_media_item(self.media) if media_item is not None: @@ -139,7 +144,7 @@ class PypoFile(Thread): self.logger.error(str(e)) self.logger.error(top) raise - + def run(self): """ Entry point of the thread