diff --git a/scripts/debug/debug_web_manual.py b/scripts/debug/debug_web_manual.py index 62620946..387a4300 100644 --- a/scripts/debug/debug_web_manual.py +++ b/scripts/debug/debug_web_manual.py @@ -54,8 +54,13 @@ def main(): config = config_manager.load_config() print(" ✅ Config loaded") - autostart = config.get('web_display_autostart', False) - print(f" 🔧 web_display_autostart: {autostart}") + # Same rule ledmatrix-web.service applies: only an explicit false/off + # keeps the web interface down; a missing key means on. + sys.path.insert(0, str(project_root / 'scripts' / 'utils')) + from start_web_conditionally import autostart_enabled + raw = config.get('web_display_autostart', '(not set, defaults to on)') + state = 'starts' if autostart_enabled(config) else 'will NOT start' + print(f" 🔧 web_display_autostart: {raw} (web interface {state})") except Exception as e: print(f" ❌ Config check failed: {e}") traceback.print_exc() diff --git a/scripts/diagnose_web_interface.sh b/scripts/diagnose_web_interface.sh index b9b304c3..4bc3dd70 100755 --- a/scripts/diagnose_web_interface.sh +++ b/scripts/diagnose_web_interface.sh @@ -20,6 +20,38 @@ PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_DIR" +# Report web_display_autostart the way scripts/utils/start_web_conditionally.py +# (what ledmatrix-web.service runs) decides it: only an explicit false/off keeps +# the web interface down; a missing key or an unreadable config starts it. +# Prints "on ", "off ", "default" (key not set) or "unreadable". +web_autostart_state() { + (cd "$1" && python3 - 2>/dev/null <<'PY' +import json, os, sys +sys.path.insert(0, os.path.join(os.getcwd(), "scripts", "utils")) +try: + from start_web_conditionally import autostart_enabled +except Exception: + def autostart_enabled(config): + value = config.get("web_display_autostart", True) + if isinstance(value, str): + return value.strip().lower() not in ("off", "false", "no", "0") + return bool(value) +try: + with open(os.path.join("config", "config.json"), encoding="utf-8") as f: + config = json.load(f) +except Exception: + config = None +if not isinstance(config, dict): + print("unreadable") +elif "web_display_autostart" not in config: + print("default") +else: + raw = json.dumps(config["web_display_autostart"]) + print(("on " if autostart_enabled(config) else "off ") + raw) +PY + ) || echo "unknown" +} + echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${BLUE}1. SERVICE STATUS${NC}" echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" @@ -41,14 +73,26 @@ if [ -f "$PROJECT_DIR/config/config.json" ]; then echo -e "${GREEN}✓ Config file found${NC}" # Check web_display_autostart setting - AUTOSTART=$(grep -o '"web_display_autostart"[[:space:]]*:[[:space:]]*[a-z]*' "$PROJECT_DIR/config/config.json" | grep -o '[a-z]*$') - - if [ "$AUTOSTART" == "true" ]; then - echo -e "${GREEN}✓ web_display_autostart: true${NC}" - else - echo -e "${YELLOW}⚠ web_display_autostart: ${AUTOSTART:-not set}${NC}" - echo -e "${YELLOW} Web interface will not start unless this is set to true${NC}" - fi + AUTOSTART=$(web_autostart_state "$PROJECT_DIR") + + case "$AUTOSTART" in + on\ *) + echo -e "${GREEN}✓ web_display_autostart: ${AUTOSTART#on }${NC}" + ;; + off\ *) + echo -e "${YELLOW}⚠ web_display_autostart: ${AUTOSTART#off }${NC}" + echo -e "${YELLOW} Web interface will not start with this value${NC}" + ;; + default) + echo -e "${GREEN}✓ web_display_autostart: not set (defaults to on)${NC}" + ;; + unreadable) + echo -e "${YELLOW}⚠ config.json could not be parsed (the web interface still starts so it can be repaired)${NC}" + ;; + *) + echo -e "${YELLOW}⚠ web_display_autostart: could not be evaluated (python3 unavailable?)${NC}" + ;; + esac else echo -e "${RED}✗ Config file not found at: $PROJECT_DIR/config/config.json${NC}" fi @@ -63,7 +107,7 @@ declare -a REQUIRED_FILES=( "web_interface/app.py" "web_interface/start.py" "web_interface/requirements.txt" - "web_interface/blueprints/api_v3.py" + "web_interface/blueprints/api_v3/__init__.py" "web_interface/blueprints/pages_v3.py" "scripts/utils/start_web_conditionally.py" ) @@ -134,8 +178,8 @@ if ! sudo systemctl is-active --quiet ledmatrix-web; then echo " sudo systemctl start ledmatrix-web" fi -if [ "$AUTOSTART" != "true" ]; then - echo -e "${YELLOW}→ Enable web_display_autostart in config/config.json${NC}" +if [ "${AUTOSTART%% *}" = "off" ]; then + echo -e "${YELLOW}→ Set web_display_autostart to true in config/config.json (or remove it; missing means on)${NC}" fi if [ "$ALL_FILES_OK" = false ]; then diff --git a/scripts/diagnose_web_ui.sh b/scripts/diagnose_web_ui.sh index e2226f1a..1bc26306 100755 --- a/scripts/diagnose_web_ui.sh +++ b/scripts/diagnose_web_ui.sh @@ -22,6 +22,38 @@ fi PROJECT_DIR="${HOME}/LEDMatrix" +# Report web_display_autostart the way scripts/utils/start_web_conditionally.py +# (what ledmatrix-web.service runs) decides it: only an explicit false/off keeps +# the web interface down; a missing key or an unreadable config starts it. +# Prints "on ", "off ", "default" (key not set) or "unreadable". +web_autostart_state() { + (cd "$1" && python3 - 2>/dev/null <<'PY' +import json, os, sys +sys.path.insert(0, os.path.join(os.getcwd(), "scripts", "utils")) +try: + from start_web_conditionally import autostart_enabled +except Exception: + def autostart_enabled(config): + value = config.get("web_display_autostart", True) + if isinstance(value, str): + return value.strip().lower() not in ("off", "false", "no", "0") + return bool(value) +try: + with open(os.path.join("config", "config.json"), encoding="utf-8") as f: + config = json.load(f) +except Exception: + config = None +if not isinstance(config, dict): + print("unreadable") +elif "web_display_autostart" not in config: + print("default") +else: + raw = json.dumps(config["web_display_autostart"]) + print(("on " if autostart_enabled(config) else "off ") + raw) +PY + ) || echo "unknown" +} + echo "1. Checking service status..." echo "------------------------------" if systemctl is-active --quiet ledmatrix-web 2>/dev/null || sudo systemctl is-active --quiet ledmatrix-web 2>/dev/null; then @@ -47,16 +79,25 @@ echo "3. Checking configuration file..." echo "------------------------------" if [ -f "${PROJECT_DIR}/config/config.json" ]; then echo -e "${GREEN}✓ Config file exists${NC}" - AUTOSTART=$(grep -o '"web_display_autostart":\s*\(true\|false\)' "${PROJECT_DIR}/config/config.json" | grep -o '\(true\|false\)' || echo "not found") - if [ "$AUTOSTART" = "true" ]; then - echo -e "${GREEN}✓ web_display_autostart is set to TRUE${NC}" - elif [ "$AUTOSTART" = "false" ]; then - echo -e "${RED}✗ web_display_autostart is set to FALSE (web UI won't start!)${NC}" - echo " Fix: Edit config.json and set 'web_display_autostart': true" - else - echo -e "${YELLOW}⚠ web_display_autostart setting not found (defaults to false)${NC}" - echo " Fix: Add 'web_display_autostart': true to config.json" - fi + AUTOSTART=$(web_autostart_state "$PROJECT_DIR") + case "$AUTOSTART" in + on\ *) + echo -e "${GREEN}✓ web_display_autostart is ${AUTOSTART#on } (web UI starts)${NC}" + ;; + off\ *) + echo -e "${RED}✗ web_display_autostart is ${AUTOSTART#off } (web UI won't start!)${NC}" + echo " Fix: Edit config.json and set 'web_display_autostart': true" + ;; + default) + echo -e "${GREEN}✓ web_display_autostart is not set (defaults to on; web UI starts)${NC}" + ;; + unreadable) + echo -e "${YELLOW}⚠ config.json could not be parsed (the web UI still starts so it can be repaired)${NC}" + ;; + *) + echo -e "${YELLOW}⚠ Could not evaluate web_display_autostart (python3 unavailable?)${NC}" + ;; + esac else echo -e "${RED}✗ Config file NOT FOUND at ${PROJECT_DIR}/config/config.json${NC}" fi @@ -82,7 +123,7 @@ FILES_TO_CHECK=( "web_interface/start.py" "web_interface/app.py" "web_interface/requirements.txt" - "web_interface/blueprints/api_v3.py" + "web_interface/blueprints/api_v3/__init__.py" "web_interface/blueprints/pages_v3.py" ) @@ -175,7 +216,7 @@ echo "Diagnostic Summary" echo "==========================================" echo "" echo "Most common issues:" -echo " 1. web_display_autostart is false or missing in config.json" +echo " 1. web_display_autostart is set to false in config.json (a missing key means on)" echo " 2. Service not enabled or not started" echo " 3. Missing dependencies (Flask, etc.)" echo " 4. Import errors in web_interface/app.py"