2014-11-28 00:48:03 +01:00
|
|
|
<?php
|
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
define("RMQ_INI_SECTION", "rabbitmq");
|
|
|
|
require_once dirname(dirname( __DIR__)) . '/library/php-amqplib/amqp.inc';
|
|
|
|
|
2014-12-19 17:44:23 +01:00
|
|
|
function booleanReduce($a, $b) {
|
|
|
|
return $a && $b;
|
|
|
|
}
|
|
|
|
|
2014-11-28 01:10:23 +01:00
|
|
|
/**
|
|
|
|
* Check to see if Airtime is properly configured.
|
|
|
|
*
|
|
|
|
* @return boolean true if all Airtime dependencies and services are
|
|
|
|
* properly configured and running
|
|
|
|
*/
|
2014-12-04 00:04:47 +01:00
|
|
|
function checkConfiguration() {
|
2014-12-19 17:44:23 +01:00
|
|
|
$r1 = array_reduce(checkPhpDependencies(), "booleanReduce", true);
|
|
|
|
$r2 = array_reduce(checkExternalServices(), "booleanReduce", true);
|
|
|
|
return $r1 && $r2;
|
2014-11-28 01:10:23 +01:00
|
|
|
}
|
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
|
|
|
* Check for Airtime's PHP dependencies and return an associative
|
|
|
|
* array with the results
|
|
|
|
*
|
|
|
|
* @return array associative array of dependency check results
|
|
|
|
*/
|
2014-12-04 00:04:47 +01:00
|
|
|
function checkPhpDependencies() {
|
2014-11-28 21:30:11 +01:00
|
|
|
return array(
|
2015-01-15 22:44:49 +01:00
|
|
|
"zend" => checkZendDependencies(),
|
2014-12-04 00:04:47 +01:00
|
|
|
"postgres" => checkDatabaseDependencies()
|
2014-11-28 21:30:11 +01:00
|
|
|
);
|
2014-11-28 00:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-28 21:30:11 +01:00
|
|
|
* Check that the Zend framework libraries are installed
|
2014-11-28 00:48:03 +01:00
|
|
|
*
|
2014-11-28 21:30:11 +01:00
|
|
|
* @return boolean true if Zend exists in /usr/share/php
|
2014-11-28 00:48:03 +01:00
|
|
|
*/
|
2015-01-15 22:44:49 +01:00
|
|
|
function checkZendDependencies() {
|
2014-11-28 21:30:11 +01:00
|
|
|
return file_exists('/usr/share/php/libzend-framework-php')
|
|
|
|
|| file_exists('/usr/share/php/zendframework'); // Debian version
|
|
|
|
}
|
2014-11-28 01:10:23 +01:00
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
|
|
|
* Check that the PHP dependencies for the database exist
|
|
|
|
*
|
|
|
|
* @return boolean true if the database dependencies exist
|
|
|
|
*/
|
2014-12-04 00:04:47 +01:00
|
|
|
function checkDatabaseDependencies() {
|
2014-12-01 21:49:53 +01:00
|
|
|
global $extensions;
|
2014-11-28 21:30:11 +01:00
|
|
|
// Check the PHP extension list for the Postgres db extensions
|
|
|
|
return (in_array('pdo_pgsql', $extensions)
|
|
|
|
&& in_array('pgsql', $extensions));
|
|
|
|
}
|
2014-11-28 00:48:03 +01:00
|
|
|
|
2014-12-19 17:44:23 +01:00
|
|
|
/**
|
|
|
|
* Check that all external services are configured correctly and return an associative
|
|
|
|
* array with the results
|
|
|
|
*
|
|
|
|
* @return array associative array of external service check results
|
|
|
|
*/
|
|
|
|
function checkExternalServices() {
|
|
|
|
return array(
|
|
|
|
"database" => checkDatabaseConfiguration(),
|
|
|
|
"media-monitor" => checkMediaMonitorService(),
|
|
|
|
"pypo" => checkPlayoutService(),
|
|
|
|
"liquidsoap" => checkLiquidsoapService(),
|
|
|
|
"rabbitmq" => checkRMQConnection()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
|
|
|
* Check the database configuration by fetching a connection from Propel
|
|
|
|
*
|
|
|
|
* @return boolean true if a connection is made to the database
|
|
|
|
*/
|
2014-12-04 00:04:47 +01:00
|
|
|
function checkDatabaseConfiguration() {
|
|
|
|
configureDatabase();
|
2014-11-28 00:48:03 +01:00
|
|
|
|
|
|
|
try {
|
2014-11-28 21:30:11 +01:00
|
|
|
// Try to establish a database connection. If something goes
|
|
|
|
// wrong, the database is improperly configured
|
|
|
|
Propel::getConnection();
|
|
|
|
Propel::close();
|
2014-11-28 00:48:03 +01:00
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
|
|
|
* Initialize Propel to configure the Airtime database
|
|
|
|
*/
|
2014-12-04 00:04:47 +01:00
|
|
|
function configureDatabase() {
|
2014-11-28 21:30:11 +01:00
|
|
|
Propel::init(CONFIG_PATH . 'airtime-conf-production.php');
|
2014-12-04 00:04:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
/**
|
|
|
|
* Check that we can connect to RabbitMQ
|
2014-12-19 17:58:47 +01:00
|
|
|
*
|
|
|
|
* @return true if the RabbitMQ connection can be established
|
2014-12-09 23:48:16 +01:00
|
|
|
*/
|
|
|
|
function checkRMQConnection() {
|
|
|
|
// Check for airtime.conf in /etc/airtime/ first, then check in the build directory,
|
|
|
|
if (file_exists(AIRTIME_CONFIG_STOR . AIRTIME_CONFIG)) {
|
|
|
|
$ini = parse_ini_file(AIRTIME_CONFIG_STOR . AIRTIME_CONFIG, true);
|
|
|
|
} else {
|
|
|
|
$ini = parse_ini_file(BUILD_PATH . "airtime.example.conf", true);
|
|
|
|
}
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
$conn = new AMQPConnection($ini[RMQ_INI_SECTION]["host"],
|
|
|
|
$ini[RMQ_INI_SECTION]["port"],
|
|
|
|
$ini[RMQ_INI_SECTION]["user"],
|
|
|
|
$ini[RMQ_INI_SECTION]["password"],
|
|
|
|
$ini[RMQ_INI_SECTION]["vhost"]);
|
|
|
|
return isset($conn);
|
2014-12-19 17:44:23 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 17:58:47 +01:00
|
|
|
/**
|
|
|
|
* Check if airtime-media-monitor is currently running
|
|
|
|
*
|
|
|
|
* @return boolean true if airtime-media-monitor is running
|
|
|
|
*/
|
2014-12-19 17:44:23 +01:00
|
|
|
function checkMediaMonitorService() {
|
2015-01-19 23:40:21 +01:00
|
|
|
exec("pgrep -fx 'python /usr/lib/airtime/media-monitor/media_monitor.py'", $out, $status);
|
2014-12-19 17:44:23 +01:00
|
|
|
return $status == 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 17:58:47 +01:00
|
|
|
/**
|
|
|
|
* Check if airtime-playout is currently running
|
|
|
|
*
|
|
|
|
* @return boolean true if airtime-playout is running
|
|
|
|
*/
|
2014-12-19 17:44:23 +01:00
|
|
|
function checkPlayoutService() {
|
2015-01-19 23:40:21 +01:00
|
|
|
exec("pgrep -fx 'python /usr/lib/airtime/pypo/bin/pypocli.py'", $out, $status);
|
2015-01-08 17:45:43 +01:00
|
|
|
return $status == 0;
|
2014-12-19 17:44:23 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 17:58:47 +01:00
|
|
|
/**
|
|
|
|
* Check if airtime-liquidsoap is currently running
|
|
|
|
*
|
|
|
|
* @return boolean true if airtime-liquidsoap is running
|
|
|
|
*/
|
2014-12-19 17:44:23 +01:00
|
|
|
function checkLiquidsoapService() {
|
2015-01-19 23:40:21 +01:00
|
|
|
exec("pgrep -fx '/usr/bin/airtime-liquidsoap --verbose -f /usr/lib/airtime/pypo/bin/liquidsoap_scripts/ls_script.liq'", $out, $status);
|
2015-01-08 17:45:43 +01:00
|
|
|
return $status == 0;
|
2014-11-28 00:48:03 +01:00
|
|
|
}
|