Removed many unnecessary files and started changing pypo to use setuptools
This commit is contained in:
parent
144923c353
commit
97805ad271
169 changed files with 5 additions and 8620 deletions
|
@ -1,140 +0,0 @@
|
|||
import os
|
||||
import grp
|
||||
import stat
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import random
|
||||
import string
|
||||
import re
|
||||
from configobj import ConfigObj
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
def get_current_script_dir():
|
||||
current_script_dir = os.path.realpath(__file__)
|
||||
index = current_script_dir.rindex('/')
|
||||
return current_script_dir[0:index]
|
||||
|
||||
def copy_dir(src_dir, dest_dir):
|
||||
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
|
||||
shutil.rmtree(dest_dir)
|
||||
if not (os.path.exists(dest_dir)):
|
||||
#print "Copying directory "+os.path.realpath(src_dir)+" to "+os.path.realpath(dest_dir)
|
||||
shutil.copytree(src_dir, dest_dir)
|
||||
|
||||
def create_dir(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
def get_rand_string(length=10):
|
||||
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
|
||||
|
||||
def get_rand_string(length=10):
|
||||
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
|
||||
|
||||
def get_monit_version():
|
||||
version = 0
|
||||
try:
|
||||
p = subprocess.Popen(['monit', '-V'], stdout=subprocess.PIPE)
|
||||
out = p.communicate()[0].strip()
|
||||
search = re.search(r'This is Monit version (.*)\n', out, re.IGNORECASE)
|
||||
|
||||
if search:
|
||||
matches = search.groups()
|
||||
if len(matches) == 1:
|
||||
version = matches[0]
|
||||
except Exception:
|
||||
print "Could not get monit version"
|
||||
|
||||
return version
|
||||
|
||||
#return 1 if version1 > version2
|
||||
#return 0 if version1 == version2
|
||||
#return -1 if version1 < version2
|
||||
def version_compare(version1, version2):
|
||||
def normalize(v):
|
||||
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
|
||||
return cmp(normalize(version1), normalize(version2))
|
||||
|
||||
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
||||
|
||||
try:
|
||||
# Absolute path this script is in
|
||||
current_script_dir = get_current_script_dir()
|
||||
|
||||
if not os.path.exists(PATH_INI_FILE):
|
||||
shutil.copy('%s/../pypo.cfg'%current_script_dir, PATH_INI_FILE)
|
||||
|
||||
try:
|
||||
os.remove("/etc/airtime/liquidsoap.cfg")
|
||||
except Exception, e:
|
||||
pass
|
||||
gid = grp.getgrnam("pypo").gr_gid
|
||||
os.chown("/etc/airtime", -1, gid)
|
||||
os.chmod("/etc/airtime", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
|
||||
|
||||
# load config file
|
||||
try:
|
||||
config = ConfigObj(PATH_INI_FILE)
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit(1)
|
||||
|
||||
#copy monit files
|
||||
shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
||||
subprocess.call('sed -i "s/\$admin_pass/%s/g" /etc/monit/conf.d/monit-airtime-generic.cfg' % get_rand_string(), shell=True, close_fds=True)
|
||||
|
||||
monit_version = get_monit_version()
|
||||
if version_compare(monit_version, "5.3.0") >= 0:
|
||||
shutil.copy('%s/../monit-airtime-liquidsoap.cfg' % current_script_dir, \
|
||||
'/etc/monit/conf.d/monit-airtime-liquidsoap.cfg')
|
||||
else:
|
||||
shutil.copy('%s/../monit-pre530-airtime-liquidsoap.cfg' % current_script_dir, \
|
||||
'/etc/monit/conf.d/monit-airtime-liquidsoap.cfg')
|
||||
|
||||
shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
||||
|
||||
#create pypo log dir
|
||||
create_dir(config['pypo_log_dir'])
|
||||
os.system("chown -R pypo:pypo "+config["pypo_log_dir"])
|
||||
|
||||
#create liquidsoap log dir
|
||||
create_dir(config['liquidsoap_log_dir'])
|
||||
os.system("chown -R pypo:pypo "+config["liquidsoap_log_dir"])
|
||||
|
||||
#create cache, tmp, file dirs
|
||||
create_dir(config['cache_dir'])
|
||||
create_dir(config['file_dir'])
|
||||
create_dir(config['tmp_dir'])
|
||||
|
||||
create_dir(config["base_recorded_files"])
|
||||
|
||||
#copy files to bin dir
|
||||
copy_dir("%s/.."%current_script_dir, config["bin_dir"]+"/bin/")
|
||||
|
||||
# delete /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap.cfg
|
||||
# as we don't use it anymore.(CC-2552)
|
||||
os.remove(config["bin_dir"]+"/bin/liquidsoap_scripts/liquidsoap.cfg")
|
||||
|
||||
#set permissions in bin dir and cache dir
|
||||
os.system("chmod 755 "+os.path.join(config["bin_dir"], "bin/liquidsoap_scripts/notify.sh"))
|
||||
os.system("chown -R pypo:pypo "+config["bin_dir"])
|
||||
os.system("chown -R pypo:pypo "+config["cache_base_dir"])
|
||||
os.system("chown -R pypo:pypo "+config["base_recorded_files"])
|
||||
|
||||
#copy init.d script
|
||||
shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout")
|
||||
shutil.copy(config["bin_dir"]+"/bin/airtime-liquidsoap-init-d", "/etc/init.d/airtime-liquidsoap")
|
||||
|
||||
#copy log rotate script
|
||||
shutil.copy(config["bin_dir"]+"/bin/liquidsoap_scripts/airtime-liquidsoap.logrotate", "/etc/logrotate.d/airtime-liquidsoap")
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
import platform
|
||||
import shutil
|
||||
from subprocess import Popen, PIPE
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
sys.path.append('/usr/lib/airtime/')
|
||||
from api_clients import api_client
|
||||
from configobj import ConfigObj
|
||||
|
||||
import logging
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
"""
|
||||
This function returns the codename of the host OS by querying lsb_release.
|
||||
If lsb_release does not exist, or an exception occurs the codename returned
|
||||
is 'unknown'
|
||||
"""
|
||||
def get_os_codename():
|
||||
try:
|
||||
p = Popen("which lsb_release > /dev/null", shell=True)
|
||||
sts = os.waitpid(p.pid, 0)[1]
|
||||
|
||||
if (sts == 0):
|
||||
#lsb_release is available on this system. Let's get the os codename
|
||||
p = Popen("lsb_release -sc", shell=True, stdout=PIPE)
|
||||
codename = p.communicate()[0].strip('\r\n')
|
||||
|
||||
p = Popen("lsb_release -sd", shell=True, stdout=PIPE)
|
||||
fullname = p.communicate()[0].strip('\r\n')
|
||||
|
||||
return (codename, fullname)
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
return ("unknown", "unknown")
|
||||
|
||||
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
||||
PATH_LIQUIDSOAP_BIN = '/usr/lib/airtime/pypo/bin/liquidsoap_bin'
|
||||
|
||||
#any debian/ubuntu codename in this et will automatically use the natty liquidsoap binary
|
||||
arch_map = dict({"32bit":"i386", "64bit":"amd64"})
|
||||
|
||||
# load config file
|
||||
try:
|
||||
config = ConfigObj(PATH_INI_FILE)
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
#select appropriate liquidsoap file for given system os/architecture
|
||||
architecture = platform.architecture()[0]
|
||||
arch = arch_map[architecture]
|
||||
|
||||
print "* Detecting OS: ...",
|
||||
(codename, fullname) = get_os_codename()
|
||||
print " Found %s (%s) on %s architecture" % (fullname, codename, arch)
|
||||
|
||||
print " * Creating symlink to Liquidsoap binary"
|
||||
|
||||
p = Popen("which liquidsoap", shell=True, stdout=PIPE)
|
||||
liq_path = p.communicate()[0].strip()
|
||||
symlink_path = "/usr/bin/airtime-liquidsoap"
|
||||
|
||||
if p.returncode == 0:
|
||||
try:
|
||||
os.unlink(symlink_path)
|
||||
except Exception:
|
||||
#liq_path DNE, which is OK.
|
||||
pass
|
||||
|
||||
os.symlink(liq_path, symlink_path)
|
||||
else:
|
||||
print " * Liquidsoap binary not found!"
|
||||
sys.exit(1)
|
||||
|
||||
#initialize init.d scripts
|
||||
subprocess.call("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True)
|
||||
subprocess.call("update-rc.d airtime-liquidsoap defaults >/dev/null 2>&1", shell=True)
|
||||
|
||||
#clear out an previous pypo cache
|
||||
print "* Clearing previous pypo cache"
|
||||
subprocess.call("rm -rf /var/tmp/airtime/pypo/cache/scheduler/* >/dev/null 2>&1", shell=True)
|
||||
|
||||
if "airtime_service_start" in os.environ and os.environ["airtime_service_start"] == "t":
|
||||
print "* Waiting for pypo processes to start..."
|
||||
subprocess.call("invoke-rc.d airtime-liquidsoap start > /dev/null 2>&1", shell=True)
|
||||
subprocess.call("invoke-rc.d airtime-playout start > /dev/null 2>&1", shell=True)
|
||||
|
||||
except Exception, e:
|
||||
print e
|
|
@ -1,54 +0,0 @@
|
|||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from configobj import ConfigObj
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
||||
|
||||
def remove_file(path):
|
||||
try:
|
||||
os.remove(path)
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
# load config file
|
||||
try:
|
||||
config = ConfigObj(PATH_INI_FILE)
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
#remove log rotate script
|
||||
print " * Removing Pypo Log Rotate Script"
|
||||
remove_file("/etc/logrotate.d/airtime-liquidsoap")
|
||||
|
||||
#remove init.d script
|
||||
print " * Removing Pypo init.d Script"
|
||||
remove_file("/etc/init.d/airtime-playout")
|
||||
remove_file("/etc/init.d/airtime-liquidsoap")
|
||||
|
||||
#remove bin, cache, tmp and file dir
|
||||
print " * Removing Pypo Program Directory"
|
||||
shutil.rmtree(config['bin_dir'], ignore_errors=True)
|
||||
shutil.rmtree(config['cache_dir'], ignore_errors=True)
|
||||
shutil.rmtree(config['file_dir'], ignore_errors=True)
|
||||
shutil.rmtree(config['tmp_dir'], ignore_errors=True)
|
||||
|
||||
#remove liquidsoap and pypo log dir
|
||||
print " * Removing Pypo Log Directories"
|
||||
shutil.rmtree(config['liquidsoap_log_dir'], ignore_errors=True)
|
||||
shutil.rmtree(config['pypo_log_dir'], ignore_errors=True)
|
||||
|
||||
#remove monit files
|
||||
print " * Removing Pypo Monit Files"
|
||||
remove_file("/etc/monit/conf.d/monit-airtime-playout.cfg")
|
||||
remove_file("/etc/monit/conf.d/monit-airtime-liquidsoap.cfg")
|
||||
remove_file("/etc/monit/conf.d/monit-airtime-generic.cfg")
|
||||
|
||||
except Exception, e:
|
||||
print e
|
|
@ -1,33 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
#stop pypo and liquidsoap processes
|
||||
print "Waiting for Pypo process to stop...",
|
||||
try:
|
||||
os.remove("/usr/bin/airtime-liquidsoap")
|
||||
except Exception, e:
|
||||
pass
|
||||
if (os.path.exists('/etc/init.d/airtime-playout')):
|
||||
subprocess.call("invoke-rc.d airtime-playout stop", shell=True)
|
||||
print "OK"
|
||||
else:
|
||||
print "Wasn't running"
|
||||
|
||||
print "Waiting for Liquidsoap process to stop...",
|
||||
if (os.path.exists('/etc/init.d/airtime-liquidsoap')):
|
||||
subprocess.call("invoke-rc.d airtime-liquidsoap stop", shell=True)
|
||||
print "OK"
|
||||
else:
|
||||
print "Wasn't running"
|
||||
|
||||
subprocess.call("update-rc.d -f airtime-playout remove".split(" "))
|
||||
subprocess.call("update-rc.d -f airtime-liquidsoap remove".split(" "))
|
||||
|
||||
except Exception, e:
|
||||
print e
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 492242f4bb7367afebbf2f096067cb5a5d3c0449
|
|
@ -1,17 +0,0 @@
|
|||
set daemon 15 # Poll at 5 second intervals
|
||||
set logfile /var/log/monit.log
|
||||
|
||||
set httpd port 2812
|
||||
|
||||
check process airtime-liquidsoap matching "airtime-liquidsoap.*airtime.*ls_script"
|
||||
if does not exist for 3 cycles then restart
|
||||
|
||||
start program = "/etc/init.d/airtime-liquidsoap start" with timeout 30 seconds
|
||||
stop program = "/etc/init.d/airtime-liquidsoap stop"
|
||||
|
||||
if mem > 600 MB for 3 cycles then restart
|
||||
if failed host localhost port 1234
|
||||
send "version\r\nexit\r\n"
|
||||
expect "Liquidsoap"
|
||||
with timeout 2 seconds retry 3 for 2 cycles
|
||||
then restart
|
|
@ -1,9 +0,0 @@
|
|||
set daemon 10 # Poll at 5 second intervals
|
||||
set logfile /var/log/monit.log
|
||||
|
||||
set httpd port 2812
|
||||
|
||||
check process airtime-playout
|
||||
with pidfile "/var/run/airtime/airtime-playout.pid"
|
||||
start program = "/etc/init.d/airtime-playout start" with timeout 5 seconds
|
||||
stop program = "/etc/init.d/airtime-playout stop"
|
|
@ -1,8 +0,0 @@
|
|||
set daemon 15 # Poll at 5 second intervals
|
||||
set logfile /var/log/monit.log
|
||||
|
||||
set httpd port 2812
|
||||
|
||||
check process airtime-liquidsoap with pidfile "/var/run/airtime/airtime-liquidsoap.pid"
|
||||
start program = "/etc/init.d/airtime-liquidsoap start" with timeout 5 seconds
|
||||
stop program = "/etc/init.d/airtime-liquidsoap stop"
|
|
@ -56,37 +56,18 @@ stop () {
|
|||
sleep 2
|
||||
}
|
||||
|
||||
start_with_monit () {
|
||||
start
|
||||
monit monitor airtime-liquidsoap >/dev/null 2>&1
|
||||
}
|
||||
|
||||
stop_with_monit() {
|
||||
monit unmonitor airtime-liquidsoap >/dev/null 2>&1
|
||||
stop
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
case "${1:-''}" in
|
||||
'stop')
|
||||
echo "* Stopping Liquidsoap without notifying Monit process watchdog. If Monit is
|
||||
* running it will automatically bring the Liquidsoap back up. You probably want
|
||||
* 'stop-with-monit' instead of 'stop'."
|
||||
echo -n "Stopping $NAME: "
|
||||
stop
|
||||
echo "Done."
|
||||
;;
|
||||
'start')
|
||||
echo "* Starting $NAME without Monit process watchdog. To make sure Monit is watching
|
||||
* Liquidsoap, use 'start-with-monit' instead of 'start'."
|
||||
echo -n "Starting $NAME: "
|
||||
start
|
||||
echo "Done."
|
||||
;;
|
||||
'restart')
|
||||
# restart commands here
|
||||
echo -n "Restarting $NAME: "
|
||||
stop
|
||||
start
|
||||
|
@ -104,18 +85,6 @@ case "${1:-''}" in
|
|||
echo "$NAME is not running"
|
||||
exit 1
|
||||
;;
|
||||
'start-with-monit')
|
||||
# restart commands here
|
||||
echo -n "Starting $NAME: "
|
||||
start_with_monit
|
||||
echo "Done."
|
||||
;;
|
||||
'stop-with-monit')
|
||||
# restart commands here
|
||||
echo -n "Stopping $NAME: "
|
||||
stop_with_monit
|
||||
echo "Done."
|
||||
;;
|
||||
|
||||
*) # no parameter specified
|
||||
echo "Usage: $SELF start|stop|restart|status"
|
|
@ -28,16 +28,6 @@ stop () {
|
|||
rm -f $PIDFILE
|
||||
}
|
||||
|
||||
start_with_monit() {
|
||||
start
|
||||
monit monitor airtime-playout >/dev/null 2>&1
|
||||
}
|
||||
|
||||
stop_with_monit() {
|
||||
monit unmonitor airtime-playout >/dev/null 2>&1
|
||||
stop
|
||||
}
|
||||
|
||||
case "${1:-''}" in
|
||||
'start')
|
||||
# start commands here
|
||||
|
@ -58,18 +48,6 @@ case "${1:-''}" in
|
|||
start
|
||||
echo "Done."
|
||||
;;
|
||||
'start-with-monit')
|
||||
# restart commands here
|
||||
echo -n "Starting $NAME: "
|
||||
start_with_monit
|
||||
echo "Done."
|
||||
;;
|
||||
'stop-with-monit')
|
||||
# restart commands here
|
||||
echo -n "Stopping $NAME: "
|
||||
stop_with_monit
|
||||
echo "Done."
|
||||
;;
|
||||
|
||||
'status')
|
||||
# status commands here
|
Loading…
Add table
Add a link
Reference in a new issue