use crate::config::AppConfig; use crate::package_manager::{InstallMode, PackageManager}; use anyhow::Result; use log::{debug, info, trace, warn}; pub struct BootstrapManager { pub install_mode: InstallMode, pub tenant: Option, } impl BootstrapManager { pub fn new(install_mode: InstallMode, tenant: Option) -> Self { info!( "Initializing BootstrapManager with mode {:?} and tenant {:?}", install_mode, tenant ); Self { install_mode, tenant, } } pub fn start_all(&mut self) -> Result<()> { info!("Starting all components"); let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone())?; let components = vec![ "tables", "cache", "drive", "llm", "email", "proxy", "directory", "alm", "alm_ci", "dns", "webmail", "meeting", "table_editor", "doc_editor", "desktop", "devtools", "bot", "system", "vector_db", "host", ]; for component in components { info!("Starting component: {}", component); pm.start(component)?; trace!("Successfully started component: {}", component); } info!("All components started successfully"); Ok(()) } pub fn bootstrap(&mut self) -> Result { info!("Starting bootstrap process"); let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone())?; let required_components = vec!["tables", "cache", "drive", "llm"]; for component in required_components { info!("Checking component: {}", component); if !pm.is_installed(component) { info!("Installing required component: {}", component); futures::executor::block_on(pm.install(component))?; trace!("Successfully installed component: {}", component); } else { debug!("Component {} already installed", component); } } info!("Bootstrap completed successfully"); let config = match diesel::Connection::establish( "postgres://botserver:botserver@localhost:5432/botserver", ) { Ok(mut conn) => { trace!("Connected to database for config loading"); AppConfig::from_database(&mut conn) } Err(e) => { warn!("Failed to connect to database for config: {}", e); trace!("Falling back to environment configuration"); AppConfig::from_env() } }; Ok(config) } }