diff --git a/src/core/bootstrap/bootstrap_manager.rs b/src/core/bootstrap/bootstrap_manager.rs index 4c3ed9a21..8f215c936 100644 --- a/src/core/bootstrap/bootstrap_manager.rs +++ b/src/core/bootstrap/bootstrap_manager.rs @@ -1,6 +1,6 @@ // Bootstrap manager implementation use crate::core::bootstrap::bootstrap_types::{BootstrapManager, BootstrapProgress}; -use crate::core::bootstrap::bootstrap_utils::{safe_pkill, vault_health_check}; +use crate::core::bootstrap::bootstrap_utils::{cache_health_check, safe_pkill, vault_health_check}; use crate::core::config::AppConfig; use crate::core::package_manager::{InstallMode, PackageManager}; use log::{info, warn}; @@ -102,14 +102,30 @@ impl BootstrapManager { } } - if pm.is_installed("redis") { - info!("Starting Redis..."); - match pm.start("redis") { - Ok(_child) => { - info!("Redis started"); - } - Err(e) => { - warn!("Failed to start Redis: {}", e); + if pm.is_installed("cache") { + let cache_already_running = cache_health_check(); + if cache_already_running { + info!("Valkey cache is already running"); + } else { + info!("Starting Valkey cache..."); + match pm.start("cache") { + Ok(_child) => { + info!("Valkey cache process started, waiting for readiness..."); + // Wait for cache to be ready + for i in 0..12 { + sleep(Duration::from_secs(1)).await; + if cache_health_check() { + info!("Valkey cache is responding"); + break; + } + if i == 11 { + warn!("Valkey cache did not respond after 12 seconds"); + } + } + } + Err(e) => { + warn!("Failed to start Valkey cache: {}", e); + } } } } diff --git a/src/core/bootstrap/bootstrap_utils.rs b/src/core/bootstrap/bootstrap_utils.rs index 70b91bddd..8d89af4e4 100644 --- a/src/core/bootstrap/bootstrap_utils.rs +++ b/src/core/bootstrap/bootstrap_utils.rs @@ -91,6 +91,35 @@ pub fn vault_health_check() -> bool { false } +/// Check if Valkey/Redis cache is healthy +pub fn cache_health_check() -> bool { + // Try to PING the cache server + match Command::new("redis-cli") + .args(["-h", "127.0.0.1", "-p", "6379", "ping"]) + .output() + { + Ok(output) => { + if output.status.success() { + let response = String::from_utf8_lossy(&output.stdout); + response.trim().to_uppercase() == "PONG" + } else { + false + } + } + Err(_) => { + // If redis-cli is not available, try TCP connection + match Command::new("sh") + .arg("-c") + .arg("timeout 1 bash -c '/dev/null") + .output() + { + Ok(output) => output.status.success(), + Err(_) => false, + } + } + } +} + /// Get current user safely pub fn safe_fuser() -> String { // Return shell command that uses $USER environment variable