Use local socket for Redis; update uptime_wait.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-05-07 10:59:37 -05:00
parent 5dc6bf8742
commit 3e03980811
No known key found for this signature in database
GPG Key ID: 9FC8B9E008872109
5 changed files with 29 additions and 28 deletions

View File

@ -92,17 +92,17 @@ class UptimeWait
protected function checkDatabase(): bool
{
try {
$defaultHost = $this->isStandalone() ? 'localhost' : 'mariadb';
$dbOptions = [
'host' => $_ENV['MYSQL_HOST'] ?? $defaultHost,
'host' => $_ENV['MYSQL_HOST'] ?? 'localhost',
'port' => (int)($_ENV['MYSQL_PORT'] ?? 3306),
'dbname' => $_ENV['MYSQL_DATABASE'] ?? 'azuracast',
'user' => $_ENV['MYSQL_USER'] ?? 'azuracast',
'password' => $_ENV['MYSQL_PASSWORD'] ?? 'azur4c457',
];
$dsn = 'mysql:host=' . $dbOptions['host'] . ';port=' . $dbOptions['port']
$dsn = ('localhost' === $dbOptions['host'])
? 'mysql:unix_socket=/run/mysqld/mysqld.sock;dbname=' . $dbOptions['dbname']
: 'mysql:host=' . $dbOptions['host'] . ';port=' . $dbOptions['port']
. ';dbname=' . $dbOptions['dbname'];
$dbh = new PDO($dsn, $dbOptions['user'], $dbOptions['password']);
@ -121,13 +121,15 @@ class UptimeWait
protected function checkRedis(): bool
{
$defaultHost = $this->isStandalone() ? 'localhost' : 'redis';
$enableRedis = $this->envToBool($_ENV['ENABLE_REDIS'] ?? true);
$redisHost = $_ENV['REDIS_HOST'] ?? $defaultHost;
$redisHost = $_ENV['REDIS_HOST'] ?? 'localhost';
$redisPort = (int)($_ENV['REDIS_PORT'] ?? 6379);
$redisDb = (int)($_ENV['REDIS_DB'] ?? 1);
$redisSocket = ('localhost' === $redisHost)
? '/run/redis/redis.sock'
: null;
if (!$enableRedis) {
$this->println('Redis disabled; skipping Redis check...');
return true;
@ -135,7 +137,11 @@ class UptimeWait
try {
$redis = new Redis();
$redis->connect($redisHost, $redisPort, 15);
if (null !== $redisSocket) {
$redis->connect($redisSocket);
} else {
$redis->connect($redisHost, $redisPort, 15);
}
$redis->select($redisDb);
$redis->ping();
@ -161,11 +167,6 @@ class UptimeWait
|| '1' === $value;
}
protected function isStandalone(): bool
{
return $this->envToBool($_ENV['DOCKER_IS_STANDALONE'] ?? false);
}
protected function println(string $line): void
{
echo $line . "\n";

View File

@ -157,7 +157,11 @@ return [
$settings = $environment->getRedisSettings();
$redis = new Redis();
$redis->connect($settings['host'], $settings['port'], 15);
if (isset($settings['socket'])) {
$redis->connect($settings['socket']);
} else {
$redis->connect($settings['host'], $settings['port'], 15);
}
$redis->select($settings['db']);
return $redis;

View File

@ -313,11 +313,17 @@ class Environment
*/
public function getRedisSettings(): array
{
return [
$redisSettings = [
'host' => $this->data[self::REDIS_HOST] ?? 'localhost',
'port' => (int)($this->data[self::REDIS_PORT] ?? 6379),
'db' => (int)($this->data[self::REDIS_DB] ?? 1),
];
if ('localhost' === $redisSettings['host'] && $this->isDocker()) {
$redisSettings['socket'] = '/run/redis/redis.sock';
}
return $redisSettings;
}
public function isProfilingExtensionEnabled(): bool

View File

@ -1,3 +1,6 @@
unixsocket /run/redis/redis.sock
unixsocketperm 666
save ""
appendonly no

View File

@ -6,12 +6,6 @@ upstream php-fpm-www {
server unix:/var/run/php-fpm-www.sock;
}
{{if isTrue .Env.REDIS_LOCAL }}
upstream redis_server {
nchan_redis_server "redis://localhost:6379";
}
{{end}}
# Internal connection handler for PubSub and internal API calls
server {
listen 127.0.0.1:6010;
@ -47,10 +41,6 @@ server {
location ~ /pub/([^\/]+)$ {
nchan_publisher;
{{if isTrue .Env.REDIS_LOCAL}}
nchan_redis_pass redis_server;
{{end}}
nchan_channel_group "azuracast_nowplaying";
nchan_channel_id $1;
@ -186,9 +176,6 @@ server {
nchan_access_control_allow_origin "*";
nchan_subscriber;
{{if isTrue .Env.REDIS_LOCAL}}
nchan_redis_pass redis_server;
{{end}}
nchan_channel_group "azuracast_nowplaying";
nchan_channel_id "$1";