Put every tmpfs path in one place both layers can read

This commit is contained in:
Gmer4Lfe
2026-08-08 22:57:29 -04:00
parent 0f92609425
commit d5c36db531
7 changed files with 119 additions and 23 deletions
+3 -1
View File
@@ -95,7 +95,9 @@ header('Content-Type: application/json');
// take, because the operator's next move is to try again on a machine that already did it.
require_once dirname(__DIR__) . '/include/config.php';
define('VV_JOB_DIR', '/tmp/varaverk_dk_jobs');
// VV_JOB_DIR is defined in config.php with every other tmpfs path, read from DOCKER_JOB_DIR in
// master.conf. It was declared here, inside an endpoint, which is why a survey of Varaverk's
// cache and job directories missed it entirely.
$action = trim($_POST['action'] ?? '');
$name = trim($_POST['name'] ?? '');
+5 -5
View File
@@ -79,7 +79,8 @@
require_once __DIR__ . '/config.php';
define('VV_AI_JOB_DIR', '/tmp/varaverk_ai_jobs');
// VV_AI_JOB_DIR and VV_AI_TOKEN_CACHE_DIR are defined in config.php with every other cache path,
// read from master.conf so this layer and load_config.sh cannot disagree about where they are.
const VV_AI_KINDS = ['header', 'readme', 'manual', 'template', 'doc'];
// Profiles — what each one is, and what it is allowed to see and do. One table, in one file,
@@ -671,10 +672,9 @@ function vv_ai_token_prune(string $db): void {
// Partner ledgers pulled by AI/ai_token_sync.sh into tmpfs. Same trick conf_sync.sh uses for
// partner confs: the reader treats a missing file as "unknown", never as zero.
//
// Mirrors AI_TOKEN_CACHE_DIR in load_config.sh. Hardcoded rather than read from conf because it
// is a derived path constant on the shell side too — neither end reads it from a conf file, so
// there is no single value to drift away from.
const VV_AI_TOKEN_CACHE_DIR = '/tmp/.cache/vv/ai';
// The directory is AI_TOKEN_CACHE_DIR from master.conf, resolved in config.php. It used to be
// hardcoded here, on the reasoning that the shell side hardcoded it too and so there was no
// single value to drift away from — true when it was written, and no longer true.
// Aggregates the file into today / last 7 days / all time, both overall and per host.
//
+41 -2
View File
@@ -57,7 +57,8 @@
// master.conf HOST<n> / HOST<n>_NAME — host identity
// host*.conf HOST*_SSH_KEY — used for setup-state and conf push
// ident.cfg timeZone — Unraid's own setting, adopted for the whole PHP layer
// VV_CACHE_DIR /tmp/vv_cache (tmpfs — RAM speed, cleared on reboot)
// master.conf VV_CACHE_ROOT and the cache paths derived from it — shared with
// load_config.sh, which reads the same keys from the same file
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// ── Timezone ──────────────────────────────────────────────────────────────────
@@ -113,7 +114,45 @@ define('CUSTOM_SCRIPTS_DIR', $_vv_cfg['CUSTOM_SCRIPTS_DIR'] ?? '/boot/config/plu
unset($_vv_cfg);
define('VV_SETUP_STATE_FILE', STATE_DIR . '/varaverk_setup.db');
define('VV_CACHE_DIR', '/tmp/vv_cache');
// ── Cache roots ───────────────────────────────────────────────────────────────
// Read from master.conf so this layer and load_config.sh resolve the same paths from the same
// line. They used to be literals in three PHP files, restating what load_config.sh already said,
// because PHP cannot source bash — and the two sets were kept in agreement by hand.
//
// Deliberately NOT via vv_conf_vars(). That parses master.conf and this host's conf in full and
// calls vv_detect_host() on the way, and api/monitor.php's documented fast path loads this file
// and nothing else in order to reach vv_cache_read() on a cache hit. Making every request pay a
// full conf parse to learn a directory name would tax the exact path built to be cheap. One
// file, seven keys, no host detection.
//
// The fallbacks are the pre-consolidation paths, matching load_config.sh: an installation whose
// conf has not been through conf_upgrade yet keeps using what it is already using, rather than
// silently relocating its caches because a variable was missing.
$_vv_cache = [];
foreach (@file(CONF_DIR . '/master.conf') ?: [] as $_l) {
if (preg_match('/^\s*(VV_CACHE_ROOT|VV_CACHE_DIR|CONF_RAM_CACHE_DIR|ARR_CACHE_DIR'
. '|AI_TOKEN_CACHE_DIR|AI_JOB_DIR|DOCKER_JOB_DIR)\s*=\s*"?([^"#\r\n]+?)"?\s*(?:#.*)?$/',
$_l, $_m)) {
$_vv_cache[$_m[1]] = trim($_m[2]);
}
}
$_vv_root = $_vv_cache['VV_CACHE_ROOT'] ?? '/tmp/varaverk';
// Resolves the one reference the conf actually uses. This is not a general bash expander and is
// not trying to be — vv_conf_vars() owns that, and every value here is one level deep by design.
$_vv_path = function (string $key, string $fallback) use ($_vv_cache, $_vv_root): string {
$v = trim($_vv_cache[$key] ?? '');
if ($v === '') return $fallback;
return str_replace(['${VV_CACHE_ROOT}', '$VV_CACHE_ROOT'], $_vv_root, $v);
};
define('VV_CACHE_ROOT', $_vv_root);
define('VV_CACHE_DIR', $_vv_path('VV_CACHE_DIR', '/tmp/vv_cache'));
define('VV_CONF_RAM_CACHE_DIR', $_vv_path('CONF_RAM_CACHE_DIR', '/tmp/.cache/vv/d'));
define('VV_ARR_CACHE_DIR', $_vv_path('ARR_CACHE_DIR', '/tmp/arr_cache'));
define('VV_AI_TOKEN_CACHE_DIR', $_vv_path('AI_TOKEN_CACHE_DIR', '/tmp/.cache/vv/ai'));
define('VV_AI_JOB_DIR', $_vv_path('AI_JOB_DIR', '/tmp/varaverk_ai_jobs'));
define('VV_JOB_DIR', $_vv_path('DOCKER_JOB_DIR', '/tmp/varaverk_dk_jobs'));
unset($_vv_cache, $_vv_root, $_vv_path, $_l, $_m);
// Read the setup state file into a key=>value array.
function vv_setup_state_read(): array {