1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00
appwrite/app/cli.php

114 lines
2.6 KiB
PHP
Raw Normal View History

2020-07-29 07:48:51 +12:00
<?php
2022-05-24 02:54:50 +12:00
require_once __DIR__ . '/init.php';
require_once __DIR__ . '/controllers/general.php';
2020-07-29 07:48:51 +12:00
use Utopia\App;
use Utopia\CLI\CLI;
use Utopia\CLI\Console;
2022-10-18 05:43:51 +13:00
use Utopia\Cache\Adapter\Sharding;
use Utopia\Cache\Cache;
use Utopia\Config\Config;
use Utopia\Database\Database;
2022-04-10 21:38:22 +12:00
use Utopia\Database\Validator\Authorization;
2022-10-18 05:43:51 +13:00
use InfluxDB\Database as InfluxDatabase;
function getInfluxDB(): InfluxDatabase
{
global $register;
$client = $register->get('influxdb'); /** @var InfluxDB\Client $client */
$attempts = 0;
$max = 10;
$sleep = 1;
do { // check if telegraf database is ready
try {
$attempts++;
$database = $client->selectDB('telegraf');
if (in_array('telegraf', $client->listDatabases())) {
break; // leave the do-while if successful
}
} catch (\Throwable $th) {
Console::warning("InfluxDB not ready. Retrying connection ({$attempts})...");
if ($attempts >= $max) {
throw new \Exception('InfluxDB database not ready yet');
}
sleep($sleep);
}
} while ($attempts < $max);
return $database;
}
function getConsoleDB(): Database
{
global $register;
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
2022-10-19 21:35:30 +13:00
2022-10-24 14:34:12 +13:00
$dbAdapter = $pools
->get('console')
->pop()
->getResource()
;
2022-10-18 05:43:51 +13:00
$database = new Database($dbAdapter, getCache());
$database->setNamespace('console');
return $database;
}
function getCache(): Cache
{
global $register;
$pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */
2022-10-19 21:35:30 +13:00
2022-10-18 05:43:51 +13:00
$list = Config::getParam('pools-cache', []);
$adapters = [];
2022-10-19 21:35:30 +13:00
2022-10-18 05:43:51 +13:00
foreach ($list as $value) {
$adapters[] = $pools
->get($value)
->pop()
->getResource()
;
}
return new Cache(new Sharding($adapters));
}
2022-04-10 21:38:22 +12:00
Authorization::disable();
2020-07-29 07:48:51 +12:00
$cli = new CLI();
include 'tasks/doctor.php';
2020-12-15 05:39:44 +13:00
include 'tasks/maintenance.php';
include 'tasks/volume-sync.php';
2020-07-29 07:48:51 +12:00
include 'tasks/install.php';
include 'tasks/migrate.php';
include 'tasks/sdks.php';
include 'tasks/specs.php';
2020-07-29 07:48:51 +12:00
include 'tasks/ssl.php';
2020-10-15 18:03:38 +13:00
include 'tasks/vars.php';
2021-08-10 20:44:31 +12:00
include 'tasks/usage.php';
2020-07-29 07:48:51 +12:00
$cli
->task('version')
->desc('Get the server version')
->action(function () {
Console::log(App::getEnv('_APP_VERSION', 'UNKNOWN'));
});
2022-10-16 11:44:03 +13:00
$cli
->error(function ($error) {
2022-10-19 21:35:30 +13:00
if (App::getEnv('_APP_ENV', 'development')) {
2022-10-16 11:44:03 +13:00
Console::error($error);
} else {
Console::error($error->getMessage());
}
});
2022-05-24 02:54:50 +12:00
$cli->run();