varaverk: redesign Fallback card — host online/offline list, state line, active fallback containers with image

This commit is contained in:
Gmer4Lfe
2026-05-24 11:47:08 -04:00
parent 6bb44cae8b
commit cead4eb46f
3 changed files with 109 additions and 26 deletions
@@ -308,6 +308,61 @@ function vv_fallback_state(): array {
];
}
function vv_parse_bash_array(string $raw, string $varName): array {
if (!preg_match('/^\s*' . preg_quote($varName, '/') . '\s*=\s*\(([^)]*)\)/ms', $raw, $m)) return [];
$items = [];
foreach (explode("\n", $m[1]) as $line) {
$line = trim(preg_replace('/#.*$/', '', $line), " \t\"'");
if ($line !== '') $items[] = $line;
}
return $items;
}
function vv_fallback_active(): array {
$vars = vv_conf_vars();
$myName = trim(shell_exec('hostname -s') ?: '');
// Identify which HOST id we are
$myId = null;
foreach (['HOST1', 'HOST2', 'HOST3', 'HOST4'] as $id) {
if (strcasecmp($vars[$id] ?? '', $myName) === 0) { $myId = $id; break; }
}
if (!$myId) return [];
// Running containers: name → image
$running = [];
$psOut = shell_exec("docker ps --format '{\"n\":\"{{.Names}}\",\"i\":\"{{.Image}}\"}' 2>/dev/null") ?: '';
foreach (explode("\n", trim($psOut)) as $line) {
$c = json_decode($line, true);
if ($c) $running[strtolower($c['n'])] = $c['i'];
}
// Parse FALLBACK arrays from this host's conf
$confFile = strtolower($myId) . '.conf';
$rawConf = vv_read_conf_raw($confFile);
$result = [];
foreach (['HOST1', 'HOST2', 'HOST3', 'HOST4'] as $covered) {
if ($covered === $myId) continue;
$coveredHostname = $vars[$covered] ?? '';
if (!$coveredHostname) continue;
$names = [];
for ($tier = 1; $tier <= 4; $tier++)
$names = array_merge($names, vv_parse_bash_array($rawConf, "FALLBACK_{$myId}_COVERS_{$covered}_TIER{$tier}"));
$active = [];
foreach ($names as $name) {
if (isset($running[strtolower($name)]))
$active[] = ['name' => $name, 'image' => $running[strtolower($name)]];
}
if ($active) $result[] = ['host_id' => $covered, 'hostname' => $coveredHostname, 'containers' => $active];
}
return $result;
}
function vv_transcode_sessions(): array {
$stateFile = '/tmp/transcode_state.db';
if (!file_exists($stateFile)) return ['available' => false];