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.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-10-19 15:03:27 -03:00
parent 6f30517526
commit 2af3e3a4b8
3 changed files with 49 additions and 22 deletions

View file

@ -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<AppConfig> {
info!("Starting bootstrap process");

View file

@ -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);

View file

@ -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<std::process::Child> {
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))
}
}
}