2014-11-28 00:48:03 +01:00
|
|
|
<?php
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
define('RMQ_INI_SECTION', 'rabbitmq');
|
2014-12-09 23:48:16 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
function booleanReduce($a, $b)
|
|
|
|
{
|
2014-12-19 17:44:23 +01:00
|
|
|
return $a && $b;
|
|
|
|
}
|
|
|
|
|
2014-11-28 01:10:23 +01:00
|
|
|
/**
|
|
|
|
* Check to see if Airtime is properly configured.
|
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return bool true if all Airtime dependencies and services are
|
|
|
|
* properly configured and running
|
2014-11-28 01:10:23 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkConfiguration()
|
|
|
|
{
|
|
|
|
$r1 = array_reduce(checkPhpDependencies(), 'booleanReduce', true);
|
|
|
|
$r2 = array_reduce(checkExternalServices(), 'booleanReduce', true);
|
|
|
|
|
2014-12-19 17:44:23 +01:00
|
|
|
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
|
2021-10-11 16:10:47 +02:00
|
|
|
* array with the results.
|
2014-11-28 21:30:11 +01:00
|
|
|
*
|
|
|
|
* @return array associative array of dependency check results
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkPhpDependencies()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'postgres' => checkDatabaseDependencies(),
|
|
|
|
];
|
2014-11-28 00:48:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Check that the PHP dependencies for the database exist.
|
2014-11-28 21:30:11 +01:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return bool true if the database dependencies exist
|
2014-11-28 21:30:11 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02: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
|
2021-10-11 16:10:47 +02:00
|
|
|
return in_array('pdo_pgsql', $extensions)
|
|
|
|
&& in_array('pgsql', $extensions);
|
2014-11-28 21:30:11 +01:00
|
|
|
}
|
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
|
2021-10-11 16:10:47 +02:00
|
|
|
* array with the results.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2014-12-19 17:44:23 +01:00
|
|
|
* @return array associative array of external service check results
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkExternalServices()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'database' => checkDatabaseConfiguration(),
|
|
|
|
'analyzer' => checkAnalyzerService(),
|
|
|
|
'pypo' => checkPlayoutService(),
|
|
|
|
'liquidsoap' => checkLiquidsoapService(),
|
|
|
|
'rabbitmq' => checkRMQConnection(),
|
|
|
|
'celery' => checkCeleryService(),
|
|
|
|
'api' => checkApiService(),
|
|
|
|
];
|
2014-12-19 17:44:23 +01:00
|
|
|
}
|
|
|
|
|
2014-11-28 21:30:11 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Check the database configuration by fetching a connection from Propel.
|
2014-11-28 21:30:11 +01:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return bool true if a connection is made to the database
|
2014-11-28 21:30:11 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkDatabaseConfiguration()
|
|
|
|
{
|
2014-12-04 00:04:47 +01:00
|
|
|
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
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Initialize Propel to configure the Airtime database.
|
2014-11-28 21:30:11 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02: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
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Check that we can connect to RabbitMQ.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
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
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkRMQConnection()
|
|
|
|
{
|
2014-12-09 23:48:16 +01:00
|
|
|
// 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 {
|
2021-10-11 16:10:47 +02:00
|
|
|
$ini = parse_ini_file(BUILD_PATH . 'airtime.example.conf', true);
|
2014-12-09 23:48:16 +01:00
|
|
|
}
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2021-10-17 21:55:12 +02:00
|
|
|
$conn = new \PhpAmqpLib\Connection\AMQPStreamConnection(
|
2021-10-11 16:10:47 +02:00
|
|
|
$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']
|
|
|
|
);
|
|
|
|
|
2014-12-09 23:48:16 +01:00
|
|
|
return isset($conn);
|
2014-12-19 17:44:23 +01:00
|
|
|
}
|
|
|
|
|
2014-12-19 17:58:47 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Check if airtime-analyzer is currently running.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return bool true if airtime-analyzer is running
|
2014-12-19 17:58:47 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkAnalyzerService()
|
|
|
|
{
|
|
|
|
exec('pgrep -f libretime-analyzer', $out, $status);
|
2020-04-18 03:54:26 +02:00
|
|
|
if (($out > 0) && $status == 0) {
|
2015-01-20 19:42:41 +01:00
|
|
|
return posix_kill(rtrim($out[0]), 0);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-12-19 17:44:23 +01:00
|
|
|
return $status == 0;
|
|
|
|
}
|
|
|
|
|
2014-12-19 17:58:47 +01:00
|
|
|
/**
|
2021-10-12 14:05:55 +02:00
|
|
|
* Check if libretime-playout is currently running.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2021-10-12 14:05:55 +02:00
|
|
|
* @return bool true if libretime-playout is running
|
2014-12-19 17:58:47 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkPlayoutService()
|
|
|
|
{
|
2021-10-12 14:05:55 +02:00
|
|
|
exec('pgrep -f libretime-playout', $out, $status);
|
2020-04-18 03:54:26 +02:00
|
|
|
if ($out > 0) {
|
2015-01-20 19:42:41 +01:00
|
|
|
return posix_kill(rtrim($out[0]), 0);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
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
|
|
|
/**
|
2021-10-12 14:05:55 +02:00
|
|
|
* Check if libretime-liquidsoap is currently running.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2021-10-12 14:05:55 +02:00
|
|
|
* @return bool true if libretime-liquidsoap is running
|
2014-12-19 17:58:47 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkLiquidsoapService()
|
|
|
|
{
|
2021-10-12 14:05:55 +02:00
|
|
|
exec('pgrep -f libretime-liquidsoap', $out, $status);
|
2020-04-18 03:54:26 +02:00
|
|
|
if ($out > 0) {
|
2015-01-20 19:42:41 +01:00
|
|
|
return posix_kill(rtrim($out[0]), 0);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-01-08 17:45:43 +01:00
|
|
|
return $status == 0;
|
2015-01-20 19:42:41 +01:00
|
|
|
}
|
2017-04-01 10:25:12 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 14:05:55 +02:00
|
|
|
* Check if libretime-celery is currently running.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2021-10-12 14:05:55 +02:00
|
|
|
* @return bool true if libretime-celery is running
|
2017-04-01 10:25:12 +02:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkCeleryService()
|
|
|
|
{
|
2021-12-24 00:47:44 +01:00
|
|
|
exec('pgrep -f -u celery libretime_worker', $out, $status);
|
2017-04-01 10:25:12 +02:00
|
|
|
if (array_key_exists(0, $out) && $status == 0) {
|
2018-09-04 01:00:13 +02:00
|
|
|
return 1;
|
2017-04-01 10:25:12 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2017-04-01 10:25:12 +02:00
|
|
|
return $status == 0;
|
|
|
|
}
|
2020-01-30 14:47:36 +01:00
|
|
|
|
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Check if libretime-api is currently running.
|
2020-01-30 14:47:36 +01:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return bool true if libretime-api is running
|
2020-01-30 14:47:36 +01:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkApiService()
|
|
|
|
{
|
|
|
|
exec('pgrep -f -u www-data uwsgi', $out, $status);
|
2020-01-30 14:47:36 +01:00
|
|
|
if (array_key_exists(0, $out) && $status == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2020-01-30 14:47:36 +01:00
|
|
|
return $status == 0;
|
|
|
|
}
|