From 2af3e3a4b802e0e07c8d0bb019a5cbcef89cd11d Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 19 Oct 2025 15:03:27 -0300 Subject: [PATCH] Add method to start all components Implement a new method `start_all` in `BootstrapManager` to start all components using the `PackageManager`. This method creates a new `PackageManager` instance and uses it to start each component in a predefined list. --- Add remove_local for PackageManager Remove component specific code The specific code for component 'tables' has been removed from the `remove_local` method in `PackageManager`. The method now simply removes the binary directory for the component. --- Implement start for PackageManager Add a new method `start` to `PackageManager` to start a component. This method takes a component name as an argument and uses the `exec_cmd` for that component to spawn a new process. If the component is not found, it returns an error. --- src/bootstrap/mod.rs | 37 ++++++++++++++++++++++++++++++++ src/package_manager/facade.rs | 21 ------------------ src/package_manager/installer.rs | 13 ++++++++++- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/bootstrap/mod.rs b/src/bootstrap/mod.rs index 47bdacd5..beff5512 100644 --- a/src/bootstrap/mod.rs +++ b/src/bootstrap/mod.rs @@ -20,6 +20,43 @@ impl BootstrapManager { } } + 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"); diff --git a/src/package_manager/facade.rs b/src/package_manager/facade.rs index 620c06e6..c83b2458 100644 --- a/src/package_manager/facade.rs +++ b/src/package_manager/facade.rs @@ -193,27 +193,6 @@ impl PackageManager { } pub fn remove_local(&self, component: &ComponentConfig) -> Result<()> { - if component.name == "tables" { - let bin_path = self.base_path.join("bin").join(&component.name); - let data_path = self.base_path.join("data").join(&component.name); - - let _ = Command::new(bin_path.join("pg_ctl")) - .args(&["-D", data_path.join("pgdata").to_str().unwrap(), "stop"]) - .output(); - } - - if self.os_type == OsType::Linux { - let _ = Command::new("systemctl") - .args(&["stop", &format!("{}.service", component.name)]) - .output(); - let _ = Command::new("systemctl") - .args(&["disable", &format!("{}.service", component.name)]) - .output(); - let service_path = format!("/etc/systemd/system/{}.service", component.name); - let _ = std::fs::remove_file(service_path); - let _ = Command::new("systemctl").args(&["daemon-reload"]).output(); - } - let bin_path = self.base_path.join("bin").join(&component.name); let _ = std::fs::remove_dir_all(bin_path); diff --git a/src/package_manager/installer.rs b/src/package_manager/installer.rs index 60185b36..8b600c4f 100644 --- a/src/package_manager/installer.rs +++ b/src/package_manager/installer.rs @@ -147,7 +147,7 @@ impl PackageManager { "if [ ! -f \"{{CONF_PATH}}/postgresql.conf\" ]; then echo \"logging_collector = on\" >> {{CONF_PATH}}/postgresql.conf; fi".to_string(), "if [ ! -f \"{{CONF_PATH}}/pg_hba.conf\" ]; then echo \"host all all all md5\" > {{CONF_PATH}}/pg_hba.conf; fi".to_string(), "if [ ! -f \"{{CONF_PATH}}/pg_ident.conf\" ]; then touch {{CONF_PATH}}/pg_ident.conf; fi".to_string(), - "if [ ! -d \"{{DATA_PATH}}/pgdata\" ]; then ./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start; sleep 5; ./bin/psql -p 5432 -d postgres -c \" CREATE USER default WITH PASSWORD 'defaultpass'\"; ./bin/psql -p 5432 -d postgres -c \"CREATE DATABASE default_db OWNER default\"; ./bin/psql -p 5432 -d postgres -c \"GRANT ALL PRIVILEGES ON DATABASE default_db TO default\"; pkill postgres; fi".to_string() + "if [ ! -d \"{{DATA_PATH}}/pgdata\" ]; then ./bin/pg_ctl -D {{DATA_PATH}}/pgdata -l {{LOGS_PATH}}/postgres.log start; sleep 5; ./bin/psql -p 5432 -d postgres -c \" CREATE USER default WITH PASSWORD 'defaultpass'\"; ./bin/psql -p 5432 -d postgres -c \"CREATE DATABASE default_db OWNER default\"; ./bin/psql -p 5432 -d postgres -c \"GRANT ALL PRIVILEGES ON DATABASE default_db TO default\"; pkill; fi".to_string() ], pre_install_cmds_macos: vec![], post_install_cmds_macos: vec![ @@ -600,4 +600,15 @@ impl PackageManager { }, ); } + + pub(crate) fn start(&self, component: &str) -> Result { + if let Some(component) = self.components.get(component) { + Ok(std::process::Command::new("sh") + .arg("-c") + .arg(&component.exec_cmd) + .spawn()?) + } else { + Err(anyhow::anyhow!("Component {} not found", component)) + } + } }