diff --git a/app.py b/app.py index d9f58f5..0b9ba75 100644 --- a/app.py +++ b/app.py @@ -135,12 +135,30 @@ def health(): def ready(): """GET /ready - Kubernetes readiness probe""" try: - # Try to access the status file - if os.path.exists(STATUS_FILE): - status = load_status() - if isinstance(status, dict): - return jsonify({"status": "ready"}), 200 - return jsonify({"status": "not_ready", "reason": "status file not accessible"}), 503 + # Check if data directory is writable + data_dir = os.path.dirname(STATUS_FILE) + if not os.path.exists(data_dir): + os.makedirs(data_dir, exist_ok=True) + + # Try to read or create status file + if not os.path.exists(STATUS_FILE): + # File doesn't exist yet, try to create it + default_status = { + "repo": "unknown", + "server": "unknown", + "sync_status": "UNKNOWN", + "drift_count": 0, + "files": [], + "last_check": "" + } + save_status(default_status) + + # Verify we can read it + status = load_status() + if isinstance(status, dict): + return jsonify({"status": "ready"}), 200 + + return jsonify({"status": "not_ready", "reason": "invalid status data"}), 503 except Exception as e: logger.error(f"Readiness check failed: {e}") return jsonify({"status": "not_ready", "error": str(e)}), 503