cc-2055: switch to init.d
-allow install script to be created from any location (no hardcoded paths) -make python install scripts return 1 on error -daemon now started automatically on boot using rc.local autostart -change all prints to logs instead -create airtime-uninstall shell script (and remove pypo user in here) -create pypo user in shell script
This commit is contained in:
parent
079d9d36b0
commit
6ab5ac4582
23 changed files with 179 additions and 224 deletions
|
@ -14,7 +14,7 @@ import shutil
|
|||
import string
|
||||
import platform
|
||||
from configobj import ConfigObj
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
from subprocess import Popen
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
|
@ -29,27 +29,6 @@ def create_path(path):
|
|||
else:
|
||||
print "Directory already exists " + path
|
||||
|
||||
def create_user(username):
|
||||
print "Checking for user "+username
|
||||
p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
output = p.stdout.read()
|
||||
if (output[0:3] != "uid"):
|
||||
# Make the pypo user
|
||||
print "Creating user "+username
|
||||
os.system("adduser --system --quiet --group --shell /bin/bash "+username)
|
||||
|
||||
#set pypo password
|
||||
p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w')
|
||||
p.write('pypo\n')
|
||||
p.write('pypo\n')
|
||||
p.close()
|
||||
else:
|
||||
print "User already exists."
|
||||
#add pypo to audio group
|
||||
os.system("adduser " + username + " audio 1>/dev/null 2>&1")
|
||||
#add pypo to pulse-access group
|
||||
#os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1")
|
||||
|
||||
def copy_dir(src_dir, dest_dir):
|
||||
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
|
||||
#print "Removing old directory "+dest_dir
|
||||
|
@ -61,7 +40,6 @@ def copy_dir(src_dir, dest_dir):
|
|||
def get_current_script_dir():
|
||||
current_script_dir = os.path.realpath(__file__)
|
||||
index = current_script_dir.rindex('/')
|
||||
#print current_script_dir[0:index]
|
||||
return current_script_dir[0:index]
|
||||
|
||||
def is_natty():
|
||||
|
@ -86,18 +64,13 @@ try:
|
|||
config = ConfigObj(PATH_INI_FILE)
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit()
|
||||
sys.exit(1)
|
||||
|
||||
current_script_dir = get_current_script_dir()
|
||||
#print "Checking and removing any existing pypo processes"
|
||||
#os.system("python %s/pypo-uninstall.py 1>/dev/null 2>&1"% current_script_dir)
|
||||
#time.sleep(5)
|
||||
|
||||
p = Popen("/etc/init.d/airtime-playout stop", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
|
||||
# Create users
|
||||
create_user("pypo")
|
||||
|
||||
create_path(config["pypo_log_dir"])
|
||||
os.system("chmod -R 755 " + config["pypo_log_dir"])
|
||||
os.system("chown -R pypo:pypo "+config["pypo_log_dir"])
|
||||
|
@ -148,9 +121,13 @@ try:
|
|||
print "Installing pypo daemon"
|
||||
shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout")
|
||||
|
||||
p = Popen("update-rc.d airtime-playout defaults", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
|
||||
print "Waiting for processes to start..."
|
||||
p = Popen("/etc/init.d/airtime-playout start", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
|
||||
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
||||
|
|
|
@ -15,15 +15,6 @@ PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
|||
def remove_path(path):
|
||||
os.system("rm -rf " + path)
|
||||
|
||||
def remove_user(username):
|
||||
os.system("killall -u %s 1>/dev/null 2>&1" % username)
|
||||
|
||||
#allow all process to be completely closed before we attempt to delete user
|
||||
print "Waiting for processes to close..."
|
||||
time.sleep(5)
|
||||
|
||||
os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1")
|
||||
|
||||
def get_current_script_dir():
|
||||
current_script_dir = os.path.realpath(__file__)
|
||||
index = current_script_dir.rindex('/')
|
||||
|
@ -35,9 +26,10 @@ try:
|
|||
config = ConfigObj(PATH_INI_FILE)
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit()
|
||||
sys.exit(1)
|
||||
|
||||
os.system("/etc/init.d/airtime-playout stop")
|
||||
os.system("rm -f /etc/init.d/airtime-playout")
|
||||
|
||||
print "Removing cache directories"
|
||||
remove_path(config["cache_base_dir"])
|
||||
|
@ -48,7 +40,6 @@ try:
|
|||
print "Removing pypo files"
|
||||
remove_path(config["bin_dir"])
|
||||
|
||||
remove_user("pypo")
|
||||
print "Pypo uninstall complete."
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
||||
|
|
|
@ -49,7 +49,8 @@ logging.config.fileConfig("logging.cfg")
|
|||
try:
|
||||
config = ConfigObj('/etc/airtime/pypo.cfg')
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
logger = logging.getLogger()
|
||||
logger.error('Error loading config file: %s', e)
|
||||
sys.exit()
|
||||
|
||||
class Global:
|
||||
|
@ -71,6 +72,7 @@ class Global:
|
|||
def test_api(self):
|
||||
self.api_client.test()
|
||||
|
||||
"""
|
||||
def check_schedule(self, export_source):
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
@ -97,17 +99,20 @@ class Global:
|
|||
|
||||
for media in playlist['medias']:
|
||||
print media
|
||||
"""
|
||||
|
||||
def keyboardInterruptHandler(signum, frame):
|
||||
print "\nKeyboard Interrupt\n"
|
||||
sys.exit();
|
||||
logger = logging.getLogger()
|
||||
logger.info('\nKeyboard Interrupt\n')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print '###########################################'
|
||||
print '# *** pypo *** #'
|
||||
print '# Liquidsoap Scheduled Playout System #'
|
||||
print '###########################################'
|
||||
logger = logging.getLogger()
|
||||
logger.info('###########################################')
|
||||
logger.info('# *** pypo *** #')
|
||||
logger.info('# Liquidsoap Scheduled Playout System #')
|
||||
logger.info('###########################################')
|
||||
|
||||
signal.signal(signal.SIGINT, keyboardInterruptHandler)
|
||||
|
||||
|
@ -120,10 +125,7 @@ if __name__ == '__main__':
|
|||
# initialize
|
||||
g = Global()
|
||||
|
||||
#NOTE: MUST EXIT HERE!! while not g.selfcheck(): time.sleep()
|
||||
#Causes pypo to hang on system boot!!!
|
||||
if not g.selfcheck():
|
||||
sys.exit()
|
||||
while not g.selfcheck(): time.sleep(5)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ try:
|
|||
POLL_INTERVAL = int(config['poll_interval'])
|
||||
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
logger = logging.getLogger()
|
||||
logger.error('Error loading config file: %s', e)
|
||||
sys.exit()
|
||||
|
||||
# Yuk - using a global, i know!
|
||||
|
@ -242,8 +243,7 @@ class PypoFetch(Thread):
|
|||
|
||||
#logger.debug("everything ok, adding %s to playlist", pl_entry)
|
||||
else:
|
||||
print 'zero-file: ' + dst + ' from ' + media['uri']
|
||||
logger.warning("zero-size file - skipping %s. will not add it to playlist", dst)
|
||||
logger.warning("zero-size file - skipping %s. will not add it to playlist at %s", media['uri'], dst)
|
||||
|
||||
else:
|
||||
logger.warning("something went wrong. file %s not available. will not add it to playlist", dst)
|
||||
|
@ -325,8 +325,7 @@ class PypoFetch(Thread):
|
|||
else:
|
||||
logger.info('sucessfully removed %s', os.path.join(r, dir))
|
||||
except Exception, e:
|
||||
print e
|
||||
logger.error("%s", e)
|
||||
logger.error(e)
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
@ -27,6 +27,7 @@ try:
|
|||
LS_PORT = config['ls_port']
|
||||
PUSH_INTERVAL = 2
|
||||
except Exception, e:
|
||||
logger = logging.getLogger()
|
||||
logger.error('Error loading config file %s', e)
|
||||
sys.exit()
|
||||
|
||||
|
|
|
@ -61,12 +61,10 @@ class CueFile():
|
|||
|
||||
command = 'mp3cut -o %s -t %s-%s %s' % (dst + '.tmp.mp3', str_cue_in, str_cue_out, src);
|
||||
logger.info("command: %s", command)
|
||||
print command
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
|
||||
command = 'lame -b 128 %s %s' % (dst + '.tmp.mp3', dst);
|
||||
logger.info("command: %s", command)
|
||||
print command
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
elif src.lower().endswith('.ogg'):
|
||||
audio = OggVorbis(src)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue