botserver/src/bootstrap/mod.rs

97 lines
2.8 KiB
Rust
Raw Normal View History

2025-10-18 19:08:00 -03:00
use crate::config::AppConfig;
use crate::package_manager::{InstallMode, PackageManager};
use anyhow::Result;
use log::{debug, info, trace, warn};
2025-10-18 19:08:00 -03:00
pub struct BootstrapManager {
pub install_mode: InstallMode,
pub tenant: Option<String>,
2025-10-18 19:08:00 -03:00
}
impl BootstrapManager {
pub fn new(install_mode: InstallMode, tenant: Option<String>) -> Self {
info!(
"Initializing BootstrapManager with mode {:?} and tenant {:?}",
install_mode, tenant
);
2025-10-18 19:08:00 -03:00
Self {
install_mode,
2025-10-18 19:08:00 -03:00
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(())
}
2025-10-18 19:08:00 -03:00
pub fn bootstrap(&mut self) -> Result<AppConfig> {
info!("Starting bootstrap process");
2025-10-18 19:08:00 -03:00
let pm = PackageManager::new(self.install_mode.clone(), self.tenant.clone())?;
2025-10-18 19:08:00 -03:00
2025-10-19 14:02:47 -03:00
let required_components = vec!["tables", "cache", "drive", "llm"];
2025-10-18 19:08:00 -03:00
for component in required_components {
2025-10-19 14:02:47 -03:00
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);
2025-10-18 19:08:00 -03:00
}
}
info!("Bootstrap completed successfully");
2025-10-18 19:08:00 -03:00
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)
2025-10-18 19:08:00 -03:00
}
Err(e) => {
warn!("Failed to connect to database for config: {}", e);
trace!("Falling back to environment configuration");
AppConfig::from_env()
2025-10-18 19:08:00 -03:00
}
};
2025-10-18 19:08:00 -03:00
Ok(config)
2025-10-18 19:08:00 -03:00
}
}