CC-4017: Run airtime-playour process as root user

-Done
This commit is contained in:
Martin Konecny 2012-06-26 17:00:14 -04:00
parent 7e7f8147da
commit a6eb74b1fd
2 changed files with 27 additions and 21 deletions

View File

@ -10,6 +10,7 @@
### END INIT INFO ### END INIT INFO
USERID=pypo USERID=pypo
ROOTUSERID=root
GROUPID=pypo GROUPID=pypo
NAME=Airtime\ Playout NAME=Airtime\ Playout
@ -47,7 +48,7 @@ start () {
chown pypo:pypo /etc/airtime chown pypo:pypo /etc/airtime
chown pypo:pypo /etc/airtime/liquidsoap.cfg 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 monit monitor airtime-playout >/dev/null 2>&1
liquidsoap_start liquidsoap_start
@ -80,7 +81,7 @@ monit_restart() {
} }
start_no_monit() { 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 liquidsoap_start
} }

View File

@ -9,6 +9,7 @@ import logging.config
import shutil import shutil
import os import os
import sys import sys
import stat
from std_err_override import LogWriter from std_err_override import LogWriter
@ -33,21 +34,21 @@ except Exception, e:
class PypoFile(Thread): class PypoFile(Thread):
def __init__(self, schedule_queue): def __init__(self, schedule_queue):
Thread.__init__(self) Thread.__init__(self)
self.logger = logging.getLogger() self.logger = logging.getLogger()
self.media_queue = schedule_queue self.media_queue = schedule_queue
self.media = None self.media = None
self.cache_dir = os.path.join(config["cache_dir"], "scheduler") self.cache_dir = os.path.join(config["cache_dir"], "scheduler")
def copy_file(self, media_item): def copy_file(self, media_item):
""" """
Copy media_item from local library directory to local cache directory. Copy media_item from local library directory to local cache directory.
""" """
src = media_item['uri'] src = media_item['uri']
dst = media_item['dst'] dst = media_item['dst']
try: try:
src_size = os.path.getsize(src) src_size = os.path.getsize(src)
except Exception, e: except Exception, e:
@ -59,14 +60,14 @@ class PypoFile(Thread):
dst_size = os.path.getsize(dst) dst_size = os.path.getsize(dst)
except Exception, e: except Exception, e:
dst_exists = False dst_exists = False
do_copy = False do_copy = False
if dst_exists: if dst_exists:
if src_size != dst_size: if src_size != dst_size:
do_copy = True do_copy = True
else: else:
do_copy = True do_copy = True
if do_copy: if do_copy:
self.logger.debug("copying from %s to local cache %s" % (src, dst)) self.logger.debug("copying from %s to local cache %s" % (src, dst))
try: try:
@ -74,9 +75,13 @@ class PypoFile(Thread):
copy will overwrite dst if it already exists copy will overwrite dst if it already exists
""" """
shutil.copy(src, dst) 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("Could not copy from %s to %s" % (src, dst))
self.logger.error(e)
def get_highest_priority_media_item(self, schedule): def get_highest_priority_media_item(self, schedule):
""" """
Get highest priority media_item in the queue. Currently the highest 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: if schedule is None or len(schedule) == 0:
return None return None
sorted_keys = sorted(schedule.keys()) sorted_keys = sorted(schedule.keys())
if len(sorted_keys) == 0: if len(sorted_keys) == 0:
return None return None
highest_priority = sorted_keys[0] highest_priority = sorted_keys[0]
media_item = schedule[highest_priority] media_item = schedule[highest_priority]
self.logger.debug("Highest priority item: %s" % highest_priority) self.logger.debug("Highest priority item: %s" % highest_priority)
""" """
Remove this media_item from the dictionary. On the next iteration Remove this media_item from the dictionary. On the next iteration
(from the main function) we won't consider it for prioritization (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 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). 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 return media_item
def main(self): def main(self):
while True: while True:
try: try:
@ -128,7 +133,7 @@ class PypoFile(Thread):
self.media = self.media_queue.get_nowait() self.media = self.media_queue.get_nowait()
except Empty, e: except Empty, e:
pass pass
media_item = self.get_highest_priority_media_item(self.media) media_item = self.get_highest_priority_media_item(self.media)
if media_item is not None: if media_item is not None:
@ -139,7 +144,7 @@ class PypoFile(Thread):
self.logger.error(str(e)) self.logger.error(str(e))
self.logger.error(top) self.logger.error(top)
raise raise
def run(self): def run(self):
""" """
Entry point of the thread Entry point of the thread