2014-11-28 00:48:03 +01:00
|
|
|
<?php
|
|
|
|
|
2024-01-07 13:59:02 +01:00
|
|
|
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
2023-12-30 19:41:50 +01:00
|
|
|
use PhpAmqpLib\Exception\AMQPRuntimeException;
|
|
|
|
|
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;
|
2023-08-15 18:28:18 +02:00
|
|
|
|
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
|
|
|
|
2022-09-19 11:56:56 +02:00
|
|
|
function with_systemd()
|
|
|
|
{
|
|
|
|
return !empty(shell_exec('which systemctl'));
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2022-09-19 11:56:56 +02:00
|
|
|
$result = [
|
2021-10-11 16:10:47 +02:00
|
|
|
'database' => checkDatabaseConfiguration(),
|
|
|
|
'rabbitmq' => checkRMQConnection(),
|
|
|
|
];
|
2022-09-19 11:56:56 +02:00
|
|
|
|
|
|
|
if (with_systemd()) {
|
|
|
|
$result['analyzer'] = checkAnalyzerService();
|
|
|
|
$result['pypo'] = checkPlayoutService();
|
|
|
|
$result['liquidsoap'] = checkLiquidsoapService();
|
|
|
|
$result['celery'] = checkCeleryService();
|
|
|
|
$result['api'] = checkApiService();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
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();
|
2022-12-16 19:07:38 +01:00
|
|
|
} catch (Exception $exc) {
|
|
|
|
Logging::error($exc->getMessage());
|
|
|
|
|
2014-11-28 00:48:03 +01:00
|
|
|
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()
|
|
|
|
{
|
2022-02-04 11:00:41 +01:00
|
|
|
Propel::init(PROPEL_CONFIG_FILEPATH);
|
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()
|
|
|
|
{
|
2022-05-09 13:21:17 +02:00
|
|
|
$config = Config::getConfig();
|
2014-12-04 00:04:47 +01:00
|
|
|
|
2022-12-16 19:07:38 +01:00
|
|
|
try {
|
2024-01-07 13:59:02 +01:00
|
|
|
$conn = new AMQPStreamConnection(
|
2022-12-16 19:07:38 +01:00
|
|
|
$config['rabbitmq']['host'],
|
|
|
|
$config['rabbitmq']['port'],
|
|
|
|
$config['rabbitmq']['user'],
|
|
|
|
$config['rabbitmq']['password'],
|
|
|
|
$config['rabbitmq']['vhost']
|
|
|
|
);
|
|
|
|
|
|
|
|
return isset($conn);
|
2023-12-30 19:41:50 +01:00
|
|
|
} catch (AMQPRuntimeException $exc) {
|
2022-12-16 19:07:38 +01:00
|
|
|
Logging::error($exc->getMessage());
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2022-12-16 19:07:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
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()
|
|
|
|
{
|
2022-05-24 10:09:48 +02:00
|
|
|
exec('systemctl is-active libretime-analyzer --quiet', $out, $status);
|
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()
|
|
|
|
{
|
2022-05-24 10:09:48 +02:00
|
|
|
exec('systemctl is-active libretime-playout --quiet', $out, $status);
|
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()
|
|
|
|
{
|
2022-05-24 10:09:48 +02:00
|
|
|
exec('systemctl is-active libretime-liquidsoap --quiet', $out, $status);
|
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
|
|
|
|
|
|
|
/**
|
2022-08-20 08:13:30 +02:00
|
|
|
* Check if libretime-worker is currently running.
|
2020-05-19 16:16:31 +02:00
|
|
|
*
|
2022-08-20 08:13:30 +02:00
|
|
|
* @return bool true if libretime-worker is running
|
2017-04-01 10:25:12 +02:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
function checkCeleryService()
|
|
|
|
{
|
2022-08-20 08:13:30 +02:00
|
|
|
exec('systemctl is-active libretime-worker --quiet', $out, $status);
|
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()
|
|
|
|
{
|
2022-05-10 13:54:16 +02:00
|
|
|
exec('systemctl status libretime-api --quiet', $out, $status);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2020-01-30 14:47:36 +01:00
|
|
|
return $status == 0;
|
|
|
|
}
|