cache fix it script

This commit is contained in:
Chuck
2025-07-21 18:35:22 -05:00
parent 8d4736c91b
commit 918e25bb77
2 changed files with 79 additions and 6 deletions

45
fix_cache_permissions.sh Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
# LEDMatrix Cache Permissions Fix Script
# This script fixes permissions on the cache directory so it's writable by the daemon user
echo "Fixing LEDMatrix cache directory permissions..."
CACHE_DIR="/var/cache/ledmatrix"
if [ ! -d "$CACHE_DIR" ]; then
echo "Cache directory does not exist. Run setup_cache.sh first."
exit 1
fi
# Get the real user (not root when running with sudo)
REAL_USER=${SUDO_USER:-$USER}
echo "Current cache directory permissions:"
ls -la "$CACHE_DIR"
echo ""
echo "Fixing permissions..."
# Make the directory writable by the daemon user (which the system runs as)
sudo chmod 777 "$CACHE_DIR"
# Also set ownership to daemon:daemon to match the cache files
sudo chown daemon:daemon "$CACHE_DIR"
echo ""
echo "Updated cache directory permissions:"
ls -la "$CACHE_DIR"
echo ""
echo "Testing write access..."
if sudo -u daemon test -w "$CACHE_DIR"; then
echo "✓ Cache directory is now writable by daemon user"
else
echo "✗ Cache directory is still not writable by daemon user"
exit 1
fi
echo ""
echo "Permissions fix complete! LEDMatrix should now use persistent caching."
echo "The cache will survive system restarts."

View File

@@ -62,18 +62,46 @@ class CacheManager:
try:
# Try /var/cache/ledmatrix first (most standard)
system_cache_dir = '/var/cache/ledmatrix'
os.makedirs(system_cache_dir, exist_ok=True)
if os.access(system_cache_dir, os.W_OK):
return system_cache_dir
# Check if directory exists and we can write to it
if os.path.exists(system_cache_dir):
# Test if we can write to the existing directory
test_file = os.path.join(system_cache_dir, '.writetest')
try:
with open(test_file, 'w') as f:
f.write('test')
os.remove(test_file)
return system_cache_dir
except (IOError, OSError):
self.logger.warning(f"Directory exists but is not writable: {system_cache_dir}")
else:
# Try to create the directory
os.makedirs(system_cache_dir, exist_ok=True)
if os.access(system_cache_dir, os.W_OK):
return system_cache_dir
except Exception as e:
self.logger.warning(f"Could not use /var/cache/ledmatrix: {e}")
# Attempt 3: /opt/ledmatrix/cache (alternative persistent location)
try:
opt_cache_dir = '/opt/ledmatrix/cache'
os.makedirs(opt_cache_dir, exist_ok=True)
if os.access(opt_cache_dir, os.W_OK):
return opt_cache_dir
# Check if directory exists and we can write to it
if os.path.exists(opt_cache_dir):
# Test if we can write to the existing directory
test_file = os.path.join(opt_cache_dir, '.writetest')
try:
with open(test_file, 'w') as f:
f.write('test')
os.remove(test_file)
return opt_cache_dir
except (IOError, OSError):
self.logger.warning(f"Directory exists but is not writable: {opt_cache_dir}")
else:
# Try to create the directory
os.makedirs(opt_cache_dir, exist_ok=True)
if os.access(opt_cache_dir, os.W_OK):
return opt_cache_dir
except Exception as e:
self.logger.warning(f"Could not use /opt/ledmatrix/cache: {e}")