From a55b47efff659bc0981a2e4514b4f8a14ada9343 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 22 Dec 2011 17:21:18 -0500 Subject: [PATCH 1/2] -Allow etc and stor directories to be configurable --- .../configs/airtime-conf-production.php | 4 +++- airtime_mvc/application/configs/conf.php | 4 +++- .../controllers/plugins/RabbitMqPlugin.php | 4 +++- airtime_mvc/application/models/StoredFile.php | 15 +++++++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/configs/airtime-conf-production.php b/airtime_mvc/application/configs/airtime-conf-production.php index 31fb031e1..2d2dddb7d 100644 --- a/airtime_mvc/application/configs/airtime-conf-production.php +++ b/airtime_mvc/application/configs/airtime-conf-production.php @@ -8,7 +8,9 @@ * that the user can customize these. */ -$ini = parse_ini_file('/etc/airtime/airtime.conf', true); + +$configFile = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; +$ini = parse_ini_file($configFile, true); $dbhost = $ini['database']['host']; $dbname = $ini['database']['dbname']; diff --git a/airtime_mvc/application/configs/conf.php b/airtime_mvc/application/configs/conf.php index 27850985a..909ca4fa2 100644 --- a/airtime_mvc/application/configs/conf.php +++ b/airtime_mvc/application/configs/conf.php @@ -23,7 +23,9 @@ $CC_CONFIG = array( 'phingPath' => dirname(__FILE__).'/../../library/phing' ); -Config::loadConfig("/etc/airtime/airtime.conf"); + +$configFile = isset($_SERVER['AIRTIME_CONF']) ? $_SERVER['AIRTIME_CONF'] : "/etc/airtime/airtime.conf"; +Config::loadConfig($configFile); // Add database table names $CC_CONFIG['playListTable'] = $CC_CONFIG['tblNamePrefix'].'playlist'; diff --git a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php index 1c885528c..900f5a237 100644 --- a/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php +++ b/airtime_mvc/application/controllers/plugins/RabbitMqPlugin.php @@ -7,7 +7,9 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract if (Application_Model_RabbitMq::$doPush) { $md = array('schedule' => Application_Model_Schedule::GetScheduledPlaylists()); Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md); - Application_Model_RabbitMq::SendMessageToShowRecorder("update_schedule"); + if (!isset($_SERVER['AIRTIME_SRV'])){ + Application_Model_RabbitMq::SendMessageToShowRecorder("update_schedule"); + } } } } diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index a728e8846..d48c3c420 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -409,11 +409,13 @@ class Application_Model_StoredFile { * @return string */ public function getFilePath() - { + { $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); + $directory = $music_dir->getDirectory(); + $filepath = $this->_file->getDbFilepath(); - return $music_dir->getDirectory().$filepath; + return $directory.$filepath; } /** @@ -877,8 +879,13 @@ class Application_Model_StoredFile { $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; - $r = @copy($audio_file, $audio_stor); - $r = @unlink($audio_file); + Logging::log("copyFileToStor: moving file $audio_file to $audio_stor"); + + //Martin K.: changed to rename: Much less load + quicker since this is an atomic operation + $r = @rename($audio_file, $audio_stor); + + //$r = @copy($audio_file, $audio_stor); + //$r = @unlink($audio_file); } public static function getFileCount() From 00a05e146ba03a1875418bacf766ecb743a58b32 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 23 Dec 2011 15:32:48 -0500 Subject: [PATCH 2/2] CC-3222: Add option to disable auto starting Airtime services (after install and after system restart) -Done --- install_minimal/airtime-install | 26 ++++++++++------- install_minimal/include/airtime-initialize.sh | 20 +++++++------ .../install/media-monitor-copy-files.py | 3 +- .../install/media-monitor-initialize.py | 20 +++++++------ python_apps/monit/monit-airtime-generic.cfg | 5 ---- .../monit/monit-airtime-rabbitmq-server.cfg | 6 +--- python_apps/pypo/install/pypo-copy-files.py | 6 ++-- python_apps/pypo/install/pypo-initialize.py | 29 ++++++++++--------- .../install/recorder-copy-files.py | 7 +++-- .../install/recorder-initialize.py | 21 +++++++------- 10 files changed, 74 insertions(+), 69 deletions(-) diff --git a/install_minimal/airtime-install b/install_minimal/airtime-install index 4f2fb73b3..23ec01e2c 100755 --- a/install_minimal/airtime-install +++ b/install_minimal/airtime-install @@ -17,16 +17,17 @@ fi showhelp () { echo "Usage: airtime-install [options] ---help|-h Displays usage information. ---overwrite|-o Overwrite any existing config files. ---preserve|-p Keep any existing config files. ---no-db|-n Turn off database install. ---reinstall|-r Force a fresh install of this Airtime Version ---media-monitor|-m Install only media-monitor ---pypo|-p Install only pypo and liquidsoap ---show-recorder|-s Install only show-recorder ---web|-w Install only files for web-server ---liquidsoap-keep-alive|-l Keep Liquidsoap alive when upgrading" +--help|-h Displays usage information. +--overwrite|-o Overwrite any existing config files. +--preserve|-p Keep any existing config files. +--no-db|-n Turn off database install. +--reinstall|-r Force a fresh install of this Airtime Version +--media-monitor|-m Install only media-monitor +--pypo|-p Install only pypo and liquidsoap +--show-recorder|-s Install only show-recorder +--web|-w Install only files for web-server +--liquidsoap-keep-alive|-l Keep Liquidsoap alive when upgrading +--disable-auto-start-services|-d Disable auto-starting Airtime services" } overwrite="f" @@ -38,8 +39,9 @@ pypo="f" showrecorder="f" web="f" liquidsoap_keep_alive="f" +disable_auto_start_services="f" -set -- $(getopt -l help,overwrite,preserve,no-db,reinstall,media-monitor,pypo,show-recorder,web,liquidsoap-keep-alive "hopnrmyswl" "$@") +set -- $(getopt -l help,overwrite,preserve,no-db,reinstall,media-monitor,pypo,show-recorder,web,liquidsoap-keep-alive,disable-auto-start-services "hopnrmyswld" "$@") while [ $# -gt 0 ] do case "$1" in @@ -53,6 +55,7 @@ do (-s|--show-recorder) showrecorder="t";; (-w|--web) web="t";; (-l|--liquidsoap-keep-alive) liquidsoap_keep_alive="t";; + (-d|--disable-auto-start-services) disable_auto_start_services="t";; (--) shift; break;; (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;; @@ -107,6 +110,7 @@ export nodb export overwrite export preserve export liquidsoap_keep_alive +export disable_auto_start_services set +e test "$mediamonitor" = "t" -o "$pypo" = "t" -o "$showrecorder" = "t" diff --git a/install_minimal/include/airtime-initialize.sh b/install_minimal/include/airtime-initialize.sh index 084419142..dc69073bd 100755 --- a/install_minimal/include/airtime-initialize.sh +++ b/install_minimal/include/airtime-initialize.sh @@ -53,15 +53,17 @@ sleep 1 set +e -if [ "$mediamonitor" = "t" ]; then - monit monitor airtime-media-monitor -fi -if [ "$pypo" = "t" ]; then - monit monitor airtime-playout - monit monitor airtime-liquidsoap -fi -if [ "$showrecorder" = "t" ]; then - monit monitor airtime-show-recorder +if [ "$disable_auto_start_services" = "f" ]; then + if [ "$mediamonitor" = "t" ]; then + monit monitor airtime-media-monitor + fi + if [ "$pypo" = "t" ]; then + monit monitor airtime-playout + monit monitor airtime-liquidsoap + fi + if [ "$showrecorder" = "t" ]; then + monit monitor airtime-show-recorder + fi fi monit monitor rabbitmq-server diff --git a/python_apps/media-monitor/install/media-monitor-copy-files.py b/python_apps/media-monitor/install/media-monitor-copy-files.py index 8c083aa63..ecacf6ab1 100644 --- a/python_apps/media-monitor/install/media-monitor-copy-files.py +++ b/python_apps/media-monitor/install/media-monitor-copy-files.py @@ -42,8 +42,9 @@ try: sys.exit(1) #copy monit files - shutil.copy('%s/../monit-airtime-media-monitor.cfg'%current_script_dir, '/etc/monit/conf.d/') shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-media-monitor.cfg'%current_script_dir, '/etc/monit/conf.d/') #create log dir create_dir(config['log_dir']) diff --git a/python_apps/media-monitor/install/media-monitor-initialize.py b/python_apps/media-monitor/install/media-monitor-initialize.py index 638ab06e1..992487b49 100644 --- a/python_apps/media-monitor/install/media-monitor-initialize.py +++ b/python_apps/media-monitor/install/media-monitor-initialize.py @@ -6,15 +6,17 @@ if os.geteuid() != 0: sys.exit(1) try: - #update-rc.d init script - p = Popen("update-rc.d airtime-media-monitor defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] + + if os.environ["disable_auto_start_services"] == "f": + #update-rc.d init script + p = Popen("update-rc.d airtime-media-monitor defaults >/dev/null 2>&1", shell=True) + sts = os.waitpid(p.pid, 0)[1] - #Start media-monitor daemon - print "* Waiting for media-monitor processes to start..." - p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True) - sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-media-monitor start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] + #Start media-monitor daemon + print "* Waiting for media-monitor processes to start..." + p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-media-monitor start-no-monit", shell=True) + sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e diff --git a/python_apps/monit/monit-airtime-generic.cfg b/python_apps/monit/monit-airtime-generic.cfg index 791a401e3..e4b531587 100644 --- a/python_apps/monit/monit-airtime-generic.cfg +++ b/python_apps/monit/monit-airtime-generic.cfg @@ -3,8 +3,3 @@ set httpd port 2812 allow admin:monit - - check process rabbitmq-server - with pidfile "/var/run/rabbitmq.pid" - start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; /usr/lib/airtime/utils/rabbitmq-update-pid.sh'" - stop program = "/etc/init.d/rabbitmq-server stop" diff --git a/python_apps/monit/monit-airtime-rabbitmq-server.cfg b/python_apps/monit/monit-airtime-rabbitmq-server.cfg index 74742dc58..dac2463c8 100644 --- a/python_apps/monit/monit-airtime-rabbitmq-server.cfg +++ b/python_apps/monit/monit-airtime-rabbitmq-server.cfg @@ -1,11 +1,7 @@ set daemon 10 # Poll at 5 second intervals - #set logfile syslog facility log_daemon set logfile /var/log/monit.log - set httpd port 2812 - allow admin:monit - check process rabbitmq-server with pidfile "/var/run/rabbitmq.pid" - start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; sed "s/.*,\(.*\)\}.*/\1/" /var/lib/rabbitmq/pids > /var/run/rabbitmq.pid'" + start program = "/bin/bash -c '/etc/init.d/rabbitmq-server start; /usr/lib/airtime/utils/rabbitmq-update-pid.sh'" stop program = "/etc/init.d/rabbitmq-server stop" diff --git a/python_apps/pypo/install/pypo-copy-files.py b/python_apps/pypo/install/pypo-copy-files.py index d0baac86a..90d4705fb 100644 --- a/python_apps/pypo/install/pypo-copy-files.py +++ b/python_apps/pypo/install/pypo-copy-files.py @@ -42,9 +42,11 @@ try: sys.exit(1) #copy monit files - shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/') - shutil.copy('%s/../monit-airtime-liquidsoap.cfg'%current_script_dir, '/etc/monit/conf.d/') shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../../monit/monit-airtime-rabbitmq-server.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-liquidsoap.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/') #create pypo log dir create_dir(config['pypo_log_dir']) diff --git a/python_apps/pypo/install/pypo-initialize.py b/python_apps/pypo/install/pypo-initialize.py index 57b2a6ae8..9df8245aa 100644 --- a/python_apps/pypo/install/pypo-initialize.py +++ b/python_apps/pypo/install/pypo-initialize.py @@ -87,10 +87,6 @@ try: print "Unsupported system architecture." sys.exit(1) - #initialize init.d scripts - p = Popen("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] - #generate liquidsoap config file #access the DB and generate liquidsoap.cfg under /etc/airtime/ ac = api_client.api_client_factory(config) @@ -101,18 +97,23 @@ try: else: print "Unable to connect to the Airtime server." - #restart airtime-playout - print "* Waiting for pypo processes to start..." - if os.environ["liquidsoap_keep_alive"] == "f": - print " * Restarting any previous Liquidsoap instances" - p = Popen("/etc/init.d/airtime-playout stop", shell=True) + if os.environ["disable_auto_start_services"] == "f": + #initialize init.d scripts + p = Popen("update-rc.d airtime-playout defaults >/dev/null 2>&1", shell=True) sts = os.waitpid(p.pid, 0)[1] - else: - print " * Keeping any previous Liquidsoap instances running" - p = Popen("/etc/init.d/airtime-playout pypo-stop", shell=True) + + #restart airtime-playout + print "* Waiting for pypo processes to start..." + if os.environ["liquidsoap_keep_alive"] == "f": + print " * Restarting any previous Liquidsoap instances" + p = Popen("/etc/init.d/airtime-playout stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + else: + print " * Keeping any previous Liquidsoap instances running" + p = Popen("/etc/init.d/airtime-playout pypo-stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-playout start-no-monit", shell=True) sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-playout start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e diff --git a/python_apps/show-recorder/install/recorder-copy-files.py b/python_apps/show-recorder/install/recorder-copy-files.py index d78a22f6f..44ae93cc9 100644 --- a/python_apps/show-recorder/install/recorder-copy-files.py +++ b/python_apps/show-recorder/install/recorder-copy-files.py @@ -41,10 +41,11 @@ try: print 'Error loading config file: ', e sys.exit(1) - + #copy monit files - shutil.copy('%s/../monit-airtime-show-recorder.cfg'%current_script_dir, '/etc/monit/conf.d/') - shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/') + if os.environ["disable_auto_start_services"] == "f": + shutil.copy('%s/../monit-airtime-show-recorder.cfg'%current_script_dir, '/etc/monit/conf.d/') #create temporary media-storage directory #print "Creating temporary media storage directory" diff --git a/python_apps/show-recorder/install/recorder-initialize.py b/python_apps/show-recorder/install/recorder-initialize.py index caefa436a..9bcf38453 100644 --- a/python_apps/show-recorder/install/recorder-initialize.py +++ b/python_apps/show-recorder/install/recorder-initialize.py @@ -7,15 +7,16 @@ if os.geteuid() != 0: sys.exit(1) try: - #register init.d script - p = Popen("update-rc.d airtime-show-recorder defaults >/dev/null 2>&1", shell=True) - sts = os.waitpid(p.pid, 0)[1] - - #start daemon - print "* Waiting for show-recorder processes to start..." - p = Popen("/etc/init.d/airtime-show-recorder stop", shell=True) - sts = os.waitpid(p.pid, 0)[1] - p = Popen("/etc/init.d/airtime-show-recorder start-no-monit", shell=True) - sts = os.waitpid(p.pid, 0)[1] + if os.environ["disable_auto_start_services"] == "f": + #register init.d script + p = Popen("update-rc.d airtime-show-recorder defaults >/dev/null 2>&1", shell=True) + sts = os.waitpid(p.pid, 0)[1] + + #start daemon + print "* Waiting for show-recorder processes to start..." + p = Popen("/etc/init.d/airtime-show-recorder stop", shell=True) + sts = os.waitpid(p.pid, 0)[1] + p = Popen("/etc/init.d/airtime-show-recorder start-no-monit", shell=True) + sts = os.waitpid(p.pid, 0)[1] except Exception, e: print e